malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int const maxl = 22;   int const maxm = 2520;   long long f[maxl][maxm + 4][50][2];   int a[maxl];   std::vector<int> alcm;   long long plcm[maxm + 4][10];   long long kth[maxm + 4];   long long l, r;   int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }   int lcm(int x, int y) {     if (!x) return y;     if (!y) return x;     return x * y / gcd(x, y);   }   void init() {     for (int i2 = 0, t2 = 1; i2 < 4; i2++, t2 *= 2)       for (int i3 = 0, t3 = 1; i3 < 3; i3++, t3 *= 3)         for (int i5 = 0, t5 = 1; i5 < 2; i5++, t5 *= 5)           for (int i7 = 0, t7 = 1; i7 < 2; i7++, t7 *= 7)             alcm.push_back(t2 * t3 * t5 * t7);     std::sort(alcm.begin(), alcm.end());     for (int i = 0; i <= maxm; i++)       for (int j = 0; j < 10; j++) plcm[i][j] = lcm(i, j);     for (int i = 0; i < (int)alcm.size(); i++) kth[alcm[i]] = i;   }   int get_len(long long x) {     int ret = 0;     for (; x; x /= 10) a[ret++] = x % 10;     return ret;   }   long long calc(long long x) {     int n = get_len(x);     for (int i = 0; i <= n; i++)       for (int j = 0; j < maxm; j++)         for (int k = 0; k < (int)alcm.size(); k++)           for (int l = 0; l < 2; l++) f[i][j][k][l] = 0;     f[0][0][0][0] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < maxm; j++)         for (int k = 0; k < (int)alcm.size(); k++)           for (int l = 0; l < 2; l++) {             if (!f[i][j][k][l]) continue;             int up = (l ? 9 : a[n - i - 1]);             for (int ti = 0; ti <= up; ti++) {               int last = l || (ti < a[n - i - 1]);               f[i + 1][(j * 10 + ti) % maxm][kth[plcm[alcm[k]][ti]]][last] +=                   f[i][j][k][l];             }           }     long long ans = 0;     for (int i = 0; i < maxm; i++)       for (int k = 0; k < (int)alcm.size(); k++)         for (int l = 0; l < 2; l++)           if (!(i % alcm[k])) ans += f[n][i][k][l];     return ans;   }   int main() {     std::ios::sync_with_stdio(false);     init();     int T;     std::cin >> T;     while (T--) {       std::cin >> l >> r;       std::cout << calc(r) - calc(l - 1) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI =       3.14159265358979323846264338327950288419716939937510582097494459230;   const long long MOD = 1e9 + 7;   const long long INF = 1e14;   long long mpow(long long a, long long b, long long p = MOD) {     a = a % p;     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % p;       a = (a * a) % p;       b = b >> 1;     }     return res % p;   }   const long long N = 4 * 100000;   long long n, m, b[N], a[N], g[N], h[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= (int)(n); ++i)       cin >> a[i], a[i] += a[i - 1], g[i] = 1e14;     for (int i = 1; i <= (int)(m); ++i)       cin >> b[i], b[i] += b[i - 1], h[i] = 1e14;     for (int i = 1; i <= (int)(n); ++i)       for (long long j = i; j <= n; j++)         g[j - i + 1] = min(g[j - i + 1], a[j] - a[i - 1]);     for (int i = 1; i <= (int)(m); ++i)       for (long long j = i; j <= m; j++)         h[j - i + 1] = min(h[j - i + 1], b[j] - b[i - 1]);     long long x;     cin >> x;     long long ans = 0;     for (int i = 1; i <= (int)(n); ++i)       for (int j = 1; j <= (int)(m); ++j) {         if (g[i] * h[j] <= x) {           ans = max(ans, (long long)(i * j));         }       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long T = 1;     cin >> T;     while (T--) {       long long n;       cin >> n;       char a[n][n];       for (long long i = 0; i < n; i++)         for (long long j = 0; j < n; j++) cin >> a[i][j];       vector<pair<long long, long long> > v;       if (a[1][0] ==  0  && a[0][1] ==  0 ) {         if (a[n - 1][n - 2] !=  1 ) v.push_back({n - 1, n - 2});         if (a[n - 2][n - 1] !=  1 ) v.push_back({n - 2, n - 1});       } else if (a[1][0] ==  0  && a[0][1] ==  1 ) {         if (a[n - 1][n - 2] ==  0  && a[n - 2][n - 1] ==  0 ) {           v.push_back({1, 0});         } else if (a[n - 1][n - 2] ==  1  && a[n - 2][n - 1] ==  0 ) {           v.push_back({n - 1, n - 2});           v.push_back({1, 0});         } else if (a[n - 1][n - 2] ==  0  && a[n - 2][n - 1] ==  1 ) {           v.push_back({n - 2, n - 1});           v.push_back({1, 0});         } else {           v.push_back({0, 1});         }       } else if (a[1][0] ==  1  && a[0][1] ==  1 ) {         if (a[n - 1][n - 2] !=  0 ) v.push_back({n - 1, n - 2});         if (a[n - 2][n - 1] !=  0 ) v.push_back({n - 2, n - 1});       } else if (a[1][0] ==  1  && a[0][1] ==  0 ) {         if (a[n - 1][n - 2] ==  0  && a[n - 2][n - 1] ==  0 ) {           v.push_back({0, 1});         } else if (a[n - 1][n - 2] ==  1  && a[n - 2][n - 1] ==  0 ) {           v.push_back({n - 1, n - 2});           v.push_back({0, 1});         } else if (a[n - 1][n - 2] ==  0  && a[n - 2][n - 1] ==  1 ) {           v.push_back({n - 2, n - 1});           v.push_back({0, 1});         } else {           v.push_back({1, 0});         }       }       cout << v.size() <<   n ;       for (auto it = (v).begin(); it != (v).end(); it++)         cout << it->first + 1 <<     << it->second + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int gcd(int a, int b) {     while (b > 0) {       int t = a;       a = b;       b = t % b;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     {       int i;       for (i = 1; i < n; ++i)         if (a[i] != a[i - 1]) break;       if (i == n) {         cout << (int64_t)n * (n - 1) << endl;         return 0;       }     }     int64_t ans = 0;     for (int divisor = 1; divisor < n; ++divisor) {       if (n % divisor > 0) continue;       vector<int> max_of_rem(a.begin(), a.begin() + divisor);       for (int i = divisor; i < n; ++i)         if (a[i] > max_of_rem[i % divisor]) max_of_rem[i % divisor] = a[i];       int lim = n;       for (int left = 0; left < lim;) {         int offs;         for (offs = 0; offs < n - 1 && a[(left + offs) % n] ==                                            max_of_rem[(left + offs) % divisor];              ++offs)           ;         if (offs == 0) {           ++left;           continue;         }         int goffs = offs;         if (left == 0) {           while (left + offs < lim &&                  a[lim - 1] == max_of_rem[(lim - 1) % divisor])             --lim;           offs += n - lim;         }         for (int i = divisor; i <= offs; i += divisor) {           if (gcd(n, i) == divisor) {             ans += offs == n ? n : offs - i + 1;           }         }         left += goffs;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int ansa, ansb;   int mid[110], cnt;   int yy;   int cmp(int a, int b) { return a > b; }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int s;       scanf( %d , &s);       int m = s / 2;       int x;       if (s & 1) {         for (int i = 1; i <= m; ++i) {           scanf( %d , &x);           ansa += x;         }         scanf( %d , &x);         mid[cnt++] = x;         for (int i = 1; i <= m; ++i) {           scanf( %d , &x);           ansb += x;         }       } else {         for (int i = 1; i <= m; ++i) {           scanf( %d , &x);           ansa += x;         }         for (int i = 1; i <= m; ++i) {           scanf( %d , &x);           ansb += x;         }       }     }     sort(mid, mid + cnt, cmp);     for (int i = 0; i < cnt; ++i) {       if (i & 1)         ansb += mid[i];       else         ansa += mid[i];     }     printf( %d %d , ansa, ansb);   }
#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 1005, M_MAX = 100005;   struct union_find {     int rank[N_MAX], parent[N_MAX];     union_find() {       for (int i = 0; i < N_MAX; i++) {         rank[i] = 0;         parent[i] = i;       }     }     int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }     bool join(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return false;       if (rank[x] >= rank[y]) {         parent[y] = x;         if (rank[x] == rank[y]) rank[x]++;       } else         parent[x] = y;       return true;     }   };   struct edge {     int a, b;     char who;   };   int N, M, H;   edge edges[M_MAX];   union_find S_UF, M_UF;   int impossible() {     puts( -1 );     return 0;   }   int main() {     scanf( %d %d , &N, &M);     if (N % 2 == 0) return impossible();     H = (N - 1) / 2;     for (int i = 0; i < M; i++) {       scanf( %d %d %c , &edges[i].a, &edges[i].b, &edges[i].who);       edges[i].a--;       edges[i].b--;     }     int S = 0;     for (int i = 0; i < M; i++)       if (edges[i].who ==  S )         if (S_UF.join(edges[i].a, edges[i].b)) S++;     if (S < H) return impossible();     int components = N - S;     vector<int> answer;     for (int i = 0; i < M && (int)answer.size() < H - (components - 1); i++)       if (edges[i].who ==  M )         if (S_UF.find(edges[i].a) == S_UF.find(edges[i].b))           if (M_UF.join(edges[i].a, edges[i].b)) answer.push_back(i);     assert((int)answer.size() <= H - (components - 1));     if ((int)answer.size() != H - (components - 1)) return impossible();     for (int i = 0; i < M; i++)       if (edges[i].who ==  M )         if (S_UF.join(edges[i].a, edges[i].b)) {           assert(M_UF.join(edges[i].a, edges[i].b));           answer.push_back(i);         }     assert((int)answer.size() <= H);     if ((int)answer.size() != H) return impossible();     for (int i = 0; i < M; i++)       if (edges[i].who ==  S )         if (M_UF.join(edges[i].a, edges[i].b)) answer.push_back(i);     assert((int)answer.size() == N - 1);     printf( %d n , (int)answer.size());     for (int i = 0; i < (int)answer.size(); i++)       printf( %d%c , answer[i] + 1, i < (int)answer.size() - 1 ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool reach(int from[3], int to[3], vector<vector<string>> &works) {     if (works[from[0]][from[1]][from[2]] ==  0 ) return false;     if (from[0] == to[0] && from[1] == to[1] && from[2] == to[2]) return true;     for (int d = 0; d < 3; ++d)       if (from[d] < to[d]) {         ++from[d];         bool res = reach(from, to, works);         --from[d];         if (res) return true;       }     return false;   }   int main() {     int lim[3];     for (int i = 0; i < 3; ++i) scanf( %d , &lim[i]);     vector<vector<string>> works(lim[0],                                  vector<string>(lim[1], string(lim[2],    )));     for (int i = 0; i < lim[0]; ++i)       for (int j = 0; j < lim[1]; ++j) scanf( %s , &works[i][j][0]);     int result = 0;     for (int i = 0; i < lim[0]; ++i)       for (int j = 0; j < lim[1]; ++j)         for (int k = 0; k < lim[2]; ++k)           if (works[i][j][k] ==  1 ) {             int at[3] = {i, j, k};             bool critical = false;             for (int fromd = 0; fromd < 3; ++fromd)               if (at[fromd] >= 1) {                 int from[3] = {i, j, k};                 --from[fromd];                 for (int tod = 0; tod < 3; ++tod)                   if (at[tod] + 1 < lim[tod]) {                     int to[3] = {i, j, k};                     ++to[tod];                     bool before = reach(from, to, works);                     works[i][j][k] =  0 ;                     bool after = reach(from, to, works);                     works[i][j][k] =  1 ;                     if (before && !after) critical = true;                   }               }             if (critical) ++result;           }     printf( %d n , result);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long suml[100100], sumr[100100], l[100100], r[100100], A[100100],       B[100100], total, ans[100100];   int main() {     long long N;     cin >> N;     for (long long i = 1; i <= N; i++) {       scanf( %lld , A + i);     }     for (long long i = N; i > 0; i--) {       scanf( %lld , B + i);     }     for (long long i = 1; i <= N; i++) {       l[i] = i - 1;       r[i] = i + 1;     }     for (long long i = 1; i <= N; i++) {       long long x = B[i];       long long sum = suml[r[x]] + sumr[l[x]] + A[x];       sumr[l[x]] = suml[r[x]] = sum;       l[r[x]] = l[x];       r[l[x]] = r[x];       total = max(total, sum);       ans[i] = total;     }     for (long long i = N - 1; i >= 0; i--) {       printf( %lld n , ans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   char s[200010], t[200010];   double s1[200010][26], s2[200010][26];   double ans = 0.0;   int main() {     scanf( %d n , &n);     memset(s1, 0, sizeof(s1));     memset(s2, 0, sizeof(s2));     for (int i = 1; i <= n; i++) {       scanf( %c , &s[i]);       for (int c = 0; c < 26; c++) s1[i][c] = s1[i - 1][c];       s1[i][s[i] -  A ] += i;     }     scanf(  n );     for (int i = 1; i <= n; i++) {       scanf( %c , &t[i]);       for (int c = 0; c < 26; c++) s2[i][c] = s2[i - 1][c];       s2[i][t[i] -  A ] += i;     }     scanf(  n );     double total = 0.0;     for (int i = 1; i <= n; i++) {       total += 1.0 * i * i;       ans += 1.0 * (s2[i - 1][s[i] -  A ]) * (n - i + 1);       ans += 1.0 * (s1[i - 1][t[i] -  A ]) * (n - i + 1);       if (t[i] == s[i]) ans += 1.0 * i * (n - i + 1);     }     double ret = ans / total;     printf( %.12lf n , ret);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 1e5 + 10;   int n, m, k, p;   int h[MAXN], a[MAXN];   namespace solver1 {   long long fin[MAXN];   bool check(long long x) {     long long need = 0;     static long long t[MAXN];     for (int i = 1; i <= n; i++) {       need += (t[i] = std::max(0ll, (fin[i] - x + p - 1) / p));     }     if (need > k * m) return 0;     static int cnt[MAXN];     memset(cnt, 0, sizeof cnt);     for (int i = 1; i <= n; i++) {       for (int j = t[i] - 1; j >= 0; j--) {         long long delta = fin[i] - x - (long long)j * p;         if (delta <= h[i]) {           cnt[1]++;         } else if (h[i] + (long long)a[i] * (m - 1) < delta) {           return 0;         } else {           cnt[(delta - h[i] + a[i] - 1) / a[i] + 1]++;         }       }     }     int tot = 0;     for (int i = 1; i <= m; i++) {       tot += cnt[i];       tot = std::max(0, tot - k);     }     return tot == 0;   }   void main() {     for (int i = 1; i <= n; i++) {       fin[i] = (long long)a[i] * m + h[i];     }     long long l = 1, r = 1e15, ans = 1e15;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %lld n , ans);   }   }  // namespace solver1   int main() {     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 1; i <= n; i++) {       scanf( %d%d , h + i, a + i);     }     solver1::main();   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     int x;     int y;     int z;     int id;   };   bool compY(Point a, Point b) {     if (a.y != b.y) {       return a.y < b.y;     }     return a.z < b.z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     map<int, vector<Point>> m;     for (int i = 0; i < n; i++) {       int x, y, z;       cin >> x >> y >> z;       m[x].push_back({x, y, z, i});     }     vector<pair<int, int>> ans;     vector<bool> deleted(n, false);     for (auto &e : m) {       if (e.second.size() < 2) {         continue;       }       vector<Point> a = e.second;       int k = a.size();       if (k < 2) {         continue;       }       sort(a.begin(), a.end(), compY);       for (int i = 0; i < k - 1; i++) {         if (a[i].y == a[i + 1].y) {           ans.emplace_back(a[i].id, a[i + 1].id);           deleted[a[i].id] = true;           deleted[a[i + 1].id] = true;           i++;         }       }       int l = 0;       int r = 0;       while (l < k) {         if (deleted[a[l].id]) {           l++;           continue;         }         r = max(r, l + 1);         while (r < k && deleted[a[r].id]) {           r++;         }         if (r == k) {           break;         }         ans.emplace_back(a[l].id, a[r].id);         deleted[a[l].id] = true;         deleted[a[r].id] = true;         l++;       }     }     bool havePrev = false;     Point prev;     for (auto &e : m) {       bool here = false;       Point cur;       for (auto &x : e.second) {         if (!deleted[x.id]) {           here = true;           cur = x;           break;         }       }       if (!here) {         continue;       }       if (havePrev) {         ans.emplace_back(prev.id, cur.id);         havePrev = false;       } else {         havePrev = true;         prev = cur;       }     }     for (auto &e : ans) {       cout << e.first + 1 <<     << e.second + 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000;   int a[MAXN];   int n;   int main() {     scanf( %d , &n);     n *= 2;     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int ans = 1e9;     for (int j = 1; j <= n; ++j)       for (int k = j + 1; k <= n; ++k) {         int t = 0;         for (int i = 1; i < n;) {           while (i == j || i == k) ++i;           int p = i + 1;           while (p == j || p == k) ++p;           t += a[p] - a[i];           i = p + 1;         }         ans = min(t, ans);       }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[10][10000];   long long cnt[10];   long long w;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> w;     for (long long i = 0; i < 8; i++) {       cin >> cnt[i];     }     for (long long i = 0; i < 10; i++)       for (long long j = 0; j < 10000; j++) dp[i][j] = -1;     dp[0][0] = 0;     for (long long i = 0; i < 8; i++) {       for (long long j = 0; j < 10000; j++) {         if (dp[i][j] == -1) continue;         long long b = 840 / (i + 1);         b = min(b, cnt[i]);         for (long long k = 0; k <= b; k++)           if (j + k * (i + 1) < 10000) {             dp[i + 1][j + k * (i + 1)] =                 max(dp[i + 1][j + k * (i + 1)],                     dp[i][j] + (cnt[i] - k) / (840 / (i + 1)));           }       }     }     long long ans = 0;     for (long long j = 0; j < 10000; j++) {       if (dp[8][j] != -1 && j <= w) {         ans = max(ans, j + 840ll * (min(dp[8][j], (w - j) / 840)));       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int w, m;     cin >> w >> m;     if (m == 1 || w == 2) {       cout <<  YES  << endl;       return 0;     }     while (m) {       if (m % w == 1) {         --m;       } else if (m % w == w - 1) {         ++m;       }       if (m % w == 0) {         m /= w;       } else {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1.1e6;   int ans;   int n, m;   vector<int> F;   int S[N][7][7];   int s(int i, int a, int b) {     if (i == m) return (F[i] - a) / 3;     if (i + 1 == m) return (F[i] - a) / 3 + (F[i + 1] - b) / 3;     int loc = S[i + 1][b][0];     for (int j = 0; j < 3; j++)       if (a + j <= min(6, F[i]) && b + j <= min(6, F[i + 1]) &&           0 + j <= min(6, F[i + 2]))         loc = max(loc, j + ((F[i] - (a + j)) / 3) + S[i + 1][b + j][j]);     return loc;   }   int main() {     scanf(  %d%d , &n, &m);     F = vector<int>(m + 1);     for (int i = 0; i < n; i++) {       int a;       scanf(  %d , &a);       F[a]++;     }     for (int i = m; i + 1; i--)       for (int a = 0; a < 7; a++)         for (int b = 0; b < 7; b++) S[i][a][b] = s(i, a, b);     printf( %d n , ans + S[0][0][0]);   }
#include <bits/stdc++.h>   using namespace std;   int T, n, k, l, a[300010], lst;   bool flag = 0;   int main() {     scanf( %d , &T);     while (T--) {       flag = 0;       lst = 0;       scanf( %d%d%d , &n, &k, &l);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         if (a[i] > l)           flag = 1;         else if (a[i] + k <= l)           lst = 0;         else if (lst < k)           lst = max(lst + 1, k + a[i] - l);         else {           if (lst + 1 + a[i] <= l + k)             lst++;           else             flag = 1;         }       }       if (flag)         printf( No n );       else         printf( Yes n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     int flag = 0;     vector<char> arr(26,  . );     for (int i = 0; i < s.length(); i++) {       int a = int(s[i]);       int b = int(t[i]);       if (arr[a - 97] == t[i] || arr[a - 97] ==  . ) {         arr[a - 97] = t[i];         if (arr[b - 97] == s[i] || arr[b - 97] ==  . )           arr[b - 97] = char(a);         else {           cout << -1;           flag = -1;           break;         }       } else {         cout << -1;         flag = -1;         break;       }     }     if (flag != -1) {       for (int i = 0; i < 26; i++) {         if (arr[i] !=  . ) {           int x = (int)arr[i];           if (arr[x - 97] == char(i + 97) || arr[x - 97] ==  . ) {             arr[x - 97] =  . ;             continue;           } else {             cout << -1;             flag = -1;             break;           }         }       }     }     if (flag != -1) {       int sum = 0;       for (int i = 0; i < 26; i++) {         if (arr[i] !=  . ) sum++;       }       cout << sum << endl;       if (sum != 0) {         for (int i = 0; i < 26; i++) {           if (arr[i] !=  . ) cout << arr[i] <<     << char(i + 97) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int MOD = 1000000007;   int t, k, dp[N][N][2];   char l[N], r[N], s[N];   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int dfs(int l, int pos, int f, int limit) {     if (l == -1) return f;     if (!limit && dp[l][pos][f] != -1) return dp[l][pos][f];     int up = limit ? (s[l] -  0 ) : 9, ret = 0;     for (int i = 0; i <= up; i++) {       if (i == 4 || i == 7) {         int ff = f;         if (pos != 1001) ff |= ((pos - l) <= k);         add(ret, dfs(l - 1, l, ff, limit && (i == up)));       } else {         add(ret, dfs(l - 1, pos, f, limit && (i == up)));       }     }     if (!limit) dp[l][pos][f] = ret;     return ret;   }   int gao(char *a) {     strcpy(s, a);     reverse(s, s + strlen(s));     return dfs(strlen(a) - 1, 1001, 0, 1);   }   void sub(char *s) {     int len = strlen(s), l = strlen(s) - 1;     while (s[l] ==  0 ) s[l] =  9 , l--;     s[l]--;     if (s[0] ==  0  && len > 1) {       for (int i = 1; i <= len; i++) s[i - 1] = s[i];     }   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> t >> k;     while (t--) {       cin >> l >> r;       sub(l);       cout << ((gao(r) - gao(l)) % MOD + MOD) % MOD << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[101][101];   int main() {     int n;     cin >> n;     int sum = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> a[i][j];         if ((i == j || i == (n - j + 1)) ||             (i == (n + 1) / 2 || j == (n + 1) / 2)) {           sum += a[i][j];         }       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int N = 2e5 + 1;   const int oo = 1e9;   const double pi = acos(-1);   int main() {     int t;     cin >> t;     while (t--) {       int a, b, n;       cin >> a >> b >> n;       if (b < a) swap(a, b);       int ans = 0;       while (a <= n && b <= n) {         ++ans;         if (ans % 2)           a += b;         else           b += a;       }       cout << ans << endl;     }     return 0;   }