def f(n, i, level=0) $*[-~n*8+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 M = 10**9+7 N = gets.to_i p f(N, 0)