#include<bits/stdc++.h>
using namespace std;
#define MN 1000000
#define mod 1000000007
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int f[MN+5],p[MN+5],inv[MN+5],Inv[MN+5],n,ans;
inline int C(int n,int m){return 1LL*p[n]*Inv[m]%mod*Inv[n-m]%mod;}
int main()
{
    n=read();p[0]=inv[0]=f[0]=Inv[0]=p[1]=inv[1]=1;
    for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<=n;++i) Inv[i]=1LL*inv[i]*Inv[i-1]%mod;
    for(int i=1,j=2;i<=n;++i,j=j*2%mod) f[i]=(j+mod-f[i-1])%mod;
    int pp=1LL*(mod+1)/3*inv[n]%mod;
    for(int i=2;i<=n+1;++i)  // G(n+1-i,i) -> C(n+1-i+i,i-1)
        ans=(ans+1LL*f[i-2]*C(n,i-1)%mod*pp%mod*inv[i-1])%mod;
    for(int i=1;i<n;++i) ans=1LL*ans*(mod+1)/3%mod;
    cout<<ans;
    return 0;
}