$dp = Hash.new 0 def f(n) $dp[[0,1]] = $dp[[0,2]] = $dp[[0,3]] = 1 (1...n).each{|i| $dp[[i,1]] = ($dp[[i-2,2]] + $dp[[i-3,3]]) % M $dp[[i,2]] = ($dp[[i-1,1]] + $dp[[i-3,3]]) % M $dp[[i,3]] = ($dp[[i-1,1]] + $dp[[i-2,2]]) % M } ($dp[[n-1,1]] + $dp[[n-2,2]] + $dp[[n-3,3]]) % M end M = 10**9+7 N = gets.to_i p f(N)