malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long po(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int countP(int n, int k) {     if (n == 0 || k == 0 || k > n) return 0;     if (k == 1 || k == n) return 1;     return k * countP(n - 1, k) + countP(n - 1, k - 1);   }   void solve() {     long long fac = 1;     long long n;     cin >> n;     long long xo = n;     if (n == 2)       cout << 1 <<   n ;     else {       for (long long i = 1; i <= n; i++) {         fac = fac * i;       }       fac *= 2;       fac /= n;       fac /= n;       cout << fac <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int p[200008] = {0};   int main() {     ios_base::sync_with_stdio(false);     long long int n, z, x, i;     long double p, q;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       z = x * x - 4 * x;       if (z < 0) {         cout <<  N n ;         continue;       }       cout <<  Y  ;       p = (long double)(x + sqrt(z)) / 2;       q = (long double)(x - sqrt(z)) / 2;       cout << setprecision(20) << p <<     << setprecision(20) << q << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string str[500005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> str[i];     for (int i = n - 2; i >= 0; i--) {       if (str[i] > str[i + 1]) {         string temp;         for (int j = 0; j < str[i].length(); j++) {           if (str[i + 1].length() < j || str[i][j] > str[i + 1][j]) break;           temp += str[i][j];         }         str[i] = temp;       }     }     for (int i = 0; i < n; i++) cout << str[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(register T& t) {     register T f = 1;     register char ch = getchar();     t = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) t = t * 10 + ch -  0 , ch = getchar();     t *= f;     return t;   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   const long long p = 998244353;   inline long long power(register long long x, register long long k = p - 2) {     register long long re = 1;     for (; k; k >>= 1, x = x * x % p)       if (k & 1) re = re * x % p;     return re;   }   long long S;   long long mul[77];   long long ans = 0;   long long calc(long long re, int l, int r, int n) {     if (l > r) swap(l, r);     static long long f[55][105][2];     if (re & 1) return 0;     memset(f, 0, sizeof(f));     f[0][0][0] = 1;     for (int i = 0; i <= 52; i++)       for (int j = 0; j <= n; j++)         if (re >> (i + 1) & 1) {           f[i + 1][j][0] += f[i][j][1];           if (i + 1 <= r) f[i + 1][j + 1][0] += f[i][j][0];           if (i + 1 <= l) f[i + 1][j + 1][0] += f[i][j][0];           if (i + 1 <= l) f[i + 1][j + 2][1] += f[i][j][1];         } else {           f[i + 1][j][0] += f[i][j][0];           if (i + 1 <= r) f[i + 1][j + 1][1] += f[i][j][1];           if (i + 1 <= l) f[i + 1][j + 1][1] += f[i][j][1];           if (i + 1 <= l) f[i + 1][j + 2][1] += f[i][j][0];         }     return f[53][n][0];   }   int main() {     read(S);     for (int i = 0; i <= 50; i++) mul[i] = 1ll << i;     for (int i = 1; i <= 50; i++) {       long long x = S / (mul[i] - 1);       if (x == 0) break;       if ((x + 1) * (mul[i] - 1) - i < S) continue;       long long re = S - x * (mul[i] - 1);       for (int j = i - 1; j >= 1; j--)         if (re >= mul[j] - 1) re -= mul[j] - 1;       if (re == 0) ans++;     }     for (int l = 2; l <= 50; l++)       for (int r = 2; r <= 50; r++) {         long long Base = mul[l] + mul[r] - 3;         long long x = (S - (mul[r - 1] - 1)) / Base;         if (x <= 0) continue;         long long re = S - (x * Base + mul[r - 1] - 1);         for (int n = 0; n <= l + r - 3; n++) ans += calc(re + n, l - 2, r - 2, n);       }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, x, p, l, r, e, ans, set;     l = r = e = ans = 0;     cin >> n >> x;     vector<long long int> a(n);     set = 0;     m = (n + 1) / 2;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < x) l++;       if (a[i] > x) r++;       if (a[i] == x) e++;     }     if (e == 0)       ans++;     else       e--;     set = 1;     if (e >= abs(r - l)) {       cout << ans <<   n ;       return 0;     }     if (l < r) {       l += e;       e = 0;       cout << ans + (r - 1) - l << endl;     } else {       r += e;       e = 0;       cout << ans + l - r << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool b[33333];   vector<int> pri;   vector<pair<int, int> > fac;   int n;   void init() {     for (int i = 2; i < 33333; ++i) {       if (!b[i]) {         pri.push_back(i);         for (int j = i + i; j < 33333; j += i) {           b[j] = false;         }       }     }   }   long long minans = 10000000000000000ll;   long long maxans = 0;   void dfs2(int x, int now, int last) {     if (x == fac.size()) {       long long t = (long long)(last + 2) * (now + 2) * (n / last / now + 1) - n;       minans = min(minans, t);       maxans = max(maxans, t);       t = (long long)(last + 1) * (now + 2) * (n / last / now + 2) - n;       minans = min(minans, t);       maxans = max(maxans, t);       return;     }     int t = fac[x].second;     for (; fac[x].second >= 0; --fac[x].second) {       dfs2(x + 1, now, last);       now *= fac[x].first;     }     fac[x].second = t;   }   void dfs(int x, int now) {     if (x == fac.size()) {       dfs2(0, 1, now);       return;     }     int t = fac[x].second;     for (; fac[x].second >= 0; --fac[x].second) {       dfs(x + 1, now);       now *= fac[x].first;     }     fac[x].second = t;   }   int main() {     init();     cin >> n;     int orgn = n;     for (int i = 0; i < pri.size(); ++i) {       if (n % pri[i] == 0) {         int s = 0;         while (n % pri[i] == 0) {           s++;           n /= pri[i];         }         fac.push_back(make_pair(pri[i], s));       }     }     if (n != 1) fac.push_back(make_pair(n, 1));     n = orgn;     dfs(0, 1);     cout << minans <<     << maxans << endl;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long l[1001];     long long r[1001];     long long f = 0;     long long ar[1005] = {0};     for (int i = 0; i < n; ++i) {       cin >> l[i];       if (l[i] > i) f = 1;     }     for (int i = 0; i < n; ++i) {       cin >> r[i];       if (r[i] > n - i - 1) f = 1;     }     long long sum = 0;     long long lim = (n * (n - 1)) / 2;     for (int i = 0; i < n; ++i) {       ar[i] = n - (l[i] + r[i]);       sum += (l[i] + r[i]);       if (ar[i] <= 0 || sum > lim) {         f = 1;         break;       }     }     int lc, rc;     for (int i = 0; i < n; ++i) {       lc = rc = 0;       for (int j = 0; j < i; ++j) {         if (ar[j] > ar[i]) lc++;       }       for (int j = i + 1; j < n; ++j) {         if (ar[j] > ar[i]) rc++;       }       if (lc != l[i] || rc != r[i]) {         f = 1;         break;       }     }     if (f == 1) {       cout <<  NO ;     } else {       cout <<  YES n ;       for (int i = 0; i < n; ++i) {         cout << ar[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void boost() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   string s, fp, sp;   bool ok = 0;   int pw;   void checkF() {     if (!(int)fp.size()) {       fp =   ;       return;     }     int it = 0;     string nw =   ;     string buff =   ;     while (fp[it] ==  0  && it < (int)fp.size()) it++;     if (it < (int)fp.size()) nw += fp[it];     for (int i = it + 1; i < (int)fp.size(); i++) buff += fp[i], pw++;     sp = buff + sp;     fp = nw;   }   void checkS() {     string buff =   ;     int it = (int)sp.size() - 1;     while (sp[it] ==  0  && it >= 0) it--;     for (int i = 0; i <= it; i++) buff += sp[i];     sp = buff;   }   int main() {     boost();     cin >> s;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  . )         ok = 1;       else {         if (!ok)           fp += s[i];         else           sp += s[i];       }     }     checkF();     checkS();     if (fp ==   ) {       pw = -(int)sp.size();       swap(fp, sp);       checkF();       checkS();     }     cout << fp;     if (sp !=   ) cout <<  .  << sp;     if (pw) cout <<  E  << pw;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M;     scanf( %d%d , &N, &M);     if (M == 3 && N > 4) {       puts( -1 );       return 0;     }     for (int i = 1; i <= M; ++i) {       printf( %d %d n , i - 101, i * i);     }     N -= M;     for (int i = 1; i <= N; ++i) {       printf( %d %d n , -i + 101, -i * i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int a[N], f[N];   long long dis[N], pos[N], res[N];   int n;   void add(long long *b, int x, long long v) {     for (int i = x; i <= n; i += i & -i) b[i] += v;   }   long long qry(long long *b, int x) {     long long ret = 0;     for (int i = x; i > 0; i ^= i & -i) ret += b[i];     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], f[a[i]] = i;     long long t = 0;     for (int i = 1; i <= n; i++) {       int p = f[i];       t += qry(pos, n) - qry(pos, p);       add(pos, p, 1);       add(dis, p, p);       int j = (i + 1) / 2, l = 1, r = n;       while (l < r) {         int m = (l + r) >> 1;         if (qry(pos, m) >= j)           r = m;         else           l = m + 1;       }       int x = l;       long long r1 = j - 1, r2 = i - j, cur = t;       if (r1 > 0) cur += r1 * x - qry(dis, x - 1) - r1 * (r1 + 1) / 2;       if (r2 > 0) cur += (qry(dis, n) - qry(dis, x)) - r2 * x - r2 * (r2 + 1) / 2;       res[i] = cur;     }     for (int i = 1; i <= n; i++) cout << res[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c1;   struct state {     int h1, a1, h2, a2, level;     int laststate;     state() {}     state(int a, int b, int c, int d, int e, int f)         : h1(a), a1(b), h2(c), a2(d), level(e), laststate(f) {}   };   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int N;     cin >> N;     vector<unsigned long long> a(N);     for (int i = 0; i < N; ++i) {       cin >> a[i];     }     unsigned long long prfx = 0;     map<int, unsigned long long> removals;     map<int, unsigned long long> rcount;     unsigned long long nans = 0, pans = 0;     for (int i; i < N; ++i) {       unsigned long long tp = ((unsigned long long)a[i]) * i;       if (tp > prfx)         pans += tp - prfx;       else         nans += prfx - tp;       if (removals.count(a[i]) != 0) {         unsigned long long ot = ((unsigned long long)a[i]) * rcount[a[i]];         unsigned long long rmls = removals[a[i]];         if (ot > rmls)           nans += ot - rmls;         else           pans += rmls - ot;       }       prfx += a[i];       if (rcount.count(a[i] - 1) == 0) rcount[a[i] - 1] = 0;       if (rcount.count(a[i] + 1) == 0) rcount[a[i] + 1] = 0;       if (rcount.count(a[i]) == 0) rcount[a[i]] = 0;       if (removals.count(a[i] - 1) == 0) removals[a[i] - 1] = 0;       if (removals.count(a[i] + 1) == 0) removals[a[i] + 1] = 0;       if (removals.count(a[i]) == 0) removals[a[i]] = 0;       removals[a[i] - 1] += a[i];       removals[a[i] + 1] += a[i];       removals[a[i]] += a[i];       ++rcount[a[i] + 1];       ++rcount[a[i] - 1];       ++rcount[a[i]];       if (pans > nans) {         pans -= nans;         nans = 0;       } else {         nans -= pans;         pans = 0;       }     }     if (pans > 0 || (pans == 0 && nans == 0))       cout << pans << endl;     else       cout <<  -  << nans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 3e3 + 5;   int n, l[MX], r[MX], q[2 * MX];   int dp[2 * MX][2 * MX];   vector<int> sg[2 * MX];   void inline upmx(int& x, int y) {     if (y > x) x = y;   }   void solve() {     cin >> n;     for (int i = (0); i < (n); ++i) {       int li, ri;       cin >> li >> ri;       l[i] = li;       q[2 * i] = li;       r[i] = ri;       q[2 * i + 1] = ri;     }     sort(q, q + 2 * n);     int m = unique(q, q + 2 * n) - q;     for (int i = (0); i < (n); ++i) {       l[i] = lower_bound(q, q + m, l[i]) - q;       r[i] = lower_bound(q, q + m, r[i]) - q;     }     for (int j = (0); j < (m); ++j) {       sg[j].clear();       memset((dp[j]), 0, (m) * sizeof((dp[j])[0]));     }     for (int i = (0); i < (n); ++i) sg[l[i]].push_back(r[i]);     for (int j = (0); j < (m); ++j) sort((sg[j]).begin(), (sg[j]).end());     for (int i = (m)-1; i >= (0); --i) {       for (int j = (i + 1); j < (m); ++j) dp[i][j] = dp[i + 1][j];       for (auto& j : (sg[i])) {         dp[i][j] += 1;         for (int k = (j + 1); k < (m); ++k) {           upmx(dp[i][k], dp[i][j] + dp[j + 1][k]);         }       }     }     cout << dp[0][m - 1] <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, c;   long long a[3001];   pair<int, int> sol[3001];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     c = 0;     for (int i = 0; i < n; ++i) {       int mn = i;       for (int j = i + 1; j < n; ++j) {         if (a[mn] > a[j]) {           mn = j;         }       }       if (a[mn] < a[i]) {         swap(a[i], a[mn]);         sol[c] = pair<int, int>(i, mn);         ++c;       }     }     cout << c << endl;     for (int i = 0; i < c; ++i) {       cout << sol[i].first <<     << sol[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream f( text.in );   int t, coada[26 * 2 + 5], p, u, n, ind, frecventa[26 + 5], imposibil;   string sir;   int main() {     cin >> t;     while (t--) {       cin >> sir;       n = sir.size();       p = u = 26;       coada[p] = sir[0] -  a  + 1;       frecventa[sir[0] -  a  + 1] = 1;       ind = p;       imposibil = 0;       for (int i = 1; i < n && !imposibil; i++) {         if (ind == u) {           if (ind - 1 < p || coada[ind - 1] != sir[i] -  a  + 1) {             coada[++u] = sir[i] -  a  + 1;             if (frecventa[sir[i] -  a  + 1]) {               imposibil = 1;             }             frecventa[sir[i] -  a  + 1]++;             ind = u;           } else {             ind = u - 1;           }         } else if (ind == p) {           if (ind + 1 > u || coada[ind + 1] != sir[i] -  a  + 1) {             coada[--p] = sir[i] -  a  + 1;             if (frecventa[sir[i] -  a  + 1]) {               imposibil = 1;             }             frecventa[sir[i] -  a  + 1]++;             ind = p;           } else {             ind = p + 1;           }         } else {           if (coada[ind + 1] == sir[i] -  a  + 1) {             ind++;           } else if (coada[ind - 1] == sir[i] -  a  + 1) {             ind--;           } else {             imposibil = 1;           }         }       }       if (imposibil) {         cout <<  NO  <<   n ;       } else {         cout <<  YES  <<   n ;         for (int i = p; i <= u; i++) {           cout << (char)(coada[i] +  a  - 1);         }         for (int i = 1; i <= 26; i++) {           if (!frecventa[i]) {             cout << (char)(i +  a  - 1);           }         }         cout <<   n ;       }       for (int i = 1; i <= 26; i++) {         frecventa[i] = 0;       }       for (int i = 0; i <= 2 * 26 + 4; i++) {         coada[i] = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct c {     long long f, s, i;   };   bool com(c a, c b) { return (a.f + b.s < a.s + b.f); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, i, m, u, v;     cin >> n >> m;     vector<c> cp(n);     for (i = 0; i < n; i++) {       cin >> cp[i].f >> cp[i].s;       cp[i].i = i;     }     vector<c> wp(cp);     sort(cp.begin(), cp.end(), com);     vector<pair<long long, long long> > pre(n + 1, make_pair(0ll, 0ll));     for (i = 0; i < n; i++) {       pre[i + 1].first = pre[i].first + cp[i].f;       pre[i + 1].second = pre[i].second + cp[i].s;     }     long long ans[n];     for (i = 0; i < n; i++) {       ans[cp[i].i] = i * cp[i].s + pre[i].first + (n - i - 1) * cp[i].f +                      pre[n].second - pre[i + 1].second;     }     while (m--) {       cin >> u >> v;       long long val = com(wp[u - 1], wp[v - 1]) ? wp[u - 1].f + wp[v - 1].s                                                 : wp[u - 1].s + wp[v - 1].f;       ans[u - 1] -= val;       ans[v - 1] -= val;     }     for (i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 3e5 + 10;   const int mod = 1e5 + 7;   using namespace std;   int a[N], b[N];   pair<long long, int> dp[N][2];   void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i], &b[i]);     dp[1][0] = {0, a[1]};     dp[1][1] = {b[1], a[1] + 1};     for (int i = 2; i <= n; ++i) {       pair<long long, int> p[4];       p[0] = {b[i] * (a[i] == dp[i - 1][0].second) + dp[i - 1][0].first,               a[i] + (a[i] == dp[i - 1][0].second)};       p[1] = {p[0].first + b[i] * (1 + (p[0].second + 1 == dp[i - 1][0].second)),               p[0].second + 1 + (p[0].second + 1 == dp[i - 1][0].second)};       p[2] = {b[i] * (a[i] == dp[i - 1][1].second) + dp[i - 1][1].first,               a[i] + (a[i] == dp[i - 1][1].second)};       p[3] = {p[2].first + b[i] * (1 + (p[2].second + 1 == dp[i - 1][1].second)),               p[2].second + 1 + (p[2].second + 1 == dp[i - 1][1].second)};       sort(p, p + 4);       dp[i][0] = p[0];       for (int ii = 1; ii <= 3; ++ii)         if (p[ii].second != p[0].second) dp[i][1] = p[ii], ii = 3;     }     printf( %lld n , min(dp[n][0].first, dp[n][1].first));   }   int main() {     int t;     scanf( %d , &t);     for (int i = 1; i <= t; ++i) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, k;   char s[10];   int chk(int l1, int r1, int l2, int r2) {     printf( ? %d %d n , r1 - l1 + 1, r2 - l2 + 1);     for (int i = l1; i <= r1; i++) printf( %d  , i);     putchar(  n );     for (int i = l2; i <= r2; i++) printf( %d  , i);     putchar(  n );     fflush(stdout);     scanf( %s , &s);     if (s[0] ==  F ) return 1;     if (s[0] ==  S ) return -1;     if (s[0] ==  E ) return 0;   }   int main() {     srand(time(NULL));     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &k);       bool pd = 0;       for (int i = 1; i <= 25; i++) {         int x = 1ll * rand() * rand() % (n - 1) + 2;         if (chk(1, 1, x, x) == -1) {           pd = 1;           break;         }       }       if (pd) {         puts( ! 1 );         fflush(stdout);         continue;       }       int l, r, ans = -1;       for (int mid = 1; mid < n; mid <<= 1) {         if (chk(1, mid, mid + 1, min(2 * mid, n)) == 1) {           l = mid + 1, r = min(2 * mid, n);           break;         }       }       while (l <= r) {         int mid = l + r >> 1;         if (chk(1, mid - l + 1, l, mid) == 0)           l = mid + 1;         else           ans = mid, r = mid - 1;       }       printf( ! %d n , ans), fflush(stdout);     }   }
#include <bits/stdc++.h>   using namespace std;   int memo[4][10000011];   int path;   int main() {     scanf( %d , &path);     memo[0][path] = 1;     for (int i = path - 1; i >= 0; i--) {       for (int j = 0; j < 4; ++j)         for (int k = 0; k < 4; ++k) {           if (j != k) {             memo[j][i] = (memo[j][i] + (memo[k][i + 1])) % 1000000007;           }         }     }     printf( %d n , memo[0][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[1100], b[1100][1100];   const int inf = 2000000000;   int c[1100], len[1100], f[1100][1100], sum[1100], ran[2][1100], to[1100],       d[1100], n, m, fr[1100];   int cal(int i) {     int j, res = 0;     for (j = len[i]; j > m; j--) res += c[b[i][j] -  0 ];     return res;   }   void add(int i) {     if (len[i] <= m)       len[i] = m + 1, b[i][m + 1] =  1 ;     else {       int pos = m + 1;       b[i][pos]++;       while (b[i][pos] >  9 ) {         if (len[i] == pos)           len[i]++, b[i][len[i]] =  1 ;         else           b[i][pos + 1]++;         b[i][pos] =  0 ;         pos++;       }     }   }   int main() {     int i, j, k, nw, pre, l, r, co, p, q, ans;     scanf( %s , a + 1);     m = strlen(a + 1);     reverse(a + 1, a + m + 1);     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %s , b[i] + 1);       len[i] = strlen(b[i] + 1);       reverse(b[i] + 1, b[i] + len[i] + 1);       for (j = len[i] + 1; j <= m; j++) b[i][++len[i]] =  0 ;     }     for (i = 0; i <= 9; i++) scanf( %d , &c[i]);     for (i = 1; i <= n; i++) ran[0][i] = i;     nw = 0;     pre = 1;     for (i = 0; i <= m; i++)       for (j = 1; j <= n + 1; j++) f[i][j] = -inf;     f[0][n + 1] = 0;     for (i = 1; i <= m; i++) {       nw ^= 1;       pre ^= 1;       for (j = 0; j <= 9; j++) sum[j] = 0;       for (j = 1; j <= n; j++) sum[b[j][i] -  0 ]++;       for (j = 1; j <= 9; j++) sum[j] += sum[j - 1];       for (j = n; j; j--) {         ran[nw][sum[b[ran[pre][j]][i] -  0 ]] = ran[pre][j];         to[sum[b[ran[pre][j]][i] -  0 ]] = j;         fr[j] = sum[b[ran[pre][j]][i] -  0 ]--;       }       l = 0;       r = 9;       if (i == m) l = 1;       if (a[i] !=  ? ) l = a[i] -  0 , r = a[i] -  0 ;       for (j = l; j <= r; j++) {         co = 0;         for (k = 1; k <= n; k++) co += c[(b[k][i] -  0  + j) % 10];         for (k = n; ((k) && (b[ran[nw][k]][i] -  0  + j > 9)); k--)           ;         for (p = n + 1;              (((!k) || (p > to[k]) || (b[ran[nw][k]][i] -  0  + j < 9)) && (p));              p--) {           if (p != n + 1) {             co -= c[(b[ran[nw][fr[p]]][i] -  0  + j) % 10];             co += c[(b[ran[nw][fr[p]]][i] -  0  + j + 1) % 10];           }           f[i][k + 1] = max(f[i][k + 1], f[i - 1][p] + co);         }         for (; ((k) && (b[ran[nw][k]][i] -  0  + j == 9)); k--) {           if ((k == 1) || (b[ran[nw][k - 1]][i] -  0  + j != 9))             q = 1;           else             q = to[k - 1] + 1;           for (; p >= q; p--) {             co -= c[(b[ran[nw][fr[p]]][i] -  0  + j) % 10];             co += c[(b[ran[nw][fr[p]]][i] -  0  + j + 1) % 10];             f[i][k] = max(f[i][k], f[i - 1][p] + co);           }         }       }     }     for (i = 1; i <= n; i++) d[i] = ran[nw][i];     co = 0;     ans = 0;     for (i = 1; i <= n; i++) co += cal(i);     ans = max(ans, co + f[m][n + 1]);     for (i = n; i; i--) {       co -= cal(d[i]);       add(d[i]);       co += cal(d[i]);       ans = max(ans, co + f[m][i]);     }     printf( %d n , ans);     return 0;   }