n = int(input()) mod = 10**9 + 7 def matmul(A, B): Ah, Bh, Bw = len(A), len(B), len(B[0]) C = [[0 for _ in range(Bw)] for _ in range(Ah)] for i in range(Ah): for j in range(Bw): for k in range(Bh): C[i][j] += A[i][k] * B[k][j] % mod C[i][j] %= mod return C # Mのk乗を効率的に計算する def doubling(M, k): k -= 1 Mc = M.copy() while k > 0: if k & 1 == 1: Mc = matmul(Mc, M) M = matmul(M, M) # Mの(2のi乗)の乗 を計算する k >>= 1 return Mc M = [[0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]] F = [[1], [0], [0], [0]] Mn = doubling(M, n) G = matmul(Mn, F) print(G[0][0])