import java.util.Scanner; class Main{ static int[][] I={{1,0},{0,1}}; static int mod=1000; static int[][] pow(int[][] a,int x){ if(x==1 || x==0) return a; else if(x%2==0) return pow(mul(a,a),x/2); else return mul(pow(mul(a,a),x/2),a); } static int[][] mul(int[][] a,int[][] b){ int[][] res=new int[2][2]; for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ for(int k=0;k<2;k++){ res[i][j]+=a[i][k]*b[k][j]; res[i][j]%=mod; } } } return res; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int[][] a={{1,3},{1,1}}; int[][] ans=pow(a,n); if(n==0) System.out.println(1); else System.out.println((2*ans[0][0]+(n%2==0 ? -1 : 0))%mod); } } }