P = gets.to_i a = Array.new(P + 1) (P + 1).times{|i| a[i] = Array.new(9 * P + 1, 0) } a[0][0] = 1 ans1 = ans2 = 0 1.upto(P){|i| 10.times{|x| if x == 3 next end 0.upto(9 * i - x){|j| a[i][j + x] += a[i - 1][j] } } ans2 = 9 * ans2 + 10 ** (i - 1) ans1 = 0 3.step(9 * i, 3){|x| ans1 += a[i][x] } } p ans1 + ans2