#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;
const ll MOD = 1000000000 + 7;

ll pow(ll x, ll p) {
	if (!p) return 1;
	ll y = pow(x, p / 2);
	y = y * y % MOD;
	if (p & 1)
		y = y * x % MOD;
	return y;
}

ll inv(ll x) {
	return pow(x, MOD - 2);
}

ll sum(ll x, ll N) {
	// 1 + x + ... + x^(N-1)
	if (N <= 1) return N;

	if (N & 1) {
		return (1 + x * sum(x, N-1)) % MOD;
	} else {
		return (1+x)*sum(x*x%MOD, N/2) % MOD;
	}
}

ll sum2(ll x, ll N) {
	// 1 + 2 * x + ...  + N * x^(N-1)
	if (N <= 1) return N;
	
	if (N & 1) {
		return (sum(x, N) + x * sum2(x, N - 1)) % MOD;
	} else {
		ll Y = sum2(x, N / 2);
		ll Z = sum(x, N / 2) * pow(x, N / 2) % MOD; // x^(N/2) (1 + x + ... x^(N/2-1))
		return (Y + Z * (N/2) + Y * pow(x, N/2)) % MOD;
	}
}

ll all(ll N) {
	ll res = 0;
	ll A = sum(N*(N+1)%MOD, N);
	ll B = sum(N, N);
	res = (A*(N+1) - B + MOD) % MOD;
	res = res * (N+1) % MOD * inv(2) % MOD;
	return res;
}

ll inc(ll N) {
	return pow(2, N-1) * sum2((N+2)*inv(2) % MOD, N) % MOD;
}

ll dec(ll N) {
	return pow(N+2, N-1) * sum2(2 * inv(N+2) % MOD, N) % MOD;
}

void solve() {
	ll N;
	cin >> N;
	
	//cerr << "all " << all(N) << endl;
	//cerr << "inc " << inc(N) << endl;
	//cerr << "dec " << dec(N) << endl;
	
	ll res = (all(N) - inc(N) - dec(N) + N *(N+1)/2 + 2*MOD) % MOD;
	cout << res << endl;
}

int main() {
	solve();
	
	return 0;
}
