import numpy as np mod = 1000 def powMat(A, n): B = np.matrix(np.identity(len(A))) while n > 0: if n & 1: B = np.dot(A, B) B %= mod A = np.dot(A, A) A %= mod n /= 2 return B n = int(input()) A = np.matrix([ [1, 3], [1, 1]]) A = powMat(A, n) v0 = np.matrix([[1, 0]]).T v = np.dot(A, v0) print(int(2 * v[0] - (n % 2 == 0)) % mod)