MOD = 1000 def matpow(A, B, w): l = len(A) while w: if w & 1: C = [0] * l for i in range(l): for j in range(l): C[i] += A[i][j] * B[j] C[i] %= MOD B = C C = [[0] * l for _ in range(l)] for i in range(l): for j in range(l): for k in range(l): C[i][j] += A[i][k] * A[k][j] C[i][j] %= MOD A = C w >>= 1 return B n = int(input()) A = [[1, 3], [1, 1]] B = [1, 0] ans = matpow(A, B, n)[0] * 2 if n % 2 == 0: ans -= 1 ans %= MOD print(ans)