$dp = {} def f(x) $dp[x] ||= if x < 1 0 else (1..6).map{|i| f(x - i).quo(6) }.sum + 1 end end p f(gets.to_i).to_f