require 'matrix' # # オーバーキル解法.O(logN) # 途中計算で剰余取らずに多倍長でごリ押すため,遅くなる. # MOD = 1000000007 n = gets.to_i-1 my_nice_matrix = Matrix[ \ [0,1,1,0,0,0], \ [0,0,0,1,0,0], \ [0,0,0,0,1,0], \ [1,0,1,0,0,0], \ [0,0,0,0,0,1], \ [1,1,0,0,0,0]] status = Matrix.column_vector([1,0,0,1,0,1]) status = (my_nice_matrix**n)*status p (status[0,0]%MOD + status[1,0]%MOD + status[2,0]%MOD)%MOD