using System; using System.Collections.Generic; using System.Linq; class Solution { static ulong GetPalindromeCount(ulong n, int mod) { var list = n.ToString().Select(c => int.Parse(c.ToString())).ToList(); return GetPalindromeCount(list, mod, false); } static ulong GetPalindromeCount(IEnumerable n, int mod, bool allowHeadZero) { if (n.Count() == 0) { return 0; } if (n.Count() == 1) { return (ulong)(n.First() + (allowHeadZero ? 1 : 0)); } ulong result = 0; // 全桁を使うパターン var t = n.ToList(); var mult = 1UL; while (t.Count > 0) { var tails = t.First(); if (t.Count > 1) { tails = t.Skip(1).Aggregate((prod, next) => prod * 10 + next); } ulong min = (ulong)Math.Min(n.First(), tails); if (t.Count == n.Count()) { mult = min; } else { min++; // 0をバリエーションに加える mult = (mult * min) % (ulong)mod; } t = t.Skip(1).Take(Math.Max(t.Count - 2, 0)).ToList(); } result += mult; // 最上位の桁を使わないパターン result += GetPalindromeCount(n.Skip(1).Select(_ => 9), mod, false); return result; } static void Main() { var dividers = new int[] { 1000000000, 1000000007 }; var n = ulong.Parse(Console.ReadLine()); foreach (var div in dividers) { var pal = GetPalindromeCount(n, div); Console.WriteLine(pal); } } }