#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define LINF (ll)INF*INF #define MOD 1000000007 #define rep(i,n) for(int i=0;i<(n);i++) #define loop(i,a,n) for(int i=a;i<(n);i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed< vi; typedef vector vs; typedef pair pii; typedef vector vp; int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } int lcm(int a, int b){ return a/gcd(a,b)*b; } long long beki(long long a,int n,int mod){ long long s = 1LL; while(n){ if(n % 2) s = (s * a) % mod; a = (a * a) % mod; n /= 2; } return s; } int solve(string s, int mod){ int n = s.size(); // n桁の 回文数の 数え上げ(575) string t = ""; rep(i,n/2)t += s[i]; if(n%2) t += s[n/2]; int ret = 0; int m = t.size(); if(m > 1)t.front()--; rep(i,m){ ret *= 10; ret += t[i] - '0'; ret %= mod; } if(m > 1)ret++; //n桁未満の回文数を数え上げ //i桁の回文数は 0~9が使える桁が(i-1)/2個、1~9が使える桁が1個 loop(i,1,n){ ret += 9 * beki(10, (i-1)/2, mod) % mod; ret %= mod; } return ret; } signed main(void) { string s; cin >> s; int n = s.size(); string t = ""; bool c = s.front() == '1' && s.size() > 1; loop(i,1,n)if(s[i] != '0')c = false; if(c){//10…0 rep(i,n-1)t += "9"; }else{//それ以外 rep(i,n/2)t += s[i]; int p = 0; rep(i,t.size()){ if(p == 0 && t[t.size()-1-i] > s[(n+1)/2+i])p++; if(p == 0 && t[t.size()-1-i] < s[(n+1)/2+i])p--; } if(n%2){ if(p == 1){ if(s[(n+1)/2-1] > '0')s[(n+1)/2-1]--; else{ int ind = t.size()-1; while(ind >= 0 && t[ind] == '0')ind++; t[ind]--; while(ind < t.size()-1){ ind++; t[ind] = '9'; } s[(n+1)/2-1] = '9'; } } string rev = t; reverse(all(rev)); t = t + s[(n+1)/2-1] + rev; }else{ if(p == 1){ int ind = t.size()-1; while(ind >= 0 && t[ind] == '0')ind++; t[ind]--; while(ind < t.size()-1){ ind++; t[ind] = '9'; } } string rev = t; reverse(all(rev)); t = t + rev; } } cout << t << endl; cout << solve(t,1e9) << endl; cout << solve(t,1e9+7) << endl; }