#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b= mod) x -= mod; return *this; } constexpr mint& operator-=(const mint& a){ if((x += mod-a.x) >= mod) x -= mod; return *this; } constexpr mint& operator*=(const mint& a){ (x *= a.x) %= mod; return *this; } constexpr mint operator+(const mint& a) const{ mint res(*this); return res+=a; } constexpr mint operator-(const mint& a) const{ mint res(*this); return res-=a; } constexpr mint operator*(const mint& a) const{ mint res(*this); return res*=a; } constexpr mint pow(long long x) const{ if(!x) return 1; mint a = pow(x>>1); a *= a; if(x&1) a *= *this; return a; } constexpr mint inv() const{ return pow(mod-2); } constexpr mint& operator/=(const mint& a){ return (*this) *= a.inv(); } constexpr mint operator/(const mint& a) const{ mint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } }; vector matmul(vector &dp,vector> &mt){ int m=dp.size(); vector ret(m); REP(i,m){ REP(j,m){ ret[i]+=mt[i][j]*dp[j]; } } return ret; } vector> update(vector> &mt){ int m=mt.size(); vector> ret(m,vector(m)); REP(i,m){ REP(j,m){ REP(l,m){ ret[i][j]+=mt[i][l]*mt[l][j]; } } } return ret; } void matpow(vector &dp,vector> &mt,ll k){ while(k){ if(k&1){ dp=matmul(dp,mt); } mt=update(mt); k/=2; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin >> n; vector dp(4); dp[0]=1; vector> a(4,vector(4)); REP(i,4) REP(j,4) if(i!=j) a[i][j]=1; matpow(dp,a,n); cout << dp[0] << endl; }