def ascan; gets.split.map(&:to_i); end def scan; gets.to_i; end @md = 1 # 1以上10^i-1以下の整数 def _kaibunsu_dec(keta) return 9 if (keta <= 1) r = 1 ((keta + 1) / 2).times{r*=10} return r - (r / 10) + _kaibunsu_dec(keta-1) end # dfs列挙 def _kaibunsu_dfs(low, high, kcl, kch, num=0) return low <= num && num <= high ? 1 : 0 if kcl > kch result = 0 (kcl == 1 ? 1 : 0).upto(9){|k| result = (result + _kaibunsu_dfs(low, high, kcl * 10, kch / 10, num + kcl*k + kch*k*(kcl != kch ? 1 : 0)))%@md } return result end # 1以上val以下の整数で回文数が何個あるか def kaibunsu(val) return val if (val <= 9) dec = 1 keta = 0 while (val >= dec) dec *= 10; ++keta; end dec /= 10; return _kaibunsu_dfs(dec, val, 1, dec) + _kaibunsu_dec(keta - 1); end # (´・ω・`) n = gets.to_i @md = 10000000007 p kaibunsu(n)%@md @md = 10000000000 p kaibunsu(n)%@md