#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MaxN = 1e6 + 100;
const int Mod = 1e9 + 7;
const int Inv2 = (Mod + 1) / 2;
const int Inv3 = 333333336;

int PowMod(int a, int n) {
  int r = 1;
  while (n) {
    if (n & 1) { r = (LL)r * a % Mod; }
    n >>= 1;
    a = (LL)a * a % Mod;
  }
  return r;
}

int fact[MaxN];
int inv_fact[MaxN];

int Binomial(int n, int k) {
  if (n < k) { return 0; }
  LL ans = fact[n];
  ans = (LL)ans * inv_fact[k] % Mod;
  ans = (LL)ans * inv_fact[n - k] % Mod;
  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  int N;
  cin >> N;

  fact[0] = 1;
  const int S = N + 5;
  for (int i = 1; i <= S; ++i) {
    fact[i] = (LL)fact[i - 1] * i % Mod;
  }
  inv_fact[S] = PowMod(fact[S], Mod - 2);
  for (int i = S - 1; i >= 0; --i) {
    inv_fact[i] = (LL)inv_fact[i + 1] * (i + 1) % Mod;
  }
  assert(inv_fact[0] == 1);

  vector<array<int, 3>> plast;
  plast.PB({1, 0, 0});
  for (int i = 1; i <= N; ++i) {
    array<int, 3> nxt_last{0,0,0};
    REP (j, 3) REP (k, 3) if (j != k) {
      nxt_last[k] = (nxt_last[k] + (LL)plast.back()[j] * Inv3) % Mod;
    }
    plast.PB(nxt_last);

    debug(nxt_last[0], nxt_last[1], nxt_last[2]);
  }

  LL ans = 0;
  
  for (int nchanges = 0; nchanges <= N; ++nchanges) {
    int prob_setup = plast[nchanges][1];
    prob_setup = (LL)prob_setup * Binomial(N, nchanges) % Mod;
    prob_setup = (LL)prob_setup * PowMod(Inv3, N - nchanges) % Mod;
    prob_setup = (LL)prob_setup * 3 % Mod;

    debug(nchanges, prob_setup);
    
    int prob_points;
    prob_points = PowMod(3 * nchanges, N - 1);
    prob_points = (LL)prob_points * PowMod(N, Mod - 2) % Mod;
    int integral = PowMod(3 * nchanges, Mod - 2);
    integral = PowMod(integral, N);
    prob_points = (LL)prob_points * integral % Mod;
    debug(prob_points);

    LL this_ans = (LL)prob_points * prob_setup % Mod;
    debug(nchanges, this_ans);
    ans = (ans + this_ans) % Mod;
  }

  cout << ans << "\n";

}



Measured memory_bytes: 42600