MOD = 10**9 + 7 def multiply(a, b): """Multiply two 2x2 matrices.""" res = [[0] * 2 for _ in range(2)] for i in range(2): for j in range(2): res[i][j] = (a[i][0] * b[0][j] + a[i][1] * b[1][j]) % MOD return res def matrix_power(mat, power): """Compute the matrix exponent using binary exponentiation.""" result = [[1, 0], [0, 1]] # Identity matrix while power > 0: if power % 2 == 1: result = multiply(result, mat) mat = multiply(mat, mat) power //= 2 return result n = int(input()) # Handle the case when n is 0 (though per problem statement, n >=1) if n == 0: print(1) else: matrix = [[0, 1], [3, 2]] mat_pow = matrix_power(matrix, n) print(mat_pow[0][0] % MOD)