using System; using System.Collections.Generic; using System.Linq; class Solution { static ulong GetPalindromeCount(string n, ulong mod) { ulong result = 0; // 全桁を使うパターン var front = n.Substring(0, (n.Length + 1) / 2); var back = n.Substring(n.Length / 2, (n.Length + 1) / 2); // 100...0からhalfを数える var count = ulong.Parse(front.Substring(0, 1)) - 1; foreach (var c in front.Skip(1)) { count *= 10; count %= mod; count += ulong.Parse(c.ToString()); count %= mod; } result += count + 1; result %= mod; // reverse > back であればhalfは回文にできない.数えたものから減らす var reverse = new string(front.Reverse().ToArray()); if (reverse.CompareTo(back) > 0) { result--; } // 最上位の桁を使わないパターン result += GetPalindromeCount0(n.Length - 1, mod); result %= mod; return result; } static Dictionary, ulong> powCache = new Dictionary, ulong>(); // 10^nを得る static ulong Pow10(int n, ulong mod) { if (n == 0) { return 1; } var tuple = Tuple.Create(n, mod); if (powCache.ContainsKey(tuple)) { return powCache[tuple]; } var pow = (10 * Pow10(n - 1, mod)) % mod; powCache[tuple] = pow; return pow; } // digits桁の数について,回文のバリエーションを得る static ulong GetPalindromeCount0(int digits, ulong mod) { if (digits == 0) { return 0; } var pal = (9UL * Pow10((digits - 1) / 2, mod)) % mod; return (pal + GetPalindromeCount0(digits - 1, mod)) % mod; } static void Main() { var dividers = new ulong[] { 1000000000, 1000000007 }; var n = Console.ReadLine(); foreach (var div in dividers) { var pal = GetPalindromeCount(n, div); Console.WriteLine(pal); } } }