M = 10**9+7 $dp = {} def f(n, i, level=0) $dp[[n,i]] ||= if n == 0 1 elsif n < 0 0 else [1,2,3].map{|j| if j == i 0 elsif level > 200 Fiber.new { f(n - j, j, 0) }.resume else f(n - j, j, level+1) end }.sum % M end end N = gets.to_i p f(N, 0)