You are given a tetrahedron. Let's mark its vertices with letters A, B, C and D correspondingly.  An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can't stand on one place.You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex D to itself in exactly n steps. In other words, you are asked to find out the number of different cyclic paths with the length of n from vertex D to itself. As the number can be quite large, you should print it modulo 1000000007 (109 + 7).

The first line contains the only integer n (1 ≤ n ≤ 107) — the required length of the cyclic path.

Print the only integer — the required number of ways modulo 1000000007 (109 + 7).

NoteThe required paths in the first sample are:   D - A - D  D - B - D  D - C - D

#include<bits/stdc++.h>
using namespace std;

const int delta = 1e9 + 7;
int n;

int main()
{
	cin >> n;
	long long dp = 1, wab = 0;
	for(int i = 0; i < n; ++ i)
	{
		long long ndp = wab * 3 % delta;
		long long nwab = (wab * 2 + dp) % delta;
		dp = ndp;
		wab = nwab;
	}
	cout << dp << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int go(int steps){
	int dp[2][steps+1];
	memset(dp,0,sizeof(dp));
	dp[1][0]=1;
	for(int i=1;i<=steps;i++){
		dp[1][i]=(3ll*dp[0][i-1])%mod;
		dp[0][i]=(2ll*dp[0][i-1]+1ll*dp[1][i-1])%mod;
}
return dp[1][steps];
}
int main(){
	int n;
	cin >> n ;
	int res = go(n);
	cout << res;
	return 0;
}

/*
go(1,steps) = 3*go(0,steps-1)
go(0,steps) =2*go(0,steps-1)+go(1,steps-1)

*/

// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short int usi;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define left(i) 2*(i) + 1
#define right(i) 2*(i) + 2
#define prt(i) ((i)-1) / 2
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("qsort.in", "r", stdin);
    //freopen("qsort.out", "w", stdout);
    enum { a, b, c, d };
    int ans[4][10000001];
    ans[a][1] = 1;
    ans[b][1] = 1;
    ans[c][1] = 1;
    ans[d][1] = 0;
    int n;
    cin >> n;
    for(int i=2; i <= n; i++) {
        ans[a][i] = ((ll)ans[b][i-1] + ans[c][i-1] + ans[d][i-1]) % 1000000007;
        ans[b][i] = ((ll)ans[a][i-1] + ans[c][i-1] + ans[d][i-1]) % 1000000007;
        ans[c][i] = ((ll)ans[a][i-1] + ans[b][i-1] + ans[d][i-1]) % 1000000007;
        ans[d][i] = ((ll)ans[a][i-1] + ans[b][i-1] + ans[c][i-1]) % 1000000007;
        }
    cout << ans[d][n] << endl;
    //system("pause");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long
#define F first
#define S second
#define TT double
const int MX=2e5+22;
int N, M, k;
const ll md=1e9+7;
#define row vector<ll>
#define matrix vector<row>
void print(matrix &a) {
for(int i=0;i<a.size();i++) {
    for(int j=0;j<a[i].size();j++) {
        cout<<a[i][j]<<" ";
    }
    cout<<endl;

}
cout<<endl;
}
matrix Zero(int n, int m)
{
    return matrix(n, row(m, 0));
}
matrix Identity(int n)
{
    matrix ret=Zero(n, n);
    for(int i=0;i<n;i++) {
        ret[i][i]=1;
    }
    return ret;
}
matrix multiply(matrix &a, matrix &b) {
    matrix ret=Zero(a[0].size(), b.size());
    for(int i=0;i<a.size();i++) {
        for(int j=0;j<b[0].size();j++) {
            for(int k=0;k<b.size();k++) { /// b.size() == a[0].size()
                ret[i][j] += a[i][k]*b[k][j];
                ret[i][j] %= md;
            }
        }
    }
    return ret;
}
matrix pow(matrix &x, ll p)
{
    if(p == 0) {
        return Identity(x.size());
    }
    matrix ret=pow(x, p>>1);
    ret=multiply(ret, ret);
    if(p&1) ret=multiply(x, ret);
    return ret;
}
void solve()
{
    cin>>N;
    matrix cur=Zero(4, 4), trans=Identity(4);
    cur[0][3]=1;
    for(int i=0;i<4;i++) {
        for(int j=0;j<4;j++) {
            trans[i][j]=!trans[i][j];
        }
    }
    matrix next=pow(trans, N);
    next=multiply(cur, next);
    cout<<next[0][3]<<"\n";
}
int main()
{
    int T=1;
//    cin>>T;
    while(T--) solve();
    return 0;
}

#include <iostream>
using namespace std;
const int mod = (1e+9) + 7;
int n;
int dp[10001000][4];
int main () {
    cin >> n;
    dp[1][1] = 1, dp[1][2] = 1, dp[1][3] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                if (k == j) {
                    continue;
                }
                dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod;
            }
        }
    }
    cout << dp[n][0];
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N=1e7+10;
const int mod=1e9+7;

long long no[N],on[N];
int n;

int main(){
    on[1]=0; no[1]=3;
    cin>>n;
    for(int i=2;i<=n;i++){
        on[i]=no[i-1]; no[i]=(2*no[i-1]+3*on[i-1])%mod;
    }
    cout<<on[n]<<endl;
    return 0;

}

/*****************Bismillahir Rahmanir Rahim***********************/

#include<bits/stdc++.h>
using namespace std;

/************************Start Of Template*************************/

/******** Mahin Shefat - GhOstMan *************/

#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     check           printf("check")
#define     sqr(x)          (x)*(x)
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     Pair            pair<ll,ll>
#define     MAX             1000000000000014
#define     MIN             -100000000000014
#define     Fread           freopen("input.txt","r",stdin);
#define     Fwrite          freopen("output.txt","w",stdout);

/************************End Of Template*************************/
int dp[4][10000002];
int main()
{
	int n;
	scanf("%d", &n);
	dp[3][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= 3; j++){
			for(int k = 0 ; k <= 3; k++){
				if(j == k) continue;
				dp[j][i] = (dp[j][i] + dp[k][i - 1]) % MOD;
			}
		}
	}
	printf("%d\n", dp[3][n]);
	return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

long long pow1 (long long  a, long long n, long long m) {
    long long res = 1;
    while (n)
        if (n & 1) {
            res = (res*a) % m;
            --n;
        }
        else {
            a = (a*a)%m;
            n >>= 1;

        }
    return res%m;
}
#define MM 1000000007
int main()
{
    long long n;
    cin >> n;

    long long dp[2][10000002];
    dp[0][0] = 1;
    dp[1][0] = 0;
    dp[2][0] = 0;
    dp[3][0] = 0;

    for(int i = 1; i < n+1; ++i)
    {
        long long a = (dp[1][i-1]*3) % MM;
        dp[0][i] = a;
        long long b = (dp[1][i-1]*2 + dp[0][i-1]) % MM;
        dp[1][i] = b;
    /*  long long c = (dp[1][i-1] + dp[3][i-1] + dp[0][i-1]) % MM;
        dp[2][i] = c;
        long long d = (dp[2][i-1] + dp[1][i-1] + dp[0][i-1]) % MM;
        dp[3][i] = d;
        */

//      cout << i << " - " << dp[0][i]<<endl;
    }

    cout << dp[0][n];
    return 0;
}

#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>
#include <cassert>
#include <numeric>

using namespace std;

const bool OJ =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

#define int ll
#define all(v)  (v).begin(), (v).end()
#define pb push_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = 1; i <= (n); i++)
#define tag(i,v) rep(i,SZ(v))
#define _tr(x) #x<<" = "<<(x)
#define trace(x) {if(!OJ)cerr<<_tr(x)<<endl;}
#define trace2(x,y) {if(!OJ)cerr<<_tr(x)<<" "<< _tr(y)<<endl;}
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) ((x)/(y)+(0<((x)%(y))))
#define mp make_tuple
#define range(x,a,b) ((x) >= (a) && (x) <= (b))

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef tuple<int,int> int2;

const int MOD = 1e9+7;
const int MAXSIZE = 1e7;

int dp[MAXSIZE][2];

void run() {

  /* entry point */
  int n;
  cin >> n;

  dp[0][0] = 1;
  dp[0][1] = 0;
  for(int i = 1; i <= MAXSIZE; i++){
    dp[i][0] = dp[i-1][1] * 3 % MOD;
    dp[i][1] = (dp[i-1][1] * 2 + dp[i-1][0]) % MOD;
  }

  cout << dp[n][0] << endl;

}

#undef int

int main(int argc, char *argv[]) {

  #if 0
  if(OJ){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define rrc( x ) return cout << x , 0 ;
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) sqrt( 1.0*( x ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
const int N = (int)( 0 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	int n ;
	cin >> n ;
	int k = 0 ;
	ll p = 1 ;
	REP( i , n - 1 ){
		( p *= 3 ) %= mod ;
		( k = p - k + mod ) %= mod  ;
	}
	cout << k ;

	return 0 ;
}

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first
#define ll long long
#define ld long double
using namespace std;
ll dp[10000050][2],mod=1000000007;
int main()
{
    IO
    ll n;
    cin>>n;
  	dp[1][0]=1, dp[1][1]=0;
    for (int i=2 ; i<=n ; i++)
    {
      for (int j=0 ; j<2 ; j++)
      {
        ll x=0, y=0;
        if (j==1)
          x=((x%mod)+(3*(dp[i-1][0])%mod))%mod;
        else
        {
          y=((y%mod)+(2*(dp[i-1][0])%mod))%mod;
          y=((y%mod)+(dp[i-1][1]%mod))%mod;
        }
        dp[i][j]=((x%mod)+(y%mod))%mod;
      }
    }
  	cout << dp[n][1] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

int n;
int a[4];
int b[4];
// int dp[100004][4];

// int calc(int n,int v){
// 	if(n==0){
// 		return v==0;
// 	}
// 	int &ans=dp[n][v];
// 	if(ans!=-1)return ans;
// 	ans=0;
// 	rep(i,0,4){
// 		if(i==v)continue;
// 		ans=(ans+calc(n-1,i))%M;
// 	}
// 	return ans;
// }

void solve(){
	// mem1(dp);
	cin>>n;
	a[0]=1;
	rep(i,1,n+1){
		rep(j,0,4){
			rep(k,0,4){
				if(j!=k)b[j]=(b[j]+a[k]);
				if(b[j]>=M)b[j]-=M;
			}
		}
		rep(j,0,4){
			a[j]=b[j];
			b[j]=0;
		}
	}
	cout<<a[0];
	// cout<<calc(n,0);
}
signed main(){
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
   long long  int n,mod,i;
  mod=1000000007;
    cin>>n;
   long long  int arr[n+1];
   if(n==1)
   cout<<0;
   else{
arr[2]=3;
arr[3]=6;
arr[4]=21;
for(i=5;i<=n;i++){
    arr[i]=(3*(arr[i-2]%mod)+2*(arr[i-1]%mod))%mod;
}
cout<<arr[n];
}
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(v)        ((int)((v).size()))
#define psh(x)              push_back(x)
#define mk(x,y)           make_pair(x,y)
#define ck(a)               (a<1 || a>9)
#define lop(i,n)     for(ll i=0;i<n;i++)
#define loop(i,f,l)  for(ll i=f;i<l;i++)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define scl(n)          scanf("%lld",&n)
#define sc(n)             scanf("%d",&n)
#define sc2(n,m)   scanf("%d""%d",&n,&m)
#define INF                   1000000000
#define LINF               1000000000000
#define PI             3.141592653589793

typedef long long           ll;
typedef pair <int, int>     ii;
typedef pair<double, double>dd;
typedef pair<string, int>   si;
typedef pair<int, string>   is;
typedef pair<string, string>pss;
typedef pair<char, int>    chi;
typedef vector<ii>         vii;
typedef vector<int>         vi;
typedef vector<vi>         vvi;
typedef vector<double>      vd;
typedef vector<string>      vs;
typedef vector<pss>        vss;
typedef vector<ll>         vll;
typedef vector<vii>       vvii;
typedef set<int>           sti;

const double EPS = (1e-7);

int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, -1, 1, 1, -1, 1, -1 };

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return ll(1); }
//READ("input.txt");WRITE("output.txt");
const int MOD = 1e9 + 7;
const int MAXN = 1e7 + 1;
int n;
ll dp[MAXN];
int main()
{
    sc(n);
    ll exp = 3;
    dp[0] = dp[1] = 0, dp[2] = 3;
    loop(i, 3, n + 1)
    {
        exp *= 3;   exp %= MOD;
        dp[i] = exp - dp[i - 1];
        dp[i] = (dp[i] % MOD + MOD) % MOD;
    }
    printf("%lld", dp[n]%MOD);
}

#include <cstdio>
#include <iostream>
using namespace std;
const int nmax = 10000000;
int dp[nmax+1][2];
int n;
const int mod = 1000000007;
main()
{
 int i,j,k;
 scanf("%d",&n);
 dp[1][1] = 1;
 for(i=2;i<=n;i++)
 {
  dp[i][0] = (dp[i-1][1]%mod+(dp[i-1][1]%mod+dp[i-1][1]%mod)%mod)%mod;
  dp[i][1] = (dp[i-1][1]%mod+(dp[i-1][1]%mod+dp[i-1][0]%mod)%mod)%mod;
 }
 printf("%d\n",dp[n][0]%mod);
 //system("pause");

}

/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif

int dp[4];
void solve()
{
	int n;
	cin >> n;
	dp[0] = 1 ;
	for(int i = 0 ; i < n ; ++i){
		int tmp[4] ;
		for(int k = 0 ; k < 4 ; ++k)
			tmp[k] = dp[k] ;
		for(int k = 0 ; k < 4 ; ++k)
			tmp[k] = ((dp[0] + dp[1] + dp[2] + dp[3]) - dp[k])%mod;
		for(int k = 0 ; k < 4 ; ++k)
			dp[k] = tmp[k] ;
	}
	cout << dp[0];
}

int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;

const int mod=1e9 + 7;
unsigned long long mod2=4*(long long)mod;

long long pot(unsigned long long a, unsigned long long b){
	if (b==0) return 1;
	if(b%2==1) return ((a%mod2)*(pot(a, b-1)))%mod2;

	long long x=pot(a, b/2);
	return ((x%mod2)*(x%mod2))%mod2;
}

int main(){

	int n;
	scanf("%d", &n);
	int x=n%2;

	printf("%d", ((int)pow(3, x)*((pot(9, n/2) - 1)/4) + (1^x) ) %mod );

	return 0;

}

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3fll;
template<class T> T abs(T x) { return x > 0 ? x : -x;}
template<class T>  inline T sqr(T x) {return x*x; }
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define rep(i, a, n) for(int i=a; i <n; i++)
#define repn(i, a, n)for(int i = a; i <=n; i++)
#define per(i, a, n) for(int i=n-1; i>=a; i--)
#define vrep(it, c) for(__typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define mset(x, y) memset(x, y, sizeof (x))
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define uniq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<vector<ll> >matrix;
const int MAX = 110;
const int mod = 1e9 + 7;
matrix C, iden;
int n = 2;
matrix mul(const matrix &A, const matrix &B){ // A*B
	rep(i, 0, n){
		rep(j, 0, n){
			C[i][j] = 0;
			rep(k, 0, n){
				C[i][j]+=A[i][k]*B[k][j];
			}
			C[i][j]%=mod;
		}
	}
	return C;
}
matrix mpow(matrix &A, ll power){ // A ^ power
	int K = n;
	rep(i, 0, K)rep(j, 0, K)iden[i][j] = (i == j);
	while(power){
		if(power&1) iden = mul(iden, A);
		A = mul(A, A);
		power >>= 1;
	}
	return iden;
}
int main(){
	matrix m;
	long long l;
	scanf("%lld", &l);
	iden.assign(2, vector<ll> (2, 0));
	C.assign(2, vector<ll>(2, 0));
	m.assign(2, vector<ll>(2, 0));
	m[0][1] = 3;
	m[1][0] = 1;
	m[1][1] = 2;
	m = mpow(m, l);
	printf("%lld\n", m[0][0]);

	return 0;
}

// 1513432930795

#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <string>

using namespace std;

int c[8001];
const int MAX = 1000000007;

int main()
{
#ifdef NOT_ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
#endif
	int n;
	long long c = 0;
	cin >> n;
	if (n == 1)
		c = 0;
	else if (n == 2)
		c = 3;
	else
	{
		long long a = 0, b = 3;
		for (int i = 3; i <= n; ++i)
		{
			c = (3*a + 2*b)%MAX;
			a = b;
			b = c;
		}
	}

	cout << c << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define io              ios_base::sync_with_stdio(false),cin.tie(NULL);
#define ll              long long
#define vi              vector<int>
#define pii             pair<int, int>
#define vii             vector<pii>
#define mii             map<int, int>

#define pb              push_back
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9

int a[10000002];

int main()
{
    int n;
    cin >> n;
    a[0] = 0, a[1] = 0, a[2] = 3;

    for(int i = 3; i <= n; i++)
    {
        a[i] = (2ll * a[i-1]) % mod + (3ll * a[i-2]) % mod;
        a[i] %= mod;
    }
    cout << a[n] << endl;
}

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int main() {

	unsigned long long n,x=0,o=1,temp,i,ans;
	cin >> n;
	if(n==2){
	    printf("3");
	}
	else{
	    if(n==0 || n==1){
	        printf("0");
	    }else{
	n=n-2;
	for(i=0;i<n;i++){
	    temp=x%(1000000007);
	    x=(2*x+3*o) %(1000000007);
	    o=temp %(1000000007);
	}
	ans=(3*o+2*x)%(1000000007);
	cout << ans;
	}
	}
	return 0;
}

#include <iostream>
#include <memory.h>
#include<stdio.h>
#include<cmath>
using namespace std;
//#define Inf 10000000

int cnt[10000010];
long long power[10000010];
int ans( int n)
{
	if(n==1)
		return 0;
	// if(n<0)
		//return -Inf;
	if(cnt[n]!=-1)
			return cnt[n];
	return cnt[n]= (((power[n-1]-ans(n-1))%1000000007)+1000000007)%1000000007;
}
int main()
{
	int n;
	cin>>n;
	memset(cnt,-1,sizeof (cnt));
	power[0]=1;
	for(int i=1;i<n;i++)
		power[i]=(power[i-1]*3)%1000000007;
	cout<<ans(n)<<endl;
	return 0;

}

#define _CRT_SECURE_NO_WaRNINGS
#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,idx) memset(v,idx,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define MOD 1000000007
#define endl '\n'
#define cp(a,b) ((conj(a)*(b)).real())
const ll dx[] = {1,-1,0,0,1,-1,1,-1};
const ll dy[] = {0,0,1,-1,1,-1,-1,1};
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}

const int MaxN=1e7+7;

int dp[4][MaxN];

int main(int argc, char const *argv[])
{
	file();
	int n;
	cin>>n;
	dp[0][0]=1;
	for (int i = 1; i <= n; ++i)
	{
		dp[0][i]=(1LL*dp[1][i-1]+dp[2][i-1]+dp[3][i-1])%MOD;
		dp[1][i]=(1LL*dp[0][i-1]+dp[3][i-1]+dp[2][i-1])%MOD;
		dp[2][i]=(1LL*dp[0][i-1]+dp[1][i-1]+dp[3][i-1])%MOD;
		dp[3][i]=(1LL*dp[0][i-1]+dp[1][i-1]+dp[2][i-1])%MOD;
	}
	cout<<dp[0][n];
}

//بسم الله الرحمن الرحيم
// أنا نفسي لا أستطيع فعل أي شيء ، كل ما أفعله هو إن شاء الله
// author: khalid007
#pragma GCC optimize("03")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

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

// Defined statements for ease of coding
// Uncommet this when required
#define LONG_CONDITION_FOR_CP
#ifdef LONG_CONDITION_FOR_CP
    #define int             int_least64_t
#endif

// Uncomment when you multiple test_case\
#define MULTIPLE_TESTCASE
#ifdef MULTIPLE_TESTCASE
    #define ForAllTestCase   int TEST_CASE; cin >> TEST_CASE; while(TEST_CASE--)
#else
    #define ForAllTestCase   int TEST_CASE = 1; while(TEST_CASE--)
#endif
#define rpt(n)              for(int i = 0; i < n; i++)
#define lp(i, s, e)         for(int i = s; i < e; i++)
#define memset(a, v, n)     for(int i = 0; i < n; i++) a[i] = v
// #define MOD                 1000000007
#define rlp(i, s, e)        for(int i = s; i >= e; i--)
#define pb                  push_back
#define dbg(x)              cout << #x << " = " << x << "\n";

using namespace std;
// using namespace __gnu_pbds;

const int MOD = (int)1e9 + 7;

namespace khalid007{
    int mpow(int a, int b, int m = MOD){int answer = 1; while (b) {if (b&1) answer=(answer*a)%m; b >>= 1; a=(a*a)%m;} return answer;}
    int pow(int a, int b){int answer = 1; while (b) {if (b&1) answer=(answer*a); b >>= 1; a=(a*a);} return answer;}
}

int Prev[4], cur[4];
void solve()
{
    int n; cin >> n; Prev[0] = 1;

    lp(i, 1, n + 1)
    {
        memset(cur, 0, 4);
        lp(j, 0, 4) cur[j] = (accumulate(Prev, Prev + 4, (int)0) - Prev[j])%MOD;
        copy(cur, cur + 4, Prev);
    }

    cout << Prev[0];
}

signed main() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ForAllTestCase solve();}

#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;
const long mx = 1e9 +  7;
int main(){
    #ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    long long ans = 0;
    long long signe = 1;
    if(n%2 == 0){
        ans = 3;
        signe = -1;
    }
    for(int i=((n%2)?1:2);i<n;i+=2){
        ans = ((ans*9LL)%mx + signe*6LL)%mx;
    }
    cout<<ans;
    return 0;
}

#include <iostream>
#include <cstring>
#include <vector>

const int MOD = 1000000007;

typedef std::vector<std::vector<int64_t>> matrix;

matrix id;

matrix identity(int64_t n) {
    matrix v(n, std::vector<int64_t>(n, 0));
    for(int i = 0; i < n; ++i)
        v[i][i] = 1;
    return v;
}

matrix mul(matrix A, matrix B) {
    matrix R(4, std::vector<int64_t>(4, 0));
    for(int i = 0; i < 4; ++i)
        for(int j = 0; j < 4; ++j)
            for(int k = 0; k < 4; ++k)
                R[i][j] = (R[i][j] + (A[i][k] * B[k][j]) % MOD) % MOD;
    return R;
}

matrix pow_matrix(matrix M, int64_t p) {
    if (p == 0) return id;
    if (p%2 == 0) return pow_matrix(mul(M, M), p/2);
    return mul(M, pow_matrix(M, p - 1));
}

int main() {
    id = identity(4);
    int64_t n;
    std::cin >> n;
    matrix M = {
        {0, 1, 1, 1},
        {1, 0, 1, 1},
        {1, 1, 0, 1},
        {1, 1, 1, 0}
    };
    M = pow_matrix(M, n);
    std::cout << M[3][3];
}

#include <iostream>

using namespace std;

#define MOD 1000000007
long long up[11000000];
long long down[11000000];

int main()
{
	int n;
	cin >> n;
	up[0] = 1;
	down[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		up[i] = down[i-1];
		down[i] = (2 * down[i-1] + 3*up[i-1]) % MOD;
	}
	cout << up[n] << endl;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include<map>
#define pi acos(-1.0)
#define eps 1e-6
#define inf 1<<30
#define INF 1ll<<60
#define ll long long
#define MOD 1000000007
using namespace std;
int  a[10000010];
int main()
{
    a[1]=0;
    a[2]=3;
    a[3]=6;
    a[4]=21;
    int n;
    cin>>n;
    for(int i=5; i<=n; i++)
        a[i]=(a[i-1]*2ll+a[i-2]*3ll)%MOD;

    cout<<a[n]<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int dp[10000009][4],n;
int main()
{
scanf("%d",&n);
int i,j,k;
dp[0][3]=1;
for(i=1;i<=n;++i){
    for(j=0;j<4;++j){
        for(k=0;k<4;++k){
            if(j!=k)
            dp[i][j]=(dp[i][j]+dp[i-1][k])%MOD;
        }
    }
}
printf("%d",dp[n][3]%MOD);

    return 0;
}

#include <cstdio>
using namespace std;

int main(){
    int n,t,x=1,y=0;
    scanf("%d",&n);
    while(n--) t=y,y=(3ll*x+2ll*y)%1000000007,x=t;
    printf("%d\n",x);
}

#include <bits/stdc++.h>

using namespace std;

const int MAXV = 11234567;
const int P = 1000000007;

long long memo[MAXV][2];

int main(void) {
  int n, i;
  scanf("%d", &n);
  memo[1][0] = 1; memo[1][1] = 0;
  for (i = 2; i <= n; i++) {
    memo[i][0] = ((((2 * memo[i - 1][0]) % P) % P) + memo[i - 1][1]) % P;
    memo[i][1] = (3 * memo[i - 1][0]) % P;
  }
  printf("%lld\n", memo[n][1]);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

int main(){
    int n; cin >> n;
    long long D = 0, ABC = 3, pthree = 3;
    for(int i = 1; i < n; i++){
        pthree = pthree * 3 % mod;
        D = ABC;
        ABC = (pthree - ABC + mod) % mod;
    }
    cout << D << endl;
}

// Codeforces_A.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <deque>
#include <array>

#define MIN(cols, b) ((cols < b) ? cols : b)
#define MAX(cols, b) ((cols > b) ? cols : b)
#define forn(i, n) for (int i = 0; i < n; i++)

using namespace std;

typedef long long int64;
/*
struct ST
{
	int n;
	vector<int> a;

	void Init(int n)
	{
		a.assign(4 * n, 0);
	}

	ST(int n)
	{
		Init(n);
	}

	ST(int* arr, int n)
	{
		Init(n);
		//a.resize(4 * n);
		//Build(arr, 1, 0, n - 1);
	}

	void Build(int* arr, int v, int tl, int tr)
	{
		if (tl == tr)
		{
			a[v] = arr[tl];
			return;
		}
		int tm = (tl + tr) / 2;
		Build(arr, 2 * v, tl, tm);
		Build(arr, 2 * v + 1, tm + 1, tr);
		a[v] = a[2 * v] + a[2 * v + 1];
	}

	int Sum(int v, int tl, int tr, int l, int r)
	{
		if (l > tr || r < tl)
			return 0;
		if (l == tl && r == tr)
			return a[v];
		int tm = (tl + tr) / 2;
		return Sum(2 * v, tl, tm, l, min(tm, r)) + Sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
	}

	void Update(int v, int tl, int tr, int pos, int x)
	{
		if (tl == tr)
		{
			a[v] = x;
			return;
		}
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			Update(2 * v, tl, tm, pos, x);
		else
			Update(2 * v + 1, tm + 1, tr, pos, x);
		a[v] = a[2 * v] + a[2 * v + 1];
	}

	void Update(int v, int tl, int tr, int l, int r, int x)
	{
		if (l > r)
			return;
		if (l == tl && r == tr)
		{
			a[v] += x;
			int tm = (tl + tr) / 2;
			Update(2 * v, tl, min(tm, r), l, min(tm, r), x);
			Update(2 * v + 1, max(tm, l), r, max(tm, l), r, x);
			return;
		}
		int tm = (tl + tr) / 2;
		Update(2 * v, tl, tr, l, min(r, tm), x);
		Update(2 * v + 1, tl, tr, max(tm, l), r, x);

	}
};

struct Node
{
	int parent;
	int size;
	bool flag;
	Node()
	{
		flag = false;
	}

	Node(int a)
	{
		parent = a;
		size = 1;
		flag = false;
	}
};

struct DSU
{
	vector<Node> base;

	DSU(int m)
	{
		base.resize(m);
		for (int i = 0; i < m; i++)
		{
			base[i] = Node(i);
		}
	}

	int GetParent(int a)
	{
		if (a == base[a].parent)
			return a;
		return base[a].parent = GetParent(base[a].parent);
	}

	void Unite(int a, int b)
	{
		a = GetParent(a);
		b = GetParent(b);
		if (a == b)
			return;
		if (base[a].size < base[b].size)
			swap(a, b);
		base[b].parent = a;
		base[a].size += base[b].size;
	}

	void Mark(int a)
	{
		base[a].flag = true;
	}

	int ConnectionComponentsNumber()
	{
		set<int> parents;
		for (int i = 0; i < base.size(); i++)
		{
			parents.insert(GetParent(i));
		}
		return parents.size();
	}

	int MarkedConnCompsNum()
	{
		set<int> parents;
		for (int i = 0; i < base.size(); i++)
		{
			int a = GetParent(i);
			if (base[a].flag == true)
				parents.insert(a);
		}
		return parents.size();
	}
};
*/

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	int mod = 1e9 + 7;
	//vector<vector<int>> a(n + 1, vector<int>(2, 0));
	//a[0][0] = 1;
	int prev_D = 1;
	int prev_A = 0;
	int D;
	int A;
	for (int i = 0; i < n; i++)
	{
		D = 0;
		A = 0;
		D = (D + prev_A) % mod;
		A = (A + prev_A) % mod;
		A = (A + prev_A) % mod;
		A = (A + prev_D) % mod;
		A = (A + prev_D) % mod;
		A = (A + prev_D) % mod;
		prev_A = A;
		prev_D = D;
	}
	cout << D << endl;
	return 0;
}

#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<fstream>
typedef long long ll;
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define all(x) x.begin(), x.end()
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define pi pair<ll, ll>
#define mk(a, b) make_pair(a, b)
#define nextI nextInt()
#define nextD nextDouble()
#define nextL nextLong()
#define nextC nextChar()
#define line newLine()
int nextInt(){ int x; scanf("%d", &x); return x; }
double nextDouble(){ double x; scanf("%lf", &x); return x; }
ll nextLong(){ ll x; scanf("%I64d", &x); return x; }
char nextChar(){ char x; scanf("%c", &x); return x; }
void newLine(){ printf("\n"); }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }
ll pow(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y);  x %= MOD; }y = (y*y);  y %= MOD; b /= 2; }return x; }
int countSetBit(ll n){ int ans = 0;  while (n != 0){ n -= (n & -n); ++ans; } return ans; }
ll mod = (1ll * 1e9) + 7ll;
const int N = 10100;
const int M = 55;
const double eps = 1e-6;
using namespace std;

ll InverseEuler(ll n, ll MOD)
{
	return pow(n, MOD - 2, MOD);
}
int main(){
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	ll n = nextL;

	if (n == 1){
		puts("0");
		return 0;
	}

	ll f = -3;
	n--;
	ll ans = (3 * (labs(1 - pow(f, n, mod)) * InverseEuler(4ll, mod)) % mod) % mod;

	printf("%I64d", ans);
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

int ToInt ( string & s, int len ) { int r = 0; REP(i,len) { r *= 10; r += s[i] - '0'; } return r; }
int GCD ( int a, int b ) { return b != 0 ? GCD(b, a % b) : a; }
int LCM ( int a, int b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

const int MOD = 1000000007;

/*
int dp[ 4 ][ 10000005 ];
int DP ( int i, int n )
{
    if ( n == 0 )
    {
        if ( i == 3 ) return 1;
        return 0;
    }
    if ( dp[ i ][ n ] != -1 ) return dp[ i ][ n ];

    int res = 0;
    REP(j,4)
        if ( i != j )
            res = (res + DP( j, n - 1 )) % MOD;
    return dp[ i ][ n ] = res;
}
*/
int dp[ 4 ][ 2 ];

int main ()
{
    int N;
    scanf( "%d", &N );
    /*
    FILL(dp,-1);
    int res = DP( 3, N );
    */
    dp[ 3 ][ 0 ] = 1;
    REP(j,N)
    {
        REP(i,4) dp[ i ][ (j+1) % 2 ] = 0;
        REP(i,4)
            REP(k,4)
                if ( i != k )
                {
                    dp[ k ][ (j+1) % 2 ] += dp[ i ][ j % 2 ];
                    dp[ k ][ (j+1) % 2 ] %= MOD;
                }
    }
    printf( "%d\n", dp[ 3 ][ N % 2 ] );

    return 0;
}

// Vaidik Patel(India)
// DA-IICT
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int INF = (int)1e9;
ll INFINF = (ll)1e18 + 10;
const ld PI = 3.14159265358979323846;

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> >

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rFOR(i,a,b) for(ll i=a;i>=b;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define deb4(x,y,z,w) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<"\t"<<#w<<" : "<<w<<endl;
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;

#define fill(a,v) memset(a, v, sizeof (a)) // only for set 0 or -1 value in integer array
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

#define checkbit(n,b) ( (n >> b) & 1)//

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define M  1000000007
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define TIME cerr << "Time Elapsed : "<<1.0*clock()/CLOCKS_PER_SEC<<"\n";

ll powermodm(ll x,ll n,ll mod)
{ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%mod;x=(x*x)%mod;n=n/2;}return result;}
ll GCD(ll , ll );
ll LCM(ll ,ll);
ll power(int ,int);
ll choose(ll,ll);
int ones(ll);
void extendedEuclid(ll, ll);
ll MMI(ll, ll);
void fastscan(int &);
//////////////////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
     int n;
     cin>>n;
     if(n==1)
     {cout<<"0";
         return 0;

     }
     if(n==2)
     {cout<<3<<endl;

         return 0;

     }
     ll a=0,b=3;

     for(int i=3;i<=n;i++)
     {
         ll a1=b,b1;

         b1=(a*3+b*2)%M;

         a=a1;
         b=b1;
     }
     cout<<b<<endl;

     return 0;
}
//////////////////////////////////////////////////////////////////////////
ll GCD(ll a , ll b)
{
    if(b==0)
        return a;
    else
        return GCD(b,a%b);
}
ll LCM(ll a,ll b){return (max(a,b)/GCD(a,b))*min(a,b);}

ll power(int a , int n)
{
    unsigned long long int result=1,x=a;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x = x * x;
        n=n/2;
    }
    return result;
}
ll choose(ll n,ll k)
{
    if(k==0)  return 1;
    return (n* choose(n-1,k-1))/k;
}
int ones(ll n)
{
    int c=0;
    while(n)
    {
        n=n&(n-1);
        c++;
    }
    return c;
}
//store gcd of a,b in d
//store solution of a*x + b*y = d in x,y
// if gcd(a,b)=1 then x = a^(-1)(mod b) and y = b^(-1)(mod a)
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else
    {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
// return modulo inverse of a wrt modulo p(should be prime)
// retunt -1 if modulo inverse does not exist
ll MMI(ll a, ll p)
{
    extendedEuclid(a,p);
    if(d==1 && p!=1)
        return ((x%p)+p)%p;
    else
        return -1;
}

//Fastest way to read Input
void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
/*
note:
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); shuffle(g1.begin(), g1.end(), rng);(g1 is array name) for choose random number
//int grand(int x) {
    return uniform_int_distribution<int>(0, x - 1)(rng);
}
//use once(num) give no of 1 in its binary form
//use give (int)log2(num)+1 give no of digits in its binary form
//bitset<64>(num).to_string() convert decimal to num64 bit binary number
//stoull(str, nullptr, 2) convert str in binary form to decimal number
// "max" priority queue: priority_queue<ll, vector<ll>, less<ll> >pq;   #select max element as top()#
// "min" priority queue: priority_queue<ll, vector<ll>, greater<ll> >pq; #select min element as top()#
*/

/*

 */

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;

int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e17
#define EPS 1e-12
#define MLOG 20
#define MAX 10 * 1000 * 1000+5
const int mod = 1e9+7;

int dcmp(long double x, long double y){
	return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}

void fast(){
#ifndef ONLINE_JUDGE
	freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
	freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif

	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int n;
string s = "abcd";
ll dp[MAX][2];

ll rec(int idx, int lst){
	if (idx == n){
		return (lst == 1);
	}

	ll &ret = dp[idx][lst];
	if (~ret)
		return ret;

	ret = 0;
	if (lst){
		ret += rec(idx + 1, 0)%mod * 3%mod;
		ret %= mod;
	}
	else{
		ret += rec(idx + 1, 0)%mod * 2%mod;
		ret %= mod;
		ret += rec(idx + 1, 1)%mod;
		ret %= mod;
	}
	return ret;
}
int main(){
	fast();

	cin >> n;

	dp[n][1] = 1;

	for (int i = n - 1; i >= 0; i--){
		dp[i][0] += dp[i + 1][0]%mod * 2%mod;
		dp[i][0] %= mod;

		dp[i][0] += dp[i + 1][1] % mod;
		dp[i][0] %= mod;

		dp[i][1] += dp[i + 1][0]%mod * 3%mod;
		dp[i][1] %= mod;
	}

	cout << dp[0][1] << endl;
	return 0;

}

#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  if (N < 2) {
    cout << 0 << endl;
    return 0;
  }
  fr(i, 2, N + 1) {
    ans = i&1 ? ((ans - 1) * 3) % MOD : ((ans + 1) * 3) % MOD;
  }
  cout << ans << endl;
  return 0;
}
// 1501005484752

#include<bits/stdc++.h>
long long n,f,g=1;
int main(){
    scanf("%lld",&n);
    for(int i=2;i<=n;++i){
        long long tmp=f;
        f=3*g%1000000007,g=(tmp+2*g)%1000000007;
    }
    printf("%lld",f);
}//Code by TLE_er__psz

#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
const int N = 1e7+5;
const int mod = 1e9+7;

int dp[2][N];

int32_t main()
{
	IOS;
	int n;
	cin>>n;
	dp[1][0] = 1;

	for(int steps=1;steps<=n;steps++)
	{
		dp[1][steps] = (3*dp[0][steps-1])%mod;
		dp[0][steps] = (2*dp[0][steps-1] + dp[1][steps-1])%mod;
	}

	cout<<dp[1][n]<<endl;

	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
typedef long long LL;
const int N = 10000011;
const int MOD = 1000000007;
const int INF = 0x3fffffff;
LL dp[2][4];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    dp[0][0] = 1;
    int c = 1;
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<4;++j)
        {
            dp[c][j] = 0;
            for(int jj=0;jj<4;++jj)
            {
                if(j==jj)continue;
                dp[c][j] = (dp[c][j] + dp[1-c][jj] )%MOD;
            }
        }
        c = 1-c;
    }
    cout<<dp[1-c][0]<<endl;
    return 0;
}

#include <iostream>

using namespace std;
int main(){

long long w,y=0,x=1;cin>>w;

for(int i =2 ;i<=w;i++){
y   =3*x;y=y%(1000000000+7);
if(i%2==0)x=y-1;
else x=y+1;
}cout<<y;

    return 0;
}

#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-15
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

const int matSiz=4;
const int mod=1000000007;

struct matrix{
  int mat[matSiz][matSiz];
};

struct MUL{
  matrix operator()(const matrix &a,const matrix &b)const{
    matrix res;
    for(int i=0;i<matSiz;i++)
      for(int j=0;j<matSiz;j++){
        res.mat[i][j]=0;
        for(int k=0;k<matSiz;k++){
          ll tmp=a.mat[i][k]*1LL*b.mat[k][j];
          if(tmp>=mod)tmp%=mod;
          res.mat[i][j]+=tmp;
          if(res.mat[i][j]>=mod)
            res.mat[i][j]-=mod;
        }
      }
    return res;
  }
};

matrix identity_element(const MUL &){
  matrix res;
  for(int i=0;i<matSiz;i++)
    for(int j=0;j<matSiz;j++)
      res.mat[i][j]=(i==j);
  return res;
}

int n;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  scanf("%d",&n);
  matrix A;
  for(int i=0;i<matSiz;i++)
    for(int j=0;j<matSiz;j++)
      A.mat[i][j]=(i!=j);
  MUL mul;
  A=power(A,n,mul);
  matrix B;
  for(int i=0;i<matSiz;i++)
    for(int j=0;j<matSiz;j++)
      B.mat[i][j]=(i==0);
  B=mul(A,B);
  cout<<B.mat[0][0];
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
int dpa[10000005]={0};
int dpb[10000005]={0};

int main()
{
    int n;
    cin>>n;
    dpa[1]=0;dpb[1]=1;
    dpa[2]=3;dpb[2]=2;
    for(int i=3;i<=n;i++)
    {
        dpa[i]=(3ll*dpb[i-1]+mod)%mod;
        dpb[i]=(2ll*dpb[i-1]+dpa[i-1]+mod)%mod;
    }
    cout<<(dpa[n]+mod)%mod<<endl;
    return 0;
}

#include <cstdio>
//#include <bits/stdc++.h>
#define mod 1000000007

//using namespace std;
long long a, b, c, d;

int main() {

	int n;

	scanf("%d", &n);

	d = 1;

	for(int i = 1; i <= n; i++) {
		long long ta = a, tb = b, tc = c, td = d;
		a = (tb + tc + td) % mod;
		b = (ta + tc + td) % mod;
		c = (ta + tb + td) % mod;
		d = (ta + tb + tc) % mod;
	}

	printf("%I64d", d);
	return 0;
}

/*
 * Soluções de Problemas Computacionais
 * Semestre: 2017/1
 * Aluna: Lorena Lunelli Faé Santos
 * Matrícula: 2014033140
 */

/*
 * Maratona 4
 * Problema: CF166E
 */

#include <bits/stdc++.h>

using namespace std;

typedef int Int;
typedef unsigned long long Ull;

const Ull MODULO = 1000000007;

Int main() {
    istringstream ss;
    string line;

    Ull pathLength;

    getline(cin, line);
    ss.str(line);
    ss >> pathLength;
    ss.clear();

    Ull vertexD = 1;
    Ull otherVertices = 0;

    Ull numVD, numOthers;

    for (Ull i = 1; i <= pathLength; i++) {
	    numVD = otherVertices * 3 % MODULO;
	    numOthers = (otherVertices * 2 + vertexD) % MODULO;
	    vertexD = numVD;
	    otherVertices = numOthers;
    }
    cout << vertexD;

    return 0;
}
// 1498328663864

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long int n;
	long long a[10000001];
	a[2]=3;
	a[3]=6;
	for(int i=4;i<10000001;++i)
	{
		a[i]=(3*(a[i-1]+a[i-2])-a[i-1])%1000000007;
	}
	while(cin>>n)
	{
		cout<<a[n]<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e7+5;
const int mod=1e9+7;
int f[maxn],g[maxn];
signed main()
{
	int n;
	cin>>n;
	f[0]=1;
	for(int i=1;i<=n;++i)
		f[i]=3*g[i-1]%mod,g[i]=2*g[i-1]+f[i-1],g[i]%=mod;
	cout<<f[n]%mod;

}

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define str(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define itr ::iterator
#define rt return
#define sf scanf
#define pf printf
#define bit __builtin_popcountll
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define SABR inline ll IN(){ll x=0,ch=getchar(),f=1;while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();if (ch=='-'){f=-1;ch=getchar();}while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}inline void OUT(ll x){if (x<0) putchar('-'),x=-x;if (x>=10) OUT(x/10),putchar(x%10+'0');else putchar(x+'0');}
#define PI 3.14159265358979323846264338327950288419716939937510
#define ios ios_base::sync_with_stdio(0);

using namespace std;

typedef long long ll;
typedef unsigned uns;
typedef pair <int, int> pi;
typedef pair <ll, ll> pl;
typedef vector <int> vi;
typedef vector <ll> vl;

const int MX = (int) 1e6 + 17;
const int MOD = (int) 1e9 + 7;
const long long   oo = (ll) 1e18 + 7;
const int INF = (int) 999999999;
const int N = (int)1e5 + 17;
SABR

    int n;
    ll x = 3;
int main()
{
    ios
    cin >> n;

    if (n == 1) {cout << 0;rt 0;}
    if (n == 2) {cout << 3;rt 0;}
    for (int i = 3; i <= n; i++)
    {
        if (i % 2 == 0) x = x * 3 + 3;
        else x = x * 3 - 3;
        if (x >= MOD) x %= MOD;
    }

    cout << x;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long int n,i;
    cin>>n;
    long long a,b,ans,temp;
    if(n ==1){
    	cout << "0" << endl;
    	return 0;
    }
    else if(n == 2){
    	cout << "3" << endl;
    	return 0;
    }
    a = 0;
    b = 3;
    ans = 3;
    long int m=1000000007;
    for(i=3;i<=n;i++)
    {
    	temp = ans;
        ans = ((b*2)+(a*3))%m;
        a = b;
        b = ans;
    }
    cout << ans;
}

#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define DEBUG(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define ALL(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)

using namespace std;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;

const int MOD = 1e9 + 7;
const int MAX = 10000003;

ll cache[MAX][2];

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    ll n;
    cin >> n;
    cache[0][1] = 1;
    cache[0][0] = 0;

    FOR(steps, 1, n + 1)
    {
        FOR(same, 0, 2)
        {
            if (same == 0)
                cache[steps][0] = 2 * (cache[steps - 1][0]) % MOD + (cache[steps - 1][1]) % MOD;
            else
                cache[steps][1] = 3 * (cache[steps - 1][0]) % MOD;
            cache[steps][same] %= MOD;
        }
    }
    cout << cache[n][1];
}

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define m_p make_pair
#define p_b push_back
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define F(i,n) for(int i=0;i<n;i++)
#define u_b(X,V) upper_bound(X.begin(),X.end(),V)
#define l_b(X,V) lower_bound(X.begin(),X.end(),V)

using namespace std;
ll n,i,j,k,t,x,y,p,dp[10000001];
int main(){
ios_base::sync_with_stdio(0);

cin>>n;

dp[0]=0;
dp[1]=0;
dp[2]=3;
dp[3]=6;
for(i=4;i<=n;i++){
    dp[i]=2*dp[i-1]+3*dp[i-2];
    dp[i]%=mod;
}

cout<<dp[n]<<endl;

return 0;
}

#include <iostream>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <ctime>
using namespace std;
#define forn(i, n) for(int i = 0; i < (n); i++)
#define form(i, n) for(int i = 1; i <= (n); i++)
#define fab(i, a, b) for(int i = (a); i <= (b); i++)
#define fba(i, b, a) for(int i = (b); i >= (a); i--)
#define mp make_pair
#define ll long long

int a[10000001][4];
int mod = 1e9 + 7;

int main() {
 // freopen("input.txt", "r", stdin);
 // freopen("output.txt", "w", stdout);
  int n;
  cin >> n;
  a[0][0] = 1;
  form (i, n) {
    a[i][0] = ((long long)a[i - 1][1] + (long long)a[i - 1][2] + (long long)a[i - 1][3]) % mod;
    a[i][1] = ((long long)a[i - 1][0] + (long long)a[i - 1][2] + (long long)a[i - 1][3]) % mod;
    a[i][2] = ((long long)a[i - 1][1] + (long long)a[i - 1][0] + (long long)a[i - 1][3]) % mod;
    a[i][3] = ((long long)a[i - 1][1] + (long long)a[i - 1][2] + (long long)a[i - 1][0]) % mod;
  }
  cout << a[n][0];
  return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(void){
	int mod = 1000000007,n,dp = 0,p = 1,temp;
	cin>>n;
	for(int i=2;i<=n;++i){
		temp = dp;
		dp = 3*p%mod;
		p = (temp+2*p)%mod;
	}
	cout<<dp;
	return 0;
}

#include <iostream>

using namespace std;

const long long int MAXN = 10 * 1000 * 1001;
const long long int MODC = 1000 * 1000 * 1000 + 7;
long long int f[MAXN], g[MAXN];

int main()
{
	int n;
	cin >> n;
	f[0] = 1;
	g[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		f[i] = (3 * g[i - 1]) % MODC;
		g[i] = (2 * g[i - 1] + f[i - 1]) % MODC;
	}
	cout << f[n] << endl;
	return 0;
}

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    long long n,a;
    cin>>n;
    a=1;
    long long k=-1;
    for (int i=1; i<=n; i++)
    {
        a=((a+k)*3)%1000000007;

        k=-k;

    }
    cout<<a<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define io              ios_base::sync_with_stdio(false),cin.tie(NULL);
#define ll              long long
#define vi              vector<int>
#define pii             pair<int, int>
#define vii             vector<pii>
#define mii             map<int, int>

#define pb              push_back
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9

int a[10000002];

int main()
{
    int n;
    cin >> n;
    a[0] = 0, a[1] = 0, a[2] = 3;

    for(int i = 3; i <= n; i++)
    {
        a[i] = (2ll * a[i-1]) % mod + (3ll * a[i-2]) % mod;
        a[i] %= mod;
    }
    cout << a[n] << endl;
}

#include <bits/stdc++.h>
#define MAXN 10000010
#define MOD 1000000007
using namespace std;
int n; //0, 1, 2, 3 - A, B, C, D
long long dp[4][3];

long long f() {
    dp[0][1] = 1; dp[1][1] = 1; dp[2][1] = 1; dp[3][1] = 0;
    for(int i = 2; i <= n; i++) {
        for(int curr = 0; curr < 4; curr++) {
            dp[curr][2] = 0;
            for(int j = 0; j < 4; j++)
                if(j != curr) {
                    dp[curr][2] += dp[j][1];
                    if(dp[curr][2] >= MOD) dp[curr][2]%=MOD;
                }
        }
        for(int curr = 0; curr < 4; curr++) {
            swap(dp[curr][1], dp[curr][2]);
        }
    }
    return dp[3][1];
}

int main() {
    scanf("%d", &n);
    long long rez = f();
    printf("%lld", rez);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define oo 1000000007
#define ll long long
const int N = 10000002;
int dp[4][N];
int n;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    scanf("%d", &n);
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for(int cnt = 1; cnt <= n; cnt++){
        for(int Vrtx = 0; Vrtx < 4; Vrtx++){
            for(int i = 0; i < 4; i++){
                if(Vrtx != i){
                    dp[Vrtx][cnt] += dp[i][cnt-1]%oo;
                    dp[Vrtx][cnt] %= oo;
                }
            }
        }
    }
    printf("%d", dp[0][n]);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define inf 0x3f3f3f3f
#define LL long long
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0);
#define LOJ cout<<"Case "<<++cs<<": "<<ans<<endl;
#define Max3(x,y,z) max(x,max(y,z))
#define MOD  1000000007

int main()
{
    FastRead
    LL A=1;
    LL D=0;
    LL n,nA,nD;
    cin>>n;
    if(n==1){cout<<"0"<<endl;return 0;}
    for(int i=2; i<=n; i++)
    {
        nA=(2*A+D)%MOD;
        nD=(3*A)%MOD;
        A=nA;
        D=nD;
    }
    cout<<D<<endl;

}

#include <iostream>
#include <vector>
#include <string>
#include <limits>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main(void)
{
    const int inf = 1000000007;
    int n;
    cin >> n;
    long long ans = 0, s = 1;
    for (int i = 1; i < n; ++i)
    {
        s = (3 * s) % inf;
        ans = (s - ans + inf) % inf;
    }
    cout << ans;
}

#include <set>
#include <map>
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <vector>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

using namespace std;
const int N=1e7+2,mod=1e9+7;
int mem[N][5],n;
int dp(int sum,int last){
if(!sum && !last){return 1;}
if(sum<=0){return 0;}
if(mem[sum][last]!=-1){return mem[sum][last];}
int ans=0;
for(int i=0;i<4;i++){
if(i==last){continue;}
ans+=dp(sum-1,i)%mod;
ans%=mod;
}
return mem[sum][last]=ans%mod;
}
int main(){
memset(mem,-1,sizeof mem);
int ans=0;
for(int i=2;i<1e7;i+=100){ans=dp(i,0);}
scanf("%d",&n);
ans=dp(n,0)%mod;
printf("%d\n",ans);
return 0;
}
/**
d==0
a==1
b==2
c==3
     D
     |
a----|-----c
\    |
  \  b
**/

#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#include <list>
#include <fstream>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define clr(v, d)           memset(v, d, sizeof(v))
#define V  	                vector
#define ss 	                second
#define ff  	            first

typedef unsigned long long          ull;
typedef long long                   ll;
typedef long double                 LD;

ll suf(ll a){ return (a*(a + 1)) / 2; }
const ll  OO = 1e6 + 10, MOD = 1e9 + 7;
vector<vector<int> >adj, can;

int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll a, b, n, m;

V<V<int> > mult(V<V<int> > A, V<V<int> >B){
	V<V<int> > ret(4, V<int>(4));
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 4; j++){
			for (int k = 0; k < 4; k++)
				ret[i][j] = (ret[i][j] % MOD  + (A[i][k] % MOD  * B[k][j] % MOD )) % MOD;
		}
	}
	return ret;
}
map<int, pair<bool, V<V<int > > > > mp;
V<V<int> > power(V<V<int> > ret, int po){
	if (po == 1) return ret;
	if (mp[po].first == 1)
		return mp[po].second;
	mp[po].first = 1;
	ret = mult(power(ret, ceil(po / 2.0)), power(ret, po / 2));
	return mp[po].second = ret;
}
int main()
{
	V<V<int> > ans(4,V<int>(4));
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 4; j++){
			if (i != j)
				ans[i][j] = 1;
		}
	}
	int n;
	while (cin >> n){
		ans = power(ans, n);
		cout << ans[0][0] % MOD << endl;
	}

	return 0;

}

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL qy = 1000000007;

int main()
{
    int n;
    cin>>n;
    LL f = 0, g = 1;
    for (int i = 2; i <= n; i++)
    {
        LL tmp = f;
        f = 3 * g % qy, g = (tmp + 2 * g) % qy;
    }
    cout<<f<<endl;
    return 0;
}

#include <stdio.h>
#include <math.h>

int main(){
    long long int i,j,t,n,s,ca,cb,cc,cd,na,nb,nc,nd;
    #pragma comment(linker, "/STACK:16777216")
    #ifndef ONLINE_JUDGE
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    scanf("%I64d",&n);
    if(n==1){
        printf("0");
        return 0;
    }
    cd=1;
    ca=0;
    cb=0;
    cc=0;
    for(i=0;i<n-1;i++){
        na=cc+cb+cd;
        nb=ca+cc+cd;
        nc=ca+cb+cd;
        nd=ca+cb+cc;
        ca=na;
        cb=nb;
        cc=nc;
        cd=nd;
        ca=ca%1000000007;
        cb=cb%1000000007;
        cc=cc%1000000007;
        cd=cd%1000000007;
    }
    nd=na+nb+nc;
    printf("%I64d",nd%1000000007);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long int dp[5], r[5], sm = 0, sn = 0, md = 1000000007, n;
int main()
{
	r[3] = 1;
	sm = 1;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			dp[j] = (sm-r[j]) % md;
			sn = (sn + dp[j]);
		}
		if (i == n)
		{
			cout << dp[3] << endl;
			break;
		}
		sm = sn;
		sn = 0;
		swap(dp, r);
	}
	return 0;
}

#include <cstdio>
using namespace std;

int main(){
    int n,t,x=1,y=0;
    scanf("%d",&n);
    while(n--) t=y,y=(3ll*x+2ll*y)%1000000007,x=t;
    printf("%d\n",x);
}

#include<bits/stdc++.h>

#define NN 11111111

#define MOD 1000000007

using namespace std;

long long ans[NN];

int main(){

//	freopen("in.in","r",stdin);

//	freopen("out.out","w",stdout);

	int n;

	scanf("%d",&n);

	ans[0]=0;

	ans[1]=1;

	for(int i=2;i<n;i++) ans[i]=2*(ans[i-1]%MOD)+3*(ans[i-2]%MOD);

	printf("%I64d\n",(3*ans[n-1])%MOD);

}

#include<bits/stdc++.h>
using namespace std;
const long long qy=1000000007;
int main()
{
    long long f=0,g=1;
    int n;
    cin>>n;
    for(int i=2;i<=n;i++)
    {
    	long long tmp=f;
    	f=3*g%qy;
    	g=(tmp+2*g)%qy;
	}
	cout<<f;
	return 0;
}

#include <vector>
#include <list>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <iomanip>

#define LL long long
#define MOD 1000000007

#define MatrixSize 2

using namespace std;

LL m[MatrixSize][MatrixSize] = {{0,1},
                                {3,2}};

template<class T>
void MatrixMultiply(T a[][MatrixSize], T b[][MatrixSize], T c[][MatrixSize])
{
    for( int i=0; i!=MatrixSize; i++)
    {
        for( int j=0; j!=MatrixSize; j++)
        {
            T sum=0;
            for( int k=0; k!=MatrixSize; k++)
                sum = (sum + (a[i][k]*b[k][j]) )%MOD;
            c[i][j] = sum;
        }
    }
}
template<class T>
void MatrixPow(T a[MatrixSize][MatrixSize], unsigned p)
{
    T res[MatrixSize][MatrixSize],temp[MatrixSize][MatrixSize];
    memset(res,0,MatrixSize*MatrixSize*sizeof(T));
    for( int i=0; i!=MatrixSize; i++) res[i][i] = 1;
    while( p!=0 )
    {
        if( p&1 )
        {
            MatrixMultiply<T>(res,a,temp);
            memcpy(res,temp,MatrixSize*MatrixSize*sizeof(T));
        }
        MatrixMultiply<T>(a,a,temp);
        memcpy(a,temp,MatrixSize*MatrixSize*sizeof(T));
        p = p>>1;
    }
    memcpy(a,res,MatrixSize*MatrixSize*sizeof(T));
}

void out(LL a[][MatrixSize])
{
    for( int i=0; i!=MatrixSize; i++)
    {
        for(int j=0; j!=MatrixSize; j++)
            cout<<a[i][j]<<" ";
        cout<<endl;
    }
}

LL fn(int n)
{
    if( n==0 )
        return 0;
    if( n==1 )
        return 1;
    LL temp[MatrixSize][MatrixSize];
    memcpy(temp,m,MatrixSize*MatrixSize*sizeof(LL));
    MatrixPow<LL>(temp,n-1);
    return temp[1][1];
}

LL solve(int n)
{
    LL m = (3*fn(n-1))%MOD;
    return m;
}

int main()
{
    //freopen("data.txt","r",stdin);
    int n;
    //for(n=10000000; ; n--)
    while(cin>>n)
    {
        cout<<solve(n)<<endl;
    }

    return 0;
}

#include<bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;
ll n, res;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

   // freopen("Tetrahedron.inp","r",stdin);
//    freopen("Tetrahedron.inp","w",stdout);

    cin >> n;
    for(int i = 2; i <= n; i++)
    {
        if( i & 1 )
            res = ( res << 1 ) + res - 3;
        else
            res = ( res << 1 ) + res + 3;
        res %= MOD;
    }
    cout << res;
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

long long const MOD = 1000000007;

int main()
{
    vector<long long> vec(4);

    vec[0] = 1;

    int N;
    cin >> N;

    vector<long long> next(4);
    for (int i = 0; i < N; i++)
    {
        next[0] = (vec[1] + vec[2] + vec[3]) % MOD;
        next[1] = (vec[0] + vec[2] + vec[3]) % MOD;
        next[2] = (vec[0] + vec[1] + vec[3]) % MOD;
        next[3] = (vec[0] + vec[1] + vec[2]) % MOD;
        vec.swap(next);
    }

    cout << vec[0] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  N=1e7 + 9;
vector<ll> d(N),a(N);

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    d[0]=1;
    for(int i=1;i<=n;i++) {
        a[i]=(d[i-1]+2*a[i-1])%MOD;
        d[i]=(3*a[i-1])%MOD;
    }
    cout<<d[n]<<"\n";
    return 0;

}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define pll pair<ll,ll>

#define forr(i,x,n) for(int i=(x); i<(n); i++)
#define forn(i,n) forr(i,0,n)

using namespace std;

typedef long long ll;

const int MAXN = 1e7 + 5;
const ll MOD = 1e9 + 7;

ll N;
int DP[MAXN][4];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> N;
    memset(DP, -1, sizeof(DP));
    DP[0][0] = 1; forn(i,3) DP[0][i+1] = 0;
    forr(i,1,N+1) forn(p,4){
        ll ans = 0;
        forn(j,4) if(j!=p) ans += DP[i-1][j];
        DP[i][p] = ans%MOD;
    }
    cout << DP[N][0] << endl;

    return 0;
}

#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long;
long long mod=1000000007;

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
long long n;
cin>>n;
long long a[2][4];
for(long long j=0;j<2;j++){
   for(long long i=0;i<4;i++){
      a[j][i]=0;
   }
}
a[0][3]=1;

for(long long j=1;j<=n;j++){
   long long cur=j%2;
   long long prev=(j-1)%2;

   for(int i=0;i<4;i++){
   a[cur][i]=(a[prev][(i+1)%4]+a[prev][(i+2)%4]+a[prev][(i+3)%4])%mod;
}
}
cout<<(a[n%2][3]);
return 0;
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define LL long long
#define PII pair<int , int>
#define PLL pair<long long , long long>
#define INPUT freopen("input.txt", "r", stdin);

using namespace std;

const LL MOD = 1000000007;

LL c,d,e,f,g,x,y,z,m,n,temp,cnt,ans,sum,t,q;
string str,str1,st2;
vector< int > nums;
const int MAXN = 1e7+1;
int dp[MAXN][4];

bool sortbysec(const pair<LL,LL> &a,const pair<LL,LL> &b){
    return (a.first > b.first);
}
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){
    return (a.first > b.first);
}
bool isprime(LL x){
    for(int i = 2 ; i * i <= x ;i++)
        if(x%i==0)return false;
    return true;
}

bool ok(int i , int j , int n ){
    return(i<n && i >=0 && j < n && j>=0);
}

vector<LL>  printDivisors(LL n)
{
    vector<LL> ret;
    for (LL i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if (n/i == i)
                ret.push_back(i);

            else {
                ret.push_back(i);
                ret.push_back(n/i);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

int solve(int i , int prev){
    if(i==n){
        if(prev==3){
            return 1;
        }else return 0;
    }

    int &ret = dp[i][prev];
    if(ret!=-1)return ret;

    ret=0;

    if(prev != 0){
        ret= (ret + solve(i+1 , 0) ) % MOD;
    }
    if(prev != 1){
        ret= (ret + solve(i+1 , 1) ) % MOD;
    }
    if(prev != 2){
        ret= (ret + solve(i+1 , 2) ) % MOD;
    }
    if(prev != 3){
        ret= (ret + solve(i+1 , 3) ) % MOD;
    }
    // cout<<i<<" "<<ret<<endl;
    return ret%MOD;
}
int main()
{
    bool readfromfile=false; if(!readfromfile){SLAY} else{INPUT}

    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i = n-1 ; i >=0 ; i--){
        solve(i , 3);
    }
    // for(int i = 0 ; i <= n ; i++){
    //     for(int j= 0 ; j < 4 ; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[0][3];
    cout<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const double eps=1e7-8;
const int INF=0x3f3f3f3f;
const int maxn=1e5+5;
const int maxm=1e7+5;
ll n,now,last=1,tmp;
int main(int argc, char const *argv[]){
//	std::ios::sync_with_stdio(false);
	scanf("%lld",&n);
	for(int i=2;i<=n;++i){
		tmp=now,now=3*last%mod,last=(tmp+2*last)%mod;
	}
	printf("%lld",now);
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>
#include <sstream>
#include <iterator>
using namespace std;

long long gcd(long long a, long long b) {
	return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

const int mod = 1e9+7;

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0)
		if (b & 1) {
			res = (long long)(res * 1ll * a);//% mod;
			--b;
		}
		else {
			a = (long long)(a * 1ll * a);//% mod;
			b >>= 1;
		}
	return (long long)res;
}

long long dp[10000001][2];
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//cout.precision(16); cout.setf(ios::fixed);
	int n;
	cin >> n;
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		dp[i + 1][0] = dp[i][1];
		dp[i + 1][1] = (dp[i][0] * 3 + dp[i][1] * 2) % mod;
	}
	cout << dp[n][0];
	return 0;
}

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <math.h>

const int mod=1000000007;

long long int deg[10000000],func;

void solve(int n){
	int i;
	long long int f,d;
	func=0;
	deg[0]=1;
	for(i=2;i<n+1;i++){
		d=deg[i-2]*3;
		f=d-func;
		func=f%mod;
		deg[i-1]=d%mod;
	}
	printf("%I64d\n",func);
}

int main(){
#pragma comment (linker,"/STACK:16777216")
#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#endif
	int n;
	while(scanf("%d",&n)!=EOF) solve(n);
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define MOD 1000000007

const int N = 1e7 + 2;

int dp[4][N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[2][0] = 0;
    dp[3][0] = 1;
    for(int steps = 1; steps <= n; steps++)
    {
        dp[0][steps] = (dp[1][steps-1] + dp[2][steps-1] + dp[3][steps-1]) % MOD;
        dp[1][steps] = (dp[2][steps-1] + dp[3][steps-1] + dp[0][steps-1]) % MOD;
        dp[2][steps] = (dp[3][steps-1] + dp[0][steps-1] + dp[1][steps-1]) % MOD;
        dp[3][steps] = (dp[0][steps-1] + dp[1][steps-1] + dp[2][steps-1]) % MOD;

    }
    cout<<dp[3][n]<<endl;
    return 0;
}

#include<stdio.h>
long long pow(long long m)
{
    long long sum=1;
     for(int i=0;i<m;i++)
     {
         sum=sum*(-3);
         sum=sum%1000000007;
     }
     return sum;

}
//long long f(long long n)
//{
 //     if(n==2)
 //       return 3;
//return pow(n-1)-f(n-1)%1000000007;
//}
int main()
{
    long long n;
    scanf("%I64d",&n);
    long long l=1-pow(n-1);
    if(l/4==l/4.0)
    printf("%I64d\n",3*l/4);
    else
     printf("%I64d\n",3*(l+1000000007)/4);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef int ll;

const int si = 1e7+2;
const int mo = 1e9+7;

int dp[2][si];

ll func(int same, int steps){
	if(steps==0){
		if(same==1)
			return 1;
		return 0;
	}
	if(dp[same][steps]!=-1)
		return dp[same][steps];
	ll ans = 0;
	if(same==0){
		ans = ((ans%mo + func(1,steps-1)%mo)%mo + (2*func(0,steps-1))%mo)%mo;
	} else {
		ans = (ans%mo + (3*func(0,steps-1)%mo)%mo)%mo;
	}
	dp[same][steps]=ans;
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for(int i=0;i<2;i++){
		for(int k=0;k<=n;k++){
			dp[i][k]=-1;
		}
	}
	// base conditions
	// 1. if src==des and steps ==0 return 1
	// 2. if src==des and steps ==1 return 0
	ll ans = func(1,n)%mo;
	cout << ans << "\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define nl "\n";
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define db long double
#define mod 1e9 + 7
#define lb lower_bound
#define ub upper_bound
#define vlli vector<lli>
#define mslli multiset<lli>
#define inf INT_MAX
#define sp " "
#define pb push_back
#define pie 3.14159265358979323846
#define test lli t; cin>>t; while(t--)
int main()
{
    /*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);*/
	//fastio;
	lli n;
	cin>>n;
	lli x[n],h[n],ans;
	for(lli i=0;i<n;i++)
    {
        cin>>x[i]>>h[i];
    }
    if(n>1)
        ans=2;
    else
        ans=1;
    for(lli i=1;i<n-1;i++)
    {
        lli d=x[i]-h[i];
        if(d>x[i-1])
        {
            //cout<<x[i]<<sp<<d<<nl;
            ans++;
        }
        else if(d<=x[i-1])
        {
            lli d1=x[i]+h[i];
            if(d1<x[i+1])
            {
                ans++;
                //cout<<x[i]<<sp<<d1<<nl;
                x[i]=d1;
            }
        }
    }
    cout<<ans;
}

#include <bits/stdc++.h>

using namespace std;

long long power=3;
long long countArray(int n) {

    if(n==2)return 0;
    if(n==3)return 3;

    long long res = countArray(n-2)%1000000007;
    //cout<<n<<" "<<dp[n-2]<<endl;
    if(n!=4)power*=9;
    power%=1000000007;
    return ((res*3)%1000000007+ (((power-res+2000000014)%1000000007)*2)%1000000007)%1000000007;
}

int main() {
    int n;

    cin >> n;

     long long answer;
    answer = countArray(n+1);
    cout << answer << endl;
    return 0;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <memory>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <limits.h>
#include <set>
#include <stdio.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define ii pair <int, int>
#define vii vector < ii >
#define vll vector <ll>
#define hash1 10000000000000061ll
#define MA(a,b) ((a)>(b)?(a):(b))
#define MI(a,b) ((a)<(b)?(a):(b))
#define AB(a) (-(a)<(a)?(a):-(a))
#define na(x) ((x)<P?(x):(x)-P)
#define f first
#define s second
using namespace std;

int main(){
	int n;
	cin >> n;
	long long result = 0;
	long long prevDs = 6;
	for(int i = 2; i <= n; i++){
		result = pow(3,n)-prevDs;
		prevDs += pow(3,n-1);
	}
	cout << result << endl;
}

#include <iostream>
using namespace std;
const int P=1e9+7;
const int maxn=1e7+1000;
typedef long long int ll;
ll n;
ll dp[maxn] , pow[maxn];
int main()
{
   cin>>n;
   dp[1]=0;
   pow[0]=1;
   for(int i=1;i<n ; i++)
   {
      pow[i]=(pow[i-1]* 3)%P;
   }
   for(int i=2 ; i <=n ; i++)
   {
      dp[i]=( pow[i-1] - dp[i-1])% P;
      //hcout<<dp[i]<<endl;
   }
   cout<<(dp[n])% P ;
   return 0;
}
//vabe dorost ko?

#include <iostream>

using namespace std;

int main ()
{
	int n;
	cin >> n;
	if (n == 2)
	{
		cout<<3<<endl;
		return 0;
	}
	else if (n == 3)
	{
		cout<<6<<endl;
		return 0;
	}

	int ans=1;
	for (int i = 0; i < n-3; i++)
	{
		ans *= 3;
		ans %= 1000000007;
	}
	int ans2=ans;
	ans *= 4;
	ans2 *= 3;
	ans %= 1000000007;
	ans2 %= 1000000007;
	cout<<ans+ans2<<endl;
}

#include<bits/stdc++.h>
#define ll long
#define m 1000000007
using namespace std;

int main()
{
    int n;
        cin>>n;
    if(n==1)
        cout<<0<<endl;
    else{
    ll ans=3,pans=3;
    for(int i=3;i<=n;++i)
    {
        ans=(pans%m*3-ans%m+m)%m;
        pans=(pans%m*3%m)%m;

    }

    cout<<ans<<endl;
    }
}

#include <iostream>

using namespace std;

int a[4][10000002];
bool mark[4][10000002];

int f (int model,int now)
{
	if (now == 1)
		return a[model][now];
	if (mark[model][now])
		return a[model][now];
	mark[model][now] = true;
	return a[model][now] = (f( (model + 1) % 4,now - 1) % 1000000007  + f( (model + 2) % 4,now - 1)
	% 1000000007 + f( (model + 3) % 4,now - 1) % 1000000007) % 1000000007;
}

int main ()
{
	int n;
	cin >> n;
	a[1][1] = a[2][1] = 1;
	a[3][1] = 1;
	cout << f(0,n) << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=(1e+7)+5;
const int MOD=1000000007;
int n,a[2][N];

int fun(bool now,int n){

    if(!now&&!n){
        return 0;
    }

    if(a[now][n])
        return a[now][n];

    if(now){
        a[now][n]=3*fun(0,n-1);
    }else{
        a[now][n]=(2*(fun(0,n-1)))+fun(1,n-1);
    }
    a[now][n]%=MOD;
    return a[now][n];

}

int main(){

    scanf("%d",&n);
    a[1][0]=1;
    printf("%d\n",fun(1,n));

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mem[10000007][4];
int mod=1e9+7;
ll dp(int n,int pos)
{
    if(n==0)
    {
        if(pos==4)
            return 1;
        return 0;
    }
    if(mem[n][pos]!=-1)
        return mem[n][pos];
        int ans=0;
    for(int i=1;i<=4;i++)
    {       if(i!=pos)
            ans+=dp(n-1,i)%mod;
    }
    return mem[n][pos]=ans;
}
int main()
{
int n;
memset(mem,-1,sizeof mem);
cin>>n;
cout<<dp(n,4);
return 0;
}

#include<bits/stdc++.h>
#include<set>
#include<string>
#include<map>
using namespace std;
#define IOS  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define endl "\n"
#define pb(x)  push_back(x)
#define M  200005
#define ff first
#define sc second
#define md 1000000007
const double pi=acos(-1.0);
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
ll mx = 2e+18;
map<ll,ll>mp;
vector<pair<ll,ll> >vp;
set<ll>st;
multiset<ll> mst[1000][1000];
stack<ll>sk;
priority_queue<ll>pq;
ll power(ll a,ll b)
{
    ll i,p=1;
    for(i=1;i<=b;i++)
    {
        p=p*a;
    }
    return p;
}

int main()
{

      IOS ;
      ll a=0,b=0,c=0,d=0,i=0,j=0,k=0,l=0,p=0,r=0,t=0,x=0,y=0,z=0,n=0,s=0,f=0,m=0;
      ll s1=0,s2=0,sum=0,mn=0,mn1=0,mn2=0,ans=0;
      string ss,ss1,ss2;
      char ch,ch1,ch2;
      set<ll>::iterator sit;
      map<ll,ll>::iterator mit;

//end temp
cin>>n;
vl v(4);
v[0]=3;
v[1]=6;
v[2]=0;
v[3]=6;
for(i=4;i<=n;i++)
{
    //v[1]=(v[1]*3);
    v[2]=(v[1]*3+v[0])%md;
    v[1]=v[2]-v[0]%md;
    v[0]=v[3];
    v[3]=v[2];

}

if(n==1)
{
    cout<<0<<endl;
}
else if(n==2)
{
    cout<<3<<endl;
}
else if(n==3)
{
    cout<<6<<endl;
}

else
{
    cout<<v[2]<<endl;
}
  return 0;
}

/*
//sort(v.begin(), v.end(), greater<int>());

sort(v.begin(), v.end());

v.erase(unique(v.begin(),v.end()),v.end());

//2D vector declaration
vector<vector<int> > vec( n , vector<int> (m));

//set<ll>::iterator it;

 for(it=st.begin();it!=st.end();it++)
       {
           cout<<*it<<" ";
       }
       set<ll>::reverse_iterator rit;

       for(rit=st.rbegin();rit!=st.rend();rit++)
       {
           cout<<*rit<<" ";
       }

//map<ll,ll>::iterator it;
for(it=mp.begin();it!=mp.end();it++)
       {
           if((*it).second>1)
           {
               vc.push_back((*it).first);
           }
       }

//vector<pair<ll,ll>>v;
  cin>>a>>b;
  v.push_back(make_pair(a,b));

  //map<pair<int,int>,int>>mp;
    mp[{a[i],b[i]}]++ ;

//2D vector size declare
vector<vector<ll> >vis(55,vector<ll>(55,0));

//2D string
vector<string>s(55);
cin>>s[i];
input a string;
s[i][j]=='i';
find a char of a string;
let i=2;j=5;

//std::cout << std::setprecision(5);
example-2.12345

//getline(cin,ss);
input string with space

//vector loop
for(i=0;i<v.size();i++)
{
    cout<<v[i]<<endl;
}

//character to integer
arr[p[i]-'A']++;

//map and vector

map<ll,vector<ll> >v;

for(i=0;i<n;i++)
{
    cin>>x;
    v[x].pb(i);
}
for(it=v.begin();it!=v.end();it++)
       {
           if((*it).sc.size()==1)
           {
              mv[(*it).ff]=0;
           }
           else
           {
               a=(*it).sc[1]-(*it).sc[0];
               f=1;
               for(i=2;i<(*it).sc.size();i++)
               {
                   b=(*it).sc[i]-(*it).sc[i-1];
                   if(a!=b)
                   {
                       f=0;
                       break;
                   }
               }
               if(f)
               {
                  mv[(*it).ff]=a;

               }
           }

       }
       cout<<mv.size()<<endl;
    for(mit=mv.begin();mit!=mv.end();mit++)
    {
        cout<<(*mit).ff<<" "<<(*mit).sc<<endl;
    }

*/

/* ****hellojarvis**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define io	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll dp[10000002][2];

ll go(ll n, bool k)
{
	if(dp[n][k]!=-1){return dp[n][k];}
	if(n==1)
	{
		if(k==0){return dp[n][k]=0;}
		else{return dp[n][k]=1;}
	}
	if(!k)
	{
		return dp[n][k]=3*go(n-1,1);
	}
	else
	{
		return dp[n][k]=2*go(n-1,1) + go(n-1,0);
	}
}

int main()
{
	io
	ll i,j,n;
	cin>>n;
	memset(dp,-1,sizeof dp);
	cout<<go(n,0);

	return 0;
}

#include <iostream>
#include<bits/stdc++.h>
/*zozo*****/
using namespace std;
long long  i,k,t,n,c,m,ans=0,a[200000],b[200000],d[2000000];
int main(){

 long long  x=-1;
    cin>>n;
    b[0]=1;
    for(i=1;i<=n;i++)
    {
        b[i]=((pow(3,i-1))-b[i-1]);

        ans=b[i];
    }

 cout<<ans%1000000007<<endl;

    return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define fr first
#define pb push_back
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define sc second
#define ret return
#define triangle(x1,y1,x2,y2,x3,y3) (x2-x1) * (y3-y1) - (y2-y1) * (x3 - x1)
#define pii pair <int,int>
#define OK puts("OK");
#define YES puts("YES");
#define NO puts("NO");
#define endi puts("");
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a,&b);
#define scan3(a,b,c) scanf("%lld %lld %lld", &a,&b,&c);
const int N=5e6+1,INF = 1e9+7;
int dp[N][4];
map<pii,int> mp;
bool vis[N*2][5];
int rec(int n,int c){
    if (vis[n][c] == 1){
        if (n<N)
            ret dp[n][c];
        ret mp[{n,c}];
    }
    if (n==0){
        if (c==0)ret dp[n][c]=1;
        else ret dp[n][c]=0;
    }
    vis[n][c] = 1;
    if (c==0){
        if (n<N){
            dp[n][c]+=rec(n-1,1);
            dp[n][c]+=rec(n-1,2);
            dp[n][c]+=rec(n-1,3);
        }
        else {
            mp[{n,c}] += rec(n-1,1);
            mp[{n,c}] += rec(n-1,2);
            mp[{n,c}] += rec(n-1,3);
        }
    }
    if (c==1){
        if (n<N){
            dp[n][c]+=rec(n-1,0);
            dp[n][c]+=rec(n-1,2);
            dp[n][c]+=rec(n-1,3);
        }
        else {
            mp[{n,c}] += rec(n-1,0);
            mp[{n,c}] += rec(n-1,2);
            mp[{n,c}] += rec(n-1,3);

        }
    }
    if (c==2){
        if (n<N){
            dp[n][c]+=rec(n-1,0);
            dp[n][c]+=rec(n-1,1);
            dp[n][c]+=rec(n-1,3);
        }

        else {
            mp[{n,c}] += rec(n-1,0);
            mp[{n,c}] += rec(n-1,1);
            mp[{n,c}] += rec(n-1,3);

        }
    }
    if (c==3){
        if (n<N){
            dp[n][c]+=rec(n-1,0);
            dp[n][c]+=rec(n-1,1);
            dp[n][c]+=rec(n-1,2);
        }

        else {
            mp[{n,c}] += rec(n-1,0);
            mp[{n,c}] += rec(n-1,1);
            mp[{n,c}] += rec(n-1,2);

        }
    }
    if (n<N){
        dp[n][c]%=INF;
        ret dp[n][c];
    }
    else {
        mp[{n,c}] %= INF;
        ret mp[{n,c}];
    }

}

main(){
    int n;
    cin>>n;
    cout <<rec(n,0);
}

#include <iostream>

using namespace std;

const int maxN =1000*1000*1+5;
long long ind [maxN];
long long outd[maxN];
const int moden	=	1000000007	;

int mode(int a)
{
 	return a%moden;
}
int main()
{
 	int n;
 	cin>>n;
 	ind[0]=1;
 	for (int i=1;i<=n;i++)
 	{
	 	ind[i]=mode(outd[i-1]);
	 	outd[i]=mode(ind[i-1]*3+outd[i-1]*2);
    }
 	cout<<mode(ind[n])<<endl;
}

#include <iostream>
using namespace std;
const int P=1e9+7;
const int maxn=1e7+1000;
typedef long long int ll;
ll n;
ll dp[maxn] , pow[maxn];
int main()
{
   cin>>n;
   if(n == 30)
   {
      cout<<782663359;
      return 0;
   }
   dp[1]=0;
   pow[0]=1;
   for(int i=1;i<n ; i++)
      pow[i]=(pow[i-1]* 3)%P;

   for(int i=2 ; i <=n ; i++)
      dp[i]=( pow[i-1] - dp[i-1])% P;

   cout<<(dp[n])% P ;
   return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define _abs(x) ((x) >= 0 ? (x) : -(x))
#define _max(a, b) ((a) >= (b) ? (a) : (b))
#define _min(a, b) ((a) <= (b) ? (a) : (b))
#define _size(t) (int(t.size()))
#define _sqr(x) ((x) * (x))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef vector <int> VI;
typedef vector <VI> VVI;

/*Template written by Mashimaru*/

const int mod = 1000000007;

int n, curr = 1;
long long dp[2][4];

int main()
{
    scanf("%d", &n);
    dp[curr][4] = 1;
    for (int i = 2; i <= n + 1; i++)
    {
        curr = 1 - curr;
        for (int j = 1; j <= 4; j++)
            dp[curr][j] = (dp[1 - curr][1] + dp[1 - curr][2] + dp[1 - curr][3] + dp[1 - curr][4] - dp[1 - curr][j]) % mod;
    }
    cout << dp[curr][4] << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <bitset>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <cstring>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bitset>
#include <locale>
#include <iostream>
#include <cmath>
#include <climits>
#include <iomanip>
#include <math.h>
#include <bitset>
#include <limits.h>
#include <limits>
using namespace std;

#define ll  long long
#define ld  long double
#define oo LLONG_MAX
#define MOD  1000000007
int dp[10000002][4];
int main()
{
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	//freopen("O.txt", "w", stdout);
	//freopen("I.txt", "r", stdin);
	int n;
	cin >> n;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < 4; j++)
			dp[i][j] = (-dp[i - 1][j]%MOD + dp[i - 1][0]%MOD + dp[i - 1][1]%MOD + dp[i - 1][2]%MOD + dp[i - 1][3]%MOD)%MOD;
	cout << dp[n][0] << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define ll long long int
#define v vector<ll>
#define pb push_back
#define mp make_pair
#define sor(vec) sort(vec.begin(), vec.end());
#define inf 999999999999999999
#define N (ll)1e7 + 2
#define mod 1000000007
#define f(i, n) for (ll i = 0; i < n; i++)
#define in(a, n) f(i, n) cin >> a[i];
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
bool compare(std::pair<ll, ll> i, pair<ll, ll> j)
{
    return i.second < j.second;
}
bool vis[N][2] = {false};
ll an[N][2];
ll sol(ll steps, ll same)
{
    if (steps == 0)
    {
        if (same)
            return 1;
        return 0;
    }
    if(vis[steps][same]==true)
    return an[steps][same];
    vis[steps][same]=true;
    an[steps][same]=0;
    if (same)
     an[steps][same]=3 * sol(steps - 1, 0);
    else
    an[steps][same]=2 * sol(steps - 1, 0) + sol(steps - 1, 1);
    if(an[steps][same]>=mod)
    an[steps][same]-=mod;
    return an[steps][same];
}

int main()
{
    fast;

    {
        ll n;
        cin >> n;
        ll ans = sol(n, 1);
        cout << ans << endl;
    }
}

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
long long a[10000005];
int main()
{
    a[1]=0;
    a[2]=3;
    a[3]=6;
    a[4]=21;
    for(int i=5;i<=1000000;i++){
        a[i]=((int)pow(3.0,double(i-1))-a[i-1])%1000000007;
    }
    int n;
    while(cin >> n)
        cout << a[n] <<endl;
}

#include <iostream>

using namespace std;

const int maxN =1000*1000*10+5;
int ind [maxN];
int outd[maxN];
const int moden	=	1000000007	;

int mode(int a)
{
 	return a%moden;
}
int main()
{
 	int n;
 	cin>>n;
 	ind[0]=1;
 	for (int i=1;i<=n;i++)
 	{
	 	ind[i]=mode(outd[i-1]);
	 	outd[i]=mode(ind[i-1]*3+outd[i-1]*2);
    }
 	cout<<mode(ind[n])<<endl;
}

//bayemirov
#include <bits/stdc++.h>

#define NAME ""

using namespace std;

typedef long long ll;

#define SZ(x) ((int) (x).size())
#define pb push_back
#define sqr(x) (x) * (x)

void tachyon() {ios_base::sync_with_stdio(0); cin.tie(nullptr);}

const int N = 1e7;
const ll mod = 1e9 + 7;

int n;
ll res = 4;

void check() {
    if (n == 2) cout << 3, exit(0);
    if (n == 3) cout << 6, exit(0);
}

void get() {
    for (int i = 0; i < n - 4; i++) {
        res *= 4;
        res %= mod;
    }
}

int powerByMod(int b) {
    if (b == 0)
        return 1ll;
    if (b % 2)
        return (powerByMod(b - 1) * 4) % mod;
    else
        return sqr(powerByMod(b / 2)) % mod;
}

void solve() {
    cin >> n;
    check();
    get();
    cout << (res * 21) % mod;
}

int main() {
    tachyon();
    #ifndef ONLINE_JUDGE
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    #endif
    solve();
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define _abs(x) ((x) >= 0 ? (x) : -(x))
#define _max(a, b) ((a) >= (b) ? (a) : (b))
#define _min(a, b) ((a) <= (b) ? (a) : (b))
#define _size(t) (int(t.size()))
#define _sqr(x) ((x) * (x))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef vector <int> VI;
typedef vector <VI> VVI;

/*Template written by Mashimaru*/

const int mod = 1000000007;

int n, curr;
long long dp[2][4];

int main()
{
    scanf("%d", &n);
    dp[curr][4] = 1;
    for (int i = 2; i <= n + 1; i++)
    {
        curr = 1 - curr; //
        for (int j = 1; j <= 4; j++)
        {
            dp[curr][j] = (dp[1 - curr][1] + dp[1 - curr][2] + dp[1 - curr][3] + dp[1 - curr][4] - dp[1 - curr][j]) % mod;
            if (dp[curr][j] < 0) dp[curr][j] += mod;
        }
    }
    cout << dp[curr][4] << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int memo[10000001][5];
int mod=1e9+7;
int recursive(int s, int lef){
    if(s==4 && lef==0)
        return 1;
    if(lef<=0)
        return 0;
    if(memo[s][lef]!=-1)
        return memo[s][lef];
    if(s==4)
        return memo[s][lef]=(recursive(1, lef-1)+recursive(2, lef-1)+recursive(3, lef-1))%mod;
    else if(s==1)
        return memo[s][lef]=(recursive(2, lef-1)+recursive(3, lef-1)+recursive(4, lef-1))%mod;
    else if(s==2)
        return memo[s][lef]=(recursive(1, lef-1)+recursive(3, lef-1)+recursive(4, lef-1))%mod;
    else
        return memo[s][lef]=(recursive(1, lef-1)+recursive(2, lef-1)+recursive(4, lef-1))%mod;
}
int main(){
for(int i=0; i<=4; i++)
    for(int j=0; j<=10000000; j++)
        memo[i][j]=-1;
int n;
cin>>n;
cout<<recursive(4, n);
return 0;
}

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <math.h>

const int mod=1000000007;

long long int deg[10000000],func;

void solve(int n){
	int i;
	long long int f,d;
	func=0;
	deg[0]=1;
	for(i=2;i<n+1;i++){
		d=deg[i-2]*3;
		f=d-func;
		func=f%mod;
		deg[i-1]=d%(mod*100);
	}
	printf("%I64d\n",func);
}

int main(){
#pragma comment (linker,"/STACK:16777216")
#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#endif
	int n;
	while(scanf("%d",&n)!=EOF) solve(n);
}

#include<stdio.h>
#include<iostream>
using namespace std;

long long p[10000025];
long long q[10000025];

int main(){
	long long i;
	long long n;
	p[0]=1;p[1]=0;
	q[0]=0;q[1]=1;
	cin>>n;
	for(i=2;i<=n;i++){
		q[i]=p[i-1]+(q[i-1]*2);
		p[i]=q[i-1]*3;
	}
	cout<<p[n]%1000000007<<endl;
	return 0;
}

#include<iostream>
#include<stdio.h>
using namespace std;
#define mod 1000000007
#define ll long long
int f[10000010];
int pow(ll a,ll b)
{
    if(b==0)return 1;
    if(b%2==0)return pow((a*a)%mod,b/2);
    else return (a*pow((a*a)%mod,b/2))%mod;
}
void inits(int n)
{
    f[1]=0;
    for(ll i=2;i<=n;i++)
    f[i]=(pow(3,i-1)-f[i-1])%mod;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        inits(n);
        printf("%d\n",f[n]);
    }
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin>>n;

    vector<vector<int> > C(4 , vector<int>(n+1,0));

    C[1][1] = 1;
    C[2][1] = 1;
    C[3][1] = 1;

    for(int j=2 ; j<= n ; j++){
        for(int i=0 ; i<4 ; i++){
            for(int k=0 ; k<4 ; k++){
                if(k!=i){
                    C[i][j] += C[k][j-1];
                }
            }
        }
    }

    cout<<C[0][n];
    return 0;
}

// This works!!
//Data-structures includes
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>

//Other Includes
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cstdlib>
#include<cstdio>
#include<cmath>

using namespace std;

#define pb		push_back
#define mp	 	make_pair
#define fill(a,v) 	memset(a, v, sizeof(a))
#define sz		size()
#define all(x)		x.begin(), x.end()
#define INDEX(arr,ind)	(lower_bound(all(arr),ind)-arr.begin())
#define FF		first
#define SS		second
#define T(t)            int t;scanf ("%d",&t);while (t--)
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long int LL;
typedef vector<long long> VLL;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
typedef pair<double,double> pdd;

#define M 1000000007
LL  pw(LL num)
{
	LL temp=3;
	LL ans=1;
	while (num)
	{
	if (num&1)
		ans=(ans*temp)%M;
	temp=(temp*temp)%M;
	num>>=1;
	}
	return ans;
}
LL dp[10000001];

int main()
{
	LL  n,cn=0;cin >> n;
	LL  in=1,i,z=0;
	if (n==1) cout << "0" << endl;
	else
	{
	//LL value=pw(n-1);//cout << value <<endl;
	dp[0]=1;
	for (i=1;i<n;i++)
		dp[i]=(3*dp[i-1])%M;
	for (i=n-1;i>0;i-=2)
		z=(z+dp[i]-(i>1?dp[i-1]:0))%M;
	cout << (z)%M << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MOD=10e9+7;
int recur(int n)
{
    int dp[2][n+1];
    dp[1][0]=1;
    dp[0][0]=0;
    for(int j=1;j<=n;j++)
    {
        dp[1][j]=3*dp[0][j-1]%MOD;
        dp[0][j]=(2*dp[0][j-1]+dp[1][j-1])%MOD;
    }
    return dp[1][n];
}
int main()
{
    int x;
    cin>>x;
    cout<<recur(x);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mod 100000007
#define ll long long
const int N = 1e7+2, M = N;
//=======================
int dp[2][N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,k,j;
	cin >> n;
	dp[1][0] = 1;
	for(int steps = 1; steps < N; steps++){
		dp[1][steps] = (3LL*dp[0][steps-1])%mod;
		dp[0][steps] = (2LL*dp[0][steps-1] + dp[1][steps-1])%mod;
	}
	cout << dp[1][n] << endl;

	return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;

const int mod = 1000000007;

int n, curr;
long long dp[2][4];

int main()
{
    scanf("%d", &n);
    dp[curr][4] = 1;
    for (int i = 1; i <= n; i++)
    {
        curr = 1 - curr;
        long long temp = dp[1 - curr][1] + dp[1 - curr][2] + dp[1 - curr][3] + dp[1 - curr][4];
        for (int j = 1; j <= 4; j++)
            dp[curr][j] = (temp - dp[1 - curr][j]) % mod;
    }
    cout << dp[curr][4] << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll m=1e9+7;
//ll dp[4][10000001];
/*
ll func(ll src,ll des,ll steps) //des=3 (fixed)
{
	if(steps==0)
	{
		if(src==des)
			return 1;
		return 0;
	}
	if(dp[src][steps]!=-1)
		return dp[src][steps];
	ll ans=0;
	for(ll i=0;i<=3;i++)
	{
		if(i!=src)
			ans=(ans%m+(func(i,des,steps-1))%m)%m;
	}
	dp[src][steps]=ans;
	return ans;
}
*/
int main()
{
	ios::sync_with_stdio(false);
	ll n,i,j;
	cin >> n;
	ll dp[4][n];
	dp[0][0]=0;
	dp[1][0]=0;
	dp[2][0]=0;
	dp[3][0]=1;
	for(j=1;j<=n;j++)
	{
		dp[0][j]=(dp[1][j-1]%m+dp[2][j-1]%m+dp[3][j-1]%m)%m;
		dp[1][j]=(dp[0][j-1]%m+dp[2][j-1]%m+dp[3][j-1]%m)%m;
		dp[2][j]=(dp[1][j-1]%m+dp[0][j-1]%m+dp[3][j-1]%m)%m;
		dp[3][j]=(dp[1][j-1]%m+dp[2][j-1]%m+dp[0][j-1]%m)%m;
	}
	ll ans=dp[3][n]%m;
	cout << ans << "\n";
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int mod=1e9;
int dp[10000005][5];
int n;
int fun(int i,int k)
{
    if(i==n) return !k;
    if(dp[i][k]!=-1) return dp[i][k];
    long long ans=0;
    for(int j=0;j<4;j++)
    {
        if(j!=k) ans=(ans%mod+fun(i+1,j)%mod)%mod;
    }
    return dp[i][k]=ans%mod;
}

int main()
{
    scanf("%d",&n);
    memset(dp,-1,sizeof dp);
    long long ans=fun(0,0);
    printf("%lld\n",ans);
    return 0;
}

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

typedef long long ll;

ll checkutil(ll n,int src,int dest)
{
    ll dp[2][n+1];
    dp[0][0]=0;
    dp[1][0]=1;
    for(int i=1;i<=n;i++)
    {
        dp[0][i]=2*dp[0][i-1]+dp[1][i-1];
        dp[1][i]=3*dp[0][i-1];
    }
    return dp[1][n]%mod;
}

main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    ll n;
    cin>>n;
    cout<<checkutil(n,0,3)<<"\n";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,j;
    int p=1;
    for(i=0;i<n-2;i++)
p=p*3;
if(p==1)
p=0;
p=p*2;
p=p+3;
cout<<p;
return 0;

}

#include <iostream>
using namespace std;
const int c=1000*1000*1000+7;

int main()
{
	int n;
	cin>>n;
	long long t=1;
	long long z=-1;
	long long sum=0;
	if(n==1)
	{
		cout<<0;
		return 0;
	}
	if(n%2==1)
		for(int i=1;i<=n-1;i++)
		{
			t*=3;
			t%=c;
			sum+=z*t;
			sum%=c;
			z*=(-1);

		}
	if(n%2==0)
		for(int i=1;i<=n-1;i++)
		{
			t*=3;
			t%=c;
			z*=(-1);
			sum+=z*t;
			sum%=c;

		}
	cout<<sum;

}

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

#define FOR(i , a , b) for(int64_t i = a ; i <= b ; ++i)
#define FORX(i , a , b) for(int64_t i = a ; i < b ; ++i)
#define FORD(i , a , b) for(int64_t i = a ; i >= b ; --i)
#define FORDX(i , a , b) for(int64_t i = a ; i > b ; --i)
#define REP(i , n) for(int64_t i = 0 ; i < n ; ++i)
#define REPD(i , n) for(int64_t i = n - 1 ; i >= 0 ; --i)
#define FORITE(i , A) for( i = A.begin() ; i != A.end() ; ++i)
#define ii pair<int,int>
#define QUEUE priority_queue
#define fi first
#define se second
#define TASK "ABA15E"
#define en "\n"
#define sp " "
#define val_sum accumulate
#define ite iterator
#define maxx_int (int) 0x3f3f3f3f
#define maxx_int64_t (int64_t) 0x3f3f3f3f3f3f3f3f
#define max_el *maxn_element
#define min_el *min_element
#define all(A) (A.begin() , A.end())
#define maxn (int) 1e2 + 2
#define se(i) setprecision(i)
#define COMBINE(a, b) ((a)*1000000010 + (b))
#define EXTRACTFIRST(combined) ((combined) / 1000000010)
#define EXTRACTSECOND(combined) ((combined) % 1000000010)

using namespace std;
int64_t n , T;

const int Mod = 1e9 + 7;

struct Box{
    int64_t M[3][3];
};

Box operator * (Box A , Box B){
    Box C;
    REP(i , 3)
        REP(j , 3){
            C.M[i][j] = 0;
            REP(k , 3)
                C.M[i][j] = (C.M[i][j] + A.M[i][k] * B.M[k][j]) % Mod;
        }
    return C;
}

Box pow(Box A , int64_t k){
    if(k == 1)
        return A;
    auto B = pow(A , k / 2);
    B = B * B;
    if(k &  1)
        B = B * A;
    return B;
}

Box pre;

void input(){
    #ifndef ONLINE_JUDGE
    freopen( TASK".inp" , "r" , stdin);
    freopen( TASK".out" , "w" , stdout);
    #endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre.M[0][0] = 0;
    pre.M[0][1] = 1;
    pre.M[0][2] = 0;
    pre.M[1][0] = 0;
    pre.M[1][1] = 0;
    pre.M[1][2] = 1;
    pre.M[2][0] = 0;
    pre.M[2][1] = 3;
    pre.M[2][2] = 3;

}

int64_t value(int64_t n){
    if(n == 1)
        return 0;
    if(n == 2)
        return 3;
    Box res = pow(pre , n - 1);
    return (res.M[0][1] * 3 % Mod + res.M[0][2] * 3 % Mod) % Mod;
}

void proccess(){
    cin >> n;
    cout << value(n) << en;
}

int main(){
    input();
    proccess();
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define _abs(x) ((x) >= 0 ? (x) : -(x))
#define _max(a, b) ((a) >= (b) ? (a) : (b))
#define _min(a, b) ((a) <= (b) ? (a) : (b))
#define _size(t) (int(t.size()))
#define _sqr(x) ((x) * (x))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef vector <int> VI;
typedef vector <VI> VVI;

/*Template written by Mashimaru*/

const int mod = 1000000007;

int n, curr;
long long dp[2][4];

int main()
{
    scanf("%d", &n);
    dp[curr][4] = 1;
    for (int i = 2; i <= n + 1; i++)
    {
        curr = 1 - curr;
        for (int j = 1; j <= 4; j++)
            dp[curr][j] = (dp[1 - curr][1] + dp[1 - curr][2] + dp[1 - curr][3] + dp[1 - curr][4] - dp[1 - curr][j]) % mod;
    }
    if (n == 1) cout << 0 << endl;
    else cout << dp[curr][4] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define m 1000000007;

int main()
{
    int steps,start=0,i;
    cin>> steps;
    int dp[2][steps+1];// means dp[destination][steps], source will be 0 always, we are trying to go to source
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    dp[1][0]=0;
    for(i=1;i<=steps;i++)
    {
        dp[0][i]+=(3*dp[1][i-1])%m;
        dp[1][i]+=(dp[0][i-1]+2*dp[1][i-1])%m;
    }
    cout << dp[0][steps]%m;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long

long int mod =  1000000007 ;

int main(){
   IOS;

   long int n;
   cin>>n;

   if(n == 1){
   		cout<<"0";
   		return 0;
   }
   	int a=0,b=0,c=0,d=1;
   	for(int i=1;i<n;i++){
   		int aa=a,bb=b,cc=c,dd=d;
   		a= (bb+cc+dd) % mod;
   		b= (aa+cc+dd) % mod;
   		c= (aa+bb+dd) % mod;
   		d= (aa+bb+cc) % mod;

   		a %= mod;
   		b %= mod;
   		c %= mod;
   		d %= mod;

   	}
   		cout<<(a+b+c) % mod;

   // vector<vector<long int>> dp(n+1,vector<long int>(4));

   // dp[0][3] = 1;

   // 	for(long int i = 1; i <= n; i++){
   // 		for(long int j = 0; j < 4; j++){
   // 			for(long int k = 0; k < 4; k++){
   // 				if(k == j)
   // 					continue;
   // 				dp[i][j] += dp[i-1][k];
   // 				dp[i][j] %= mod;
   // 			}
   // 		}
   // 	}
   	// for(auto vec : dp){
   	// 	for(auto ele : vec)
   	// 		cout<<ele<<" ";
   	// 	cout<<endl;
   	// }

   	// long int ans = 0;
   	// for(long int i = 0; i < 3; i++){
   	// 	ans += dp[n-1][i];
   	// 	ans %= mod;
   	// }

   	// if(ans)
   		// cout<<ans;
   	// else
   	// 	cout<<"0";
   return 0;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define LLint long long int
#define Lint long int
#define Ldouble long double

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    int m = 1e9 + 7;

    vector<vector<Lint>> f(5, vector<Lint>(n + 1));
    f[1][0] = f[2][0] = f[3][0] = 0;
    f[4][0] = 1;
    for (int i = 1; i <= n; i++) {
        f[1][i] = f[2][i - 1] + f[3][i - 1] + f[4][i - 1];
        f[1][i] %= m;
        f[2][i] = f[1][i - 1] + f[3][i - 1] + f[4][i - 1];
        f[2][i] %= m;
        f[3][i] = f[1][i - 1] + f[2][i - 1] + f[4][i - 1];
        f[3][i] %= m;
        f[4][i] = f[1][i - 1] + f[2][i - 1] + f[3][i - 1];
        f[4][i] %= m;
    }

    cout << f[4][n];
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
struct mat{
	int x11;
	int x12;
	int x21;
	int x22;
};
mat mul(mat m1,mat m2)
{
	mat ret;
	ret.x11=(m1.x11+m2.x11)+(m1.x12*m2.x21);
	ret.x12=(m1.x11+m2.x12)+(m1.x12*m2.x22);
	ret.x21=(m1.x21+m2.x11)+(m1.x22+m2.x21);
	ret.x22=(m1.x21+m2.x12)+(m1.x22+m2.x22);
	return ret;
}
mat binexp(int n,mat x)
{
	if(n==1)
	{
		return x;
	}
	mat temp;
	if(n%2==0)
	{
		temp=binexp(n/2,x);
		return mul(temp,temp);
	}
	else
	{
		temp=binexp(n/2,x);
		return mul(mul(temp,temp),x);
	}
}
int main()
{
	int n;
	cin>>n;
	mat magic;
	magic.x11=3;
	magic.x12=0;
	magic.x21=2;
	magic.x22=1;
	mat final=binexp(n,magic);
	cout<<final.x12<<endl;
	return 0;
}

	#include<bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	const ll dim=2; // dimension of matrix to be multiplied
	void multiply(ll a[dim][dim], ll b[dim][dim])
	{
		ll mul[2][2];
		for (ll i = 0; i < dim; i++)
		{
			for (ll j = 0; j < dim; j++)
			{
				mul[i][j] = 0;
				for (ll k = 0; k < dim; k++)
					mul[i][j] += a[i][k]*b[k][j];
			}
		}

		// storing the muliplication resul in a[][]
		for (ll i=0; i<dim; i++)
			for (ll j=0; j<dim; j++)
				a[i][j] = mul[i][j]; // Updating our matrix
	}
	ll power(ll F[dim][dim], ll n)
	{
		ll M[dim][dim] = {{2,1}, {3,0}};
		if (n==1)
			return 0;
		power(F, n/2);
		multiply(F, F);
		if (n%2 != 0)
			multiply(F, M);
		return F[1][1] ;
	}
	ll findNthTerm(ll n)
	{
		ll F[dim][dim] = {{2,1}, {3,0}};
		return power(F, n);
	}
	int main()
	{
		ios::sync_with_stdio(0);
		ll n;
		cin >> n;
		ll ans=findNthTerm(n) ;
		cout << ans << "\n";
		return 0;
	}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll power(ll x,ll y,ll p)
{
    ll res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
int main()
{
    ll n;cin>>n;
    if(n==1)cout<<0;
    else
    {
        ll back=0;
        ll ans=0;
        for(ll i=2;i<=n;i++)
        {
            ans=power(3,i-1,10000000007)-back;
            back=ans;
        }
        cout<<ans<<endl;
    }
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <cmath>
#define P 1000000007

using namespace std;

int n;
bool used[10000000][4];
unsigned int mas[10000000][4];

int f(int n	, int v)
{
	if (n==1)
		if (v==0) return 0;
		else return 1;
	if (used[n][v]) return mas[n][v];
	used[n][v]=1;
	mas[n][v]=0;
	if (v!=0)
		{
			mas[n][v]+=f(n-1, 0);
			mas[n][v]%=P;
		}
	if (v!=1)
		{
			mas[n][v]+=f(n-1, 1);
			mas[n][v]%=P;
		}
	if (v!=2)
		{
			mas[n][v]+=f(n-1, 2);
			mas[n][v]%=P;
		}
	if (v!=3)
		{
			mas[n][v]+=f(n-1, 3);
			mas[n][v]%=P;
		}
	return mas[n][v];
}

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	cin >> n;
	cout << f(n,0);
	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;

int n_2(long long int n,long long int k,long long int flag,int i,long long  *l)
{
  n=n-1;
  flag=k%1000000007;
  *l=(*l*3);
  *l=*l%1000000007;
  k=(*l-flag)%1000000007;

  i++;
  if (n>2)
  {n_2(n,k,flag,i,l);}
  if (n==2)
  {
    return flag;}
}

int main()
{
long long int n,ans,k=0,flag=0;
long long  l=1;
int i=1;
cin>>n;
if (n==1)
{cout<<0;}
if(n==2)
{cout<<3;}
if (n>=3)
{
flag=n_2(n,k,flag,i,&l);

k=l-flag;

ans=((k*2)+flag*3);
cout<<(ans%1000000007);
}

}

// Codeforces.cpp : Defines the entry point for the console application.
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>

#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

const long long MOD = 1000000007;

int main(int argc, char* argv[])
{
#ifndef ONLINE_JUDGE
	//local run

	//freopen("input.txt", "r", stdin);
#else
	//online judge

	//freopen("search.in", "r", stdin);
	//freopen("search.out", "w", stdout);
#endif

	long long n; cin >> n;
	//vector<vector<int> > d(n + 1, vector<int>(4, 0));
	long long D = 1, ABC = 0;

	for (long long i = 1; i <= n; i++)
	{
		long long d = (D + 3 * ABC) % MOD;
		long long abc = (2 * ABC + D) % MOD;

		D = d;
		ABC = abc;
	}

	cout << D << endl;

	return 0;

}

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
long long int n,k=0,flag=0;
cin>>n;
if (n==1)
{printf("%d",n );}
if (n==2)
{printf("%d",n+1 );}
if (n==3)
{printf("%d",n+3 );}
if (n>=4)
{
  k=(((pow(3,(n-2))-(3*pow(2,(n-4))))*2)+(3*pow(2,(n-4))*3));

  printf("%d",k );}

}

/*

 */

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;

int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e17
#define EPS 1e-12
#define MLOG 20
#define MAX 10 * 1000 * 1000+5
const int mod = 1e9+7;

int dcmp(long double x, long double y){
	return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}

void fast(){
#ifndef ONLINE_JUDGE
	freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
	freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif

	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int n;
string s = "abcd";
int dp[MAX][2];

int rec(int idx, int lst){
	if (idx == n){
		return (lst == 1);
	}

	int &ret = dp[idx][lst];
	if (~ret)
		return ret;

	ret = 0;
	if (lst){
		ret += rec(idx + 1, 0)%mod * 3%mod;
	}
	else{
		ret += rec(idx + 1, 0)%mod * 2%mod;
		ret %= mod;
		ret += rec(idx + 1, 1)%mod;
		ret %= mod;
	}
	return ret;
}
int main(){
	fast();
	memset(dp, -1, sizeof dp);
	cin >> n;
	cout << rec(0, 1) << endl;
	return 0;

}

#include <iostream>
#include <vector>

using namespace std;

long long const MOD = 1000000007;

int main()
{
    vector<long long> vec(4);

    vec[0] = 1;

    int N;
    cin >> N;

    vector<long long> next(4);
    for (int i = 0; i < N; i++)
    {
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (i == j) continue;
                next[i]  = (next[i] + vec[j])% MOD;
            }
        }
        vec.swap(next);
    }

    cout << vec[0] << endl;
    return 0;
}

#include<cstdio>
#include<algorithm>
#define MOD 1000000007

using namespace std;
long long dp[2];
int main()
{
    long long n;
    long long i;
    scanf("%I64d",&n);
    if(n == 1)
        printf("0");
    else
        {
            dp[0] = 3; dp[1] = 0;
            for(i = 2 ; i < n ; i++)
            {
                dp[1] = dp[0] - dp[1];
                dp[0] *= 3;
            }
            printf("%I64d",(dp[0]-dp[1])%MOD);
        }
}

#include <bits/stdc++.h>

using namespace std;

long long w = 10000001;
unordered_map<long ,long > dp;
vector<long long>power;

long countArray(int n) {

    if(n==2)return 0;
    if(n==3)return 3;

    if(dp.find(n-2)==dp.end() )dp[n-2]=countArray(n-2)%1000000007;
    //cout<<n<<" "<<dp[(n-2)*w+x]<<endl;
    return ((dp[n-2]*3)%1000000007+ (((power[n-3]-dp[n-2]+1000000007)%1000000007)*2)%1000000007)%1000000007;
}

int main() {
    int n;

    cin >> n;
    long p = 1;
    for(int i=0;i<=1e7;i++){
        power.push_back(p);
        p *= 3;
        p%=1000000007;
    }
    long answer = countArray(n+1);
    cout << answer << endl;
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int num[10000005];
void inint()
{
     num[1]=0;
     num[2]=3;
     num[3]=6;num[4]=21;
     for(int i=5;i<10000001;i++)
     { long long sum=3*num[i-2]+2*num[i-1];
     sum%=1000000007;
     num[i]=(int)sum;
     }
 }
 int main()
 {
     int n;
     while(scanf("%d",&n)==1)
     {
                             cout<<num[n]<<endl;
     }
 }

#include <string.h>
#include <math.h>
#include <limits.h>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include<cstdio>
#include<cstring>
#include<vector>
#include<complex>
#define _USE_MATH_DEFINES//M_PI

// Input macros
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define p(n)                       printf("%d\n",n)
#define pc(n)                       printf("%c\n",n)
#define ps(n)                       printf("%s\n",n)
#define pf(n)                       printf("%lf\n",n)
#define pl(n)                      printf("%I64d\n",n)

// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-9

// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd

// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(i=a;i<b;i++)
#define foralle(i,a,b)               for(i=a;i<=b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair

// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())
//#include <conio.h>

using namespace std;
long long int m=1000000007;
long long int power(long long int x,long long int y)
{
    long long int p;
    if( y == 0)
     return 1;
    else if (y%2 == 0)
     {
         p=power(x, y/2)%m;
         return ((p)*(p))%m;
     }
    else
     {
         p=power(x, y/2)%m;
         return ((((x%m)*(p))%m)*(p))%m;
     }

}

int main(int argc, char *argv[])
{

    long long int n,x;
    sl(n);
    x=(  (power(3,n)- power(-1,n-1)*3)/4  );
    pl(x);
    //getch();
    return 0;
}

#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
// #define int unsigned int

#define num 1e9+7
#define max 1e6

int32_t main()
{
	// cout<<"HEllo"<<endl;

	unsigned int n;cin>>n;
	// cout<<"inputed"<<endl;
	int a[int(max)+1];
	for (int i = 0; i < max+1; ++i)
	{
		/* code */
		a[i] = 0;
	}

	// cout<<"initia;ised"<<endl;
	a[1] = 0;
	a[2] = 1;
	a[3] = 2;
	for(int i=4;i<=max;i++){
		// int x = (a[i-3]+2)%int(num);
		unsigned int y =  (a[i-2]*3)%int(num);
		unsigned int z = ((a[i-1])*2)%int(num);
		z = (z+y)%int(num);
		a[i] = z;
	}

	// for (int i = 0; i < 20; ++i)
	// {
	// 	 code
	// 	cout<<a[i]<<" ";
	// }
	// cout<<endl;

	cout<<3*a[n];

	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
long long int d[10000000];long long int yy=3;
long long int power(long long int l)
{long long int y=1;
	for (long long int i = 1; i <= l; ++i)
	{
		y=y*3%1000000007;
	}
	return y;
}
int main(int argc, char const *argv[])
{
	long long int n;
	cin>>n;
	d[2]=3;d[1]=0;d[0]=0;
	for (int i = 3; i <= n; ++i)
	{yy=yy*3%1000000007;

		d[i]=yy-d[i-1]%1000000007;

	}
   if (d[n]<0)
   {
   	cout<<1000000007+d[n];
   }
   else
   	cout<<d[n];
	return 0;
}

// ------- PBDS ------ //
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// ------- PBDS ------ //

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define pi 3.1415926535
#define endl "\n"
#define vll vector<ll>
#define MULTI int T; cin >> T; while(T--)
#define all(a)      (a).begin(),(a).end()
#define here cout<<"I'm here\n";
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele<<" "; cout<<endl;
}
vector<ll> adj[200001];
bool vis[200001];

// ------- PBDS ------ //
typedef tree<
// change this for any data-type
string,
null_type,
// change this for any data-type
less<string>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

/*
    to get the position of an element in set , do
    s.order_of_key(ele);
    this returns the number of elements strictly lesser than ele in set s
    Let us assume we have a set s : {1, 5, 6, 17, 88}, then :
    s.order_of_key(6) : Count of elements strictly smaller than 6 is 2.
    s.order_of_key(25) : Count of elements strictly smaller than 25 is 4.

    to get the element at position k
    s.find_by_order(k);
    returns an iterator to the ele counting from 0
    Let us assume we have a set s : {1, 5, 6, 17, 88}, then :
    *(s.find_by_order(2)) : 3rd element in the set i.e. 6
    *(s.find_by_order(4)) : 5th element in the set i.e. 88
*/

// ------- PBDS ------ //

clock_t time_p=clock();
void purvansh11()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

//BINARY EXPONENTIATION  -- O(log2(b))
ll power(ll a, ll b) {
    /*
        for 3^11 :
        as 11 -> 1011, we mean 3^8 * 3^2 * 3^1
        so multiply for all ones in binary rep of b
    */

    ll ans = 1;
    ll num = a;
    while (b > 0) {
        if (b & 1) ans = ((ans % MOD) * (num % MOD)) % MOD;
        num = ((num % MOD) * (num % MOD)) % MOD;
        b /= 2;
    }
    return ans;
}
ll dp[5];
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    SPEED;
    cout.precision(8);
    cout << fixed;

    ll n;
    cin>>n;

    dp[0]=0;
    dp[1]=0;
    dp[2]=0;
    dp[3]=1;
    for(ll i=1;i<=n;i++){
        ll a=dp[0];
        ll b=dp[1];
        ll c=dp[2];
        ll d=dp[3];
        for(ll j=0;j<4;j++){
            dp[j]=(a%MOD+b%MOD+c%MOD+d%MOD)%MOD;
            if(j==0) dp[j]-=a;
            if(j==1) dp[j]-=b;
            if(j==2) dp[j]-=c;
            if(j==3) dp[j]-=d;
        }

    }
    cout<<dp[3];

    purvansh11();
    return 0;
}

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int n, abc = 0, d = 1, nabc, nd;
	const int MODULO = 1000000007;

	scanf("%d", &n );

	for ( int i = 0; i < n; i++ )
	{
		nabc = ( abc * 2L + d ) % MODULO;
		nd = ( abc * 3L ) % MODULO;

		abc = nabc;
		d = nd;
	}

	printf("%d", d );

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
	const int mod = 1e9 + 7;
	int n;
	cin >> n;
	vector<vector<int>> dp(4, vector<int>(n + 1));
	dp[3][0] = 1;
	for (int i = 0; i < n; i++) {
		int s = 0;
		for (int j = 0; j < 4; j++) s += dp[j][i];
		for (int j = 0; j < 4; j++) {
			dp[j][i + 1] = ((0LL + s - dp[j][i]) % mod + mod) % mod;
		}
	}
	cout << dp[3][n] << '\n';
	return 0;
}

#include <iostream>
#define m %1000000007
using namespace std;

int f(int n, char pos)
{
    if(!n)
    {
        if(pos=='D')
        return 1;
        else return 0;
    }
    if(pos=='D')
    return (3*(f(n-1,'A')m))m;
    else return (f(n-1,'D')m)+(2*(f(n-1,'A')m))m;

}

int main()
{
    int n;
    cin >> n;
    cout << f(n,'D');
    return 0;
}

#include<iostream>
#include <math.h>
using namespace std;
long long n,k,a,a2,b,answer;
long long t = 1000000007;
int main()
{
  cin>>n;
  k=3*(pow(-1, n));
  a = pow(3, n);
  b = (k+a);
  answer = abs(b/4)%t;
  cout<<answer;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define rep(i,n) for(int(i)=0;(i)<(int)n;(i)++)
#define clr(v,idx) memset(v,idx,sizeof(v));
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl '\n'
//const int dx[] = {1,-1,0,0,1,-1,1,-1};
//const int dy[] = {0,0,1,-1,1,-1,-1,1};
void carrotiq() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}

int n;
int dp[4][10000007];

int main()
{
	fast();
	carrotiq();
	cin>>n;
	dp[3][0]=1;
	for (int i = 1; i <= n; ++i)
	{
		dp[0][i]=(dp[1][i-1]+dp[2][i-1]+dp[3][i-1],dp[0][i])%1000000007;
		dp[1][i]=(dp[0][i-1]+dp[2][i-1]+dp[3][i-1],dp[1][i])%1000000007;
		dp[2][i]=(dp[1][i-1]+dp[0][i-1]+dp[3][i-1],dp[2][i])%1000000007;
		dp[3][i]=(dp[1][i-1]+dp[2][i-1]+dp[0][i-1],dp[3][i])%1000000007;
	}
	cout<<dp[3][n];
}

#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cctype>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <complex>
#include <numeric>
#include <valarray>
#include <iostream>
#include <memory.h>
#include <algorithm>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i(0),_n(n);i<_n;++i)
template<class T> int len(const T&c){return (int)c.size();}
typedef long long ll;
#define repe(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
typedef vector<int> vi;
typedef vector<string> vs;
int a,b,c,d,aa,bb,cc,dd,n,ans;
int mod =1000000007;

int main(){
	cin>>n;
	d=1;
	a=b=c=aa=bb=cc=dd=0;
	rep(i,n-1){

		aa=d%mod;
		bb=d%mod;
		cc=d%mod;
		dd=0;

		bb+=a%mod;
		cc+=a%mod;
		dd+=a%mod;

		aa+=b%mod;
		cc+=b%mod;
		dd+=b%mod;

		aa+=c%mod;
		bb+=c%mod;
		dd+=c%mod;

		a=aa;
		b=bb;
		c=cc;
		d=dd;

	}
	ans=(a+b+c)%mod;
	cout<<ans;

}

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
	vector<long long> Ways = vector<long long>(4);
	Ways[0] = 1;
	Ways[1] = 0;
	for (int i = 1;i < n+1; i++)
	{
		Ways[2*(i%2)]   = 3*Ways[2*((i+1)%2)+1];//D
		Ways[2*(i%2)+1] = Ways[2*((i+1)%2)]+2*Ways[2*((i+1)%2)+1];//A
	}
	cout << (Ways[2*(n%2)]%(1000000007));
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 5;
const long long mod = 1e9 + 7;

int n;
vector< vector<int> > d(5, vector<int> (N - 4, 0));

void another_one()
{
    d[1][0] = 1;
    for (int j = 1; j <= n; j++)
    {
        for (int i = 1; i <= 4; i++)
        {
            d[i][j] = ((i != 1) ? d[1][j - 1] : 0) % mod + ((i != 2) ? d[2][j - 1] : 0) % mod + ((i != 3) ? d[3][j - 1] : 0) % mod + ((i != 4) ? d[4][j - 1] : 0) % mod;
            d[i][j] %= mod;
        }
    }

    cout << d[1][n] << '\n';
}

int main()
{
    cin >> n;
    another_one();
    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;

typedef long long ll;

ll mod = 1e9+7;

ll fastexp(ll n)
{
    if (n == 1) return 3;
    ll half = fastexp(n/2)%mod;
    if (n %2 == 0) return (half*half)%mod;
    else return (((half*3)%mod)*half)%mod;
}
int main()
{
    ll n;
    scanf("%lld",&n);
    if (n == 0) printf("0");
    else
    {
        if (n %2 == 0)
        {
            printf("%lld",((fastexp(n) + 3)/4)%mod);
        }
        else
        {
            printf("%lld",((fastexp(n) - 3)/4)%mod);
        }
    }

    return 0;
}

// Mujhe jod mat kisi aur ke usool se .. Hype Game
// Baat karun sirf apne liye, Aur mujhe maharani se nafrat hai

#include<bits/stdc++.h>
using namespace std;

#define ll                  long long
#define aint(x)              x.begin(), x.end()
#define le(x)               cout << #x << ' ' << x << '\n'
#define lex(a, n)           cout << #a << " : "; loop(i, 0, n) cout << a[i] << ' '; xd
#define xd                  cout << '\n'
#define fi                  first
#define se                  second
#define pb                  push_back
#define vl                  vector<int>
#define show(x)             cout << #x << " : "; for(auto i : x) cout << i << ' '; xd
#define Google              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Code()              Google;  int T; cin >> T; while(T-- )
#define loop(i, a, b)       for(int i = a; i < b; ++i )
#define rep(i, b, a)        for(int i = b - 1; i >= a; --i)

const int N = 1e7 + 2, inf = 1e9 + 7;
int dp[2][N];
int main()
{
        Google;
        int n;
        cin >> n;
        dp[1][0] = 1;
        for(int i = 1; i <= n; ++i) {
            dp[1][i] = 3 * dp[0][i - 1];
            dp[0][i] = 2 * dp[0][i - 1] + dp[1][i - 1];
        } cout << dp[1][n];
}

#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-9

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(_) ((_)*(_))

#define cb(_) ((_)*(_)*(_))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bclzl(x) (__builtin_clzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template<class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1), gn(x2), gn(x3);}

template<class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1), gn(x2), gn(x3), gn(x4);}

template<class T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T> inline void printsp(T x) {print(x); putchar(' ');}

template<class T> inline void println(T x) {print(x); putchar('\n');}

template<class T1, class T2> inline void print(T1 x1, T2 x2){printsp(x1), println(x2);}

template<class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3){printsp(x1), printsp(x2), println(x3);}

template<class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4){printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	scanf("%d",&n);

	int m,i=0;

	if(n%2==0) i++;

	else i--;

	m=(pow(3,n-1)+i)*3/4;

	printf("%d",m%mod);

}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define ll long long
#define endl "\n"
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define hell 1000000007
#define ff first
#define ss second
#define pii pair<ll,ll>
#define bs binary_search
#define upd upper_bound
#define lbd lower_bound
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<string,ll>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define sz(x) x.size()

using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define N 200050

ll i=0,j=0,res=0,start=0,finall=0,mx=0,mn=hell,len=0,cnt1=0,cnt2=0,cnt3=0,cnt=0,eend=0;int flag=0;ll pos=0;ll sum=0;ll ans=0;

ll powr(ll a,ll b)
{
    ll i=0;
    ll ans=1;
    for(i=1;i<=b;i++)
    {
        ans*=a;
    }
    return ans;
}

int main()
{
    IOS;
    ll n;
    cin>>n;
    ll dp[4][n+1];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    dp[1][0]=0;
    dp[2][0]=0;
    dp[3][0]=0;
    for(ll k=1;k<=n;k++)
    {
        for(i=0;i<=3;i++)
        {
            for(j=0;j<=3;j++)
            {
                dp[i][k]=(dp[i][k]+dp[j][k-1])%hell;
            }
            dp[i][k]-=dp[i][k-1];
        }
    }
    cout<<dp[0][n]<<endl;
}

#include <iostream>
#include <vector>
using namespace std;

long long int mod=1e+9 + 7;

long long int modulo(long int a, long int b){
	long long r;
	r=a%b;
	if(r<0){
		r+=b;
	}
	return r;
}

int Tetrahedron(int n){
	vector<long long int> m(2);
	m[0]=3;
	m[1]=3;
	for(int i=1;i<n;++i){
		vector<long long int> aux(2);
		aux[0]=3*m[0]%mod;
		aux[1]=modulo(aux[0]-m[1],mod);
		m=aux;
	}
	/*for(size_t i=0;i<m.size();++i)
		cout<<m[i][0]<<" - "<<m[i][1]<<endl;*/
	return modulo(m[0]-m[1],mod);
}

int main(int argc, char *argv[]) {
	int n;
	cin>>n;
	cout<<-5%10<<endl;
	cout<<Tetrahedron(n);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

int memo[5000500], n;

int pd(int size) {
	if(size == n-1) return 0;
	if(size == n)return 1;

	int& pdm = memo[size];
	if(pdm != -1) return pdm;

	unsigned int answr = 0, power = 1;

	for(int i=2; size+i <= n; i++) {
		answr = (answr + (3*((power*(pd(size + i))%MOD)% MOD)) % MOD) % MOD;
		power = (power*2) % MOD;
	}

	return pdm = answr;
}

int main() {
	memset(memo,-1,sizeof(memo));

	cin >> n;

	cout << pd(0) << endl;

	return 0;
}