#include<cstdio>
using namespace std;
unsigned long long pow_mod(int a,long long b,int mod){
if( b == 0 ) return 1;
if( b == 1 ) return a%mod;
unsigned long long ans = pow_mod(a,b>>1,mod);
ans = ans*ans % mod ;
if( b & 1 ) ans = ans*a%mod;
return ans;
}
int main(){
freopen("NO1shuta.in","r",stdin);
freopen("NO1shuta.out","w",stdout);
unsigned long long n;scanf("%lld",&n);
printf("%lld",pow_mod(3,n,5201314)-1);
}