#include using namespace std; typedef long long int64; string S; int64 dp[100001][2][2]; int64 dp2[100001]; int64 rec2(int idx, const int mod) { if(idx <= 0) return (1); if(idx % 2 == 1) return (rec2(idx - 1, mod) * 10 % mod); if(~dp2[idx]) return (dp2[idx]); return (dp2[idx] = rec2(idx - 2, mod) * 10 % mod); } int64 rec(int idx, bool free, bool less, const int mod) { if(~dp[idx][free][less]) return (dp[idx][free][less]); if(S.size() / 2 == idx) { if(less && !free) { if(S.size() % 2 == 0) return (0); if(S[idx] == '0') return (0); return (S[idx] - '0'); } if(S.size() % 2 == 1) return (free ? 10 : S[idx] - '0' + 1); else return (1); } int64 ret = 0; int end = free ? 9 : S[idx] - '0'; for(int i = 0; i <= end; i++) { if(idx == 0 && i == 0) continue; bool nt = free | (i != end); if(!nt && S[S.size() - idx - 1] - '0' < i) { cout << idx << " " << i << endl; (ret += rec(idx + 1, free | (i != end), true, mod)) %= mod; } else { (ret += rec(idx + 1, free | (i != end), less & (S[S.size() - idx - 1] - '0' < i), mod)) %= mod; } } return (dp[idx][free][less] = ret); } int64 ct(int mod) { memset(dp, -1, sizeof(dp)); memset(dp2, -1, sizeof(dp2)); int64 ret = 0; for(int i = 0; i < S.size() - 1; i++) { ret += rec2(i - 1, mod) * 9; ret %= mod; } return ((ret + rec(0, 0, 0, mod)) % mod); } int dssp[100001]; void stuped(int K) { for(int i = 1; i <= K; i++) { string s = to_string(i); string t = s; reverse(begin(t), end(t)); dssp[i] += dssp[i - 1]; dssp[i] += t == s; } } int main() { cin >> S; cout << ct(1e9) << endl; cout << ct(1e9+7) << endl; /* stuped(100000); for(int i = 1; i <= 100000; i++) { S = to_string(i); if(S.size() == 1) continue; if(S.size() == 1) { cout << S << endl << S << endl; return (0); } if(dssp[i] != ct(1e9)) { cout << i << endl; return(0); } } cout << "OK" << endl; */ }