#include <bits/stdc++.h>

const int mod = 1000000007;
const int inv3 = (mod + 1) / 3;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int fastpow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}

const int MAXN = 1000010;
int inv[MAXN], n;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	*inv = inv[1] = 1;
	for (int i = 2; i <= n; ++i)
		inv[i] = mul(inv[mod % i], mod - mod / i);
	int ans = 0, now = 1;
	for (int i = 1; i <= n; ++i) {
		now = mul(now, inv3);
		reduce(ans += mul(inv[n - i + 1], now) - mod);
	}
	std::cout << fastpow(n, mod - 2, ans) << '\n';
	return 0;
}
