import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int orgN = n; long[] x = {1, 0, 0, 1}; long[] k = {1, 1, 3, 1}; long[] tmp = k; while (n > 0) { if (n % 2 == 0) { mul(tmp, tmp, 1000); n >>= 1; } else { mul(x, tmp, 1000); n --; } } long ans = (x[0] * 2 - ((orgN % 2 == 0) ? 1 : 0)) % 1000; System.out.println(ans); } public static void mul(long[] mat1, long[] mat2, long mod) { long a = mat1[0]; long b = mat1[1]; long c = mat1[2]; long d = mat1[3]; long e = mat2[0]; long f = mat2[1]; long g = mat2[2]; long h = mat2[3]; mat1[0] = (a * e + b * g) % mod; mat1[1] = (a * f + b * h) % mod; mat1[2] = (c * e + d * g) % mod; mat1[3] = (c * f + d * h) % mod; } }