import java.math.BigInteger; import java.util.Scanner; public class main{ static Scanner sc=new Scanner(System.in); public static void main(String args[]){ int n=sc.nextInt(); long[][] A={ {1,3}, {1,1} }; A=MtPow(n,A); long a=A[0][0]; if(n%2==0){ System.out.print((2*a-1)%1000); }else{ System.out.print((2*a)%1000); } } //int matrix^matrix(becareful about the size) public static long[][] MtPrd(long[][] A,long[][] B){ long[][] C=new long[A.length][B[0].length]; for(int i=0;i=0){ if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))==0){ B=MtPrd(A,B); b=b.subtract(BigInteger.valueOf(-1)); b=b.divide(BigInteger.valueOf(10)); }else if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))!=0){ b=b.divide(BigInteger.valueOf(10)); } A=MtPrd(A,A); } return B; } }