MOD = 10**9 + 7 def main(): import sys n = int(sys.stdin.readline()) inv6 = pow(6, MOD-2, MOD) # Precompute p[0] to p[5] p = [0] * 6 p[0] = 1 if n == 0: print(p[0]) return for i in range(1, 6): s = 0 for j in range(1, i + 1): s = (s + p[i - j]) % MOD p[i] = s * inv6 % MOD if n < 6: print(p[n]) return # Define the transition matrix mat = [ [inv6] * 6, [1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0] ] # Initial vector is [p5, p4, p3, p2, p1, p0] initial_vector = [p[5], p[4], p[3], p[2], p[1], p[0]] power = n - 5 # Function to multiply two matrices def multiply(a, b): res = [[0]*6 for _ in range(6)] for i in range(6): for k in range(6): if a[i][k] == 0: continue for j in range(6): res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD return res # Function to multiply matrix and vector def multiply_mat_vec(mat, vec): res = [0] * 6 for i in range(6): for j in range(6): res[i] = (res[i] + mat[i][j] * vec[j]) % MOD return res # Matrix exponentiation result_mat = [[0]*6 for _ in range(6)] for i in range(6): result_mat[i][i] = 1 # Identity matrix current_mat = [row[:] for row in mat] while power > 0: if power % 2 == 1: result_mat = multiply(result_mat, current_mat) current_mat = multiply(current_mat, current_mat) power //= 2 # Multiply the resulting matrix with the initial vector final_vec = multiply_mat_vec(result_mat, initial_vector) print(final_vec[0]) if __name__ == "__main__": main()