import java.util.Scanner; class BiMtx { int a,b,c,d; void set(int p, int q, int r, int s){ a=p; b=q; c=r; d=s; } void set(BiMtx A){ a = A.a; b = A.b; c = A.c; d = A.d; } BiMtx (int p, int q, int r, int s){ set(p,q,r,s); } } class BiMtxPow { BiMtx BMmulti (BiMtx A, BiMtx B){ BiMtx C = new BiMtx(0,0,0,0); C.a = (A.a * B.a + A.b * B.c) % 1000; C.b = (A.a * B.b + A.b * B.d) % 1000; C.c = (A.c * B.a + A.d * B.c) % 1000; C.d = (A.c * B.b + A.d * B.d) % 1000; return C; } BiMtx BMpow (BiMtx A, long n){ BiMtx C = new BiMtx(0,0,0,0); BiMtx half = new BiMtx(0,0,0,0); if(n == 0){ C.set(1, 0, 0, 1); return C; }else if (n == 1){ C.set(A); return C; }else if((n>>1)<<1 == n){ half = BMpow(A,(n>>1)); return BMmulti(half,half); }else{ half = BMpow(A,(n>>1)); return BMmulti(half,BMmulti(half,A)); } } } class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); sc.close(); BiMtx A = new BiMtx(0,1,2,2); BiMtx C = new BiMtx(0,0,0,0); BiMtxPow bmp = new BiMtxPow(); C = bmp.BMmulti(A, A); C = bmp.BMpow(A, n); if(n%2==0)System.out.println((2*C.a + 2* C.b -1) % 1000); else System.out.println((2*C.a + 2* C.b) % 1000); } }