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)); } var tails = n.Skip(1).Aggregate((prod, next) => prod * 10 + next); var mult = Math.Min(n.First(), tails); var mid = tails / 10; ulong result = 0; // 全桁を使うパターン result += GetPalindromeCount0(Math.Min(n.Count() - 1, 0), mod) * (ulong)mult; // 最上位の桁を使わないパターン result += GetPalindromeCount(n.Skip(1).Select(_ => 9), mod, false); return result; } // digits桁の数について,回文のバリエーションを得る static ulong GetPalindromeCount0(int digits, int mod) { return Enumerable.Repeat(10, (digits + 1) / 2).Aggregate(1UL, (prod, next) => (prod * (ulong)next) % (ulong)mod); } static void Main() { var dividers = new int[] { 1000000000, 1000000007 }; var n = ulong.Parse(Console.ReadLine()); foreach (var div in dividers) { var pal0 = GetPalindromeCount(n, div); Console.WriteLine(pal0); } } }