malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int l[N], r[N], n, len, posl, posr;   char a[N], b[N];   int ans, ans1, ans2;   vector<int> vec[30];   int main() {     for (int i = 0; i < 30; ++i) vec[i].push_back(1);     scanf( %s%s , a + 1, b + 1);     n = strlen(a + 1);     len = strlen(b + 1);     for (int i = 1; i <= n; ++i) vec[a[i] -  a ].push_back(i);     for (int i = 1; i <= len; ++i) {       int c = b[i] -  a ;       int& pos = vec[c][0];       while (pos <= vec[c].size() - 1 && vec[c][pos] <= l[i - 1]) {         pos++;       }       if (pos > vec[c].size() - 1)         l[i] = n + 1;       else         l[i] = vec[c][pos++];     }     for (int i = 0; i < 30; ++i) vec[i][0] = vec[i].size() - 1;     r[len + 1] = n + 1;     for (int i = len; i >= 1; --i) {       int c = b[i] -  a ;       int& pos = vec[c][0];       while (pos && vec[c][pos] > r[i + 1]) {         pos--;       }       if (pos == 0)         r[i] = 0;       else         r[i] = vec[c][pos--];     }     for (int i = 1; i <= len; ++i)       if (l[i] > l[i - 1] && l[i] <= n)         posl = i;       else         break;     posr = len + 1;     for (int i = len; i >= 1; --i)       if (r[i] < r[i + 1] && r[i] != 0)         posr = i;       else         break;     if (ans < posl) {       ans = posl;       ans1 = posl;       ans2 = len + 1;     }     if (ans < len - posr + 1) {       ans = len - posr + 1;       ans1 = 0;       ans2 = posr;     }     for (int i = posr; i <= len; ++i) {       int tmp = r[i];       int pos = lower_bound(l + 1, l + posl + 1, tmp) - l;       pos--;       if (pos >= i) pos = i - 1;       int val = len - i + 1 + pos;       if (ans < val) {         ans = val;         ans1 = pos;         ans2 = i;       }     }     if (ans == 0)       puts( - );     else {       for (int i = 1; i <= ans1; ++i) putchar(b[i]);       for (int i = ans2; i <= len; ++i) putchar(b[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, c = 0;     cin >> d >> n;     int a[n], i;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n - 1; i++) {       c += d - a[i];     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   long long int ch(long long int x, long long int y) {     if (abs(x - y) % 2 == 0) {       return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int q;     cin >> q;     while (q--) {       long long int x, y, k;       cin >> x >> y >> k;       if (k < max(x, y)) {         cout <<  -1 n ;       } else {         long long int temp = k - max(x, y);         if (temp % 2 == 0) {           if (ch(x, y)) {             cout << k - 1 <<   n ;           } else {             cout << k <<   n ;           }         } else {           if (ch(x, y)) {             cout << k - 1 <<   n ;           } else {             cout << k - 2 <<   n ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   struct node {     double x, y, vx, vy;   } a[maxn];   bool ck(double a, double b) {     if (a - b > 1e-50 || (fabs(a - b) <= 1e-50))       return true;     else       return false;   }   int main() {     int n;     scanf( %d , &n);     double lx, ly, rx, ry;     scanf( %lf%lf%lf%lf , &lx, &ly, &rx, &ry);     double tl = 0, tr = 0x3f3f3f3f3f;     for (int i = 0; i < n; ++i)       scanf( %lf%lf%lf%lf , &a[i].x, &a[i].y, &a[i].vx, &a[i].vy);     for (int i = 0; i < n; ++i) {       double x = a[i].x, y = a[i].y, vx = a[i].vx, vy = a[i].vy;       double tmpl = 0, tmpr = 0x3f3f3f3f3f;       if (ck(x, rx) && ck(vx, 0)) {         return 0 * printf( -1 n );       } else if (ck(y, ry) && vy >= 0) {         return 0 * printf( -1 n );       } else if (ck(lx, x) && vx <= 0) {         return 0 * printf( -1 n );       } else if (ck(ly, y) && vy <= 0) {         return 0 * printf( -1 n );       }       double tt = 0;       if (vx >= 0 && vy >= 0) {         if (x <= lx) {           tt = max(tt, (lx - x + 1e-50) / vx);         }         if (y <= ly) {           tt = max(tt, (ly - y + 1e-50) / vy);         }         if (ck(x + vx * tt, rx) || ck(y + vy * tt, ry)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((rx - x + 1e-50) / vx, (ry - y + 1e-50) / vy);         tr = min(tr, tt);       } else if (vx >= 0 && vy <= 0) {         if (x <= lx) {           tt = max(tt, (lx - x + 1e-50) / vx);         }         if (y >= ry) {           tt = max(tt, (ry - y + 1e-50) / vy);         }         if (ck(x + vx * tt, rx) || ck(ly, y + vy * tt)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((rx - x + 1e-50) / vx, (ly - y + 1e-50) / vy);         tr = min(tr, tt);       } else if (vx <= 0 && vy >= 0) {         if (x >= rx) {           tt = max(tt, (rx - x + 1e-50) / vx);         }         if (y <= ly) {           tt = max(tt, (ly - y + 1e-50) / vy);         }         if (ck(lx, x + vx * tt) || ck(y + vy * tt, ry)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((lx - x + 1e-50) / vx, (ry - y + 1e-50) / vy);         tr = min(tr, tt);       } else if (vx <= 0 && vy <= 0) {         if (x >= rx) {           tt = max(tt, (rx - x + 1e-50) / vx);         }         if (y >= ry) {           tt = max(tt, (ry - y + 1e-50) / vy);         }         if (ck(lx, x + vx * tt) || ck(ly, y + vy * tt)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((lx - x + 1e-50) / vx, (ly - y + 1e-50) / vy);         tr = min(tr, tt);       }     }     if (!ck(tl, tr))       printf( %.20f n , tl);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int l[N][N], r[N][N], u[N][N], z[N][N];   int v[N][N];   void swap_left(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(l[fi][fj], l[gi][gj]);     int ai = l[fi][fj] / N;     int aj = l[fi][fj] % N;     int bi = l[gi][gj] / N;     int bj = l[gi][gj] % N;     swap(r[ai][aj], r[bi][bj]);   }   void swap_right(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(r[fi][fj], r[gi][gj]);     int ai = r[fi][fj] / N;     int aj = r[fi][fj] % N;     int bi = r[gi][gj] / N;     int bj = r[gi][gj] % N;     swap(l[ai][aj], l[bi][bj]);   }   void swap_up(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(u[fi][fj], u[gi][gj]);     int ai = u[fi][fj] / N;     int aj = u[fi][fj] % N;     int bi = u[gi][gj] / N;     int bj = u[gi][gj] % N;     swap(z[ai][aj], z[bi][bj]);   }   void swap_down(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(z[fi][fj], z[gi][gj]);     int ai = z[fi][fj] / N;     int aj = z[fi][fj] % N;     int bi = z[gi][gj] / N;     int bj = z[gi][gj] % N;     swap(u[ai][aj], u[bi][bj]);   }   int main() {     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         if (j) {           int c = i * N + j - 1;           l[i][j] = c;         }         if (j + 1 < N) {           int c = i * N + j + 1;           r[i][j] = c;         }         if (i) {           int c = (i - 1) * N + j;           u[i][j] = c;         }         if (i + 1 < N) {           int c = (i + 1) * N + j;           z[i][j] = c;         }       }     }     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &v[i][j]);       }     }     while (q--) {       int a, b, c, d, h, w;       scanf( %d %d %d %d %d %d , &a, &b, &c, &d, &h, &w);       int f = 0, g = 0;       for (int i = 0; i < a; i++) f = z[f / N][f % N];       for (int i = 0; i < b; i++) f = r[f / N][f % N];       for (int i = 0; i < c; i++) g = z[g / N][g % N];       for (int i = 0; i < d; i++) g = r[g / N][g % N];       for (int i = 0; i < h; i++) {         swap_left(f, g);         if (i + 1 < h) {           f = z[f / N][f % N];           g = z[g / N][g % N];         }       }       for (int i = 0; i < w; i++) {         swap_down(f, g);         if (i + 1 < w) {           f = r[f / N][f % N];           g = r[g / N][g % N];         }       }       for (int i = 0; i < h; i++) {         swap_right(f, g);         if (i + 1 < h) {           f = u[f / N][f % N];           g = u[g / N][g % N];         }       }       for (int i = 0; i < w; i++) {         swap_up(f, g);         if (i + 1 < w) {           f = l[f / N][f % N];           g = l[g / N][g % N];         }       }     }     for (int i = 1; i <= n; i++) {       int now = r[i][0];       while (now % N <= m) {         int a = now / N;         int b = now % N;         printf( %d  , v[a][b]);         now = r[a][b];       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int head[100005], nxt[200005], v[200005], w[200005], tot = 0;   int fa[100005], rk[100005];   int p[100005], k[100005], n, m;   long long d[100005];   struct node {     int a, b, c;     long long len;   } e[100005];   queue<int> q;   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x;   }   inline void add(int a, int b, int c) {     tot++;     nxt[tot] = head[a];     head[a] = tot;     v[tot] = b;     w[tot] = c;   }   inline bool cmp(node a, node b) { return a.len < b.len; }   int getf(int a) {     if (a == fa[a]) return a;     return fa[a] = getf(fa[a]);   }   int main() {     int i, num;     n = read();     m = read();     for (i = 1; i <= m; i++) {       e[i].a = read();       e[i].b = read();       e[i].c = read();       add(e[i].a, e[i].b, e[i].c);       add(e[i].b, e[i].a, e[i].c);     }     num = read();     memset(d, 0x3f, sizeof(d));     memset(p, -1, sizeof(p));     for (i = 1; i <= num; i++) {       k[i] = read();       d[k[i]] = 0;       p[k[i]] = k[i];       q.push(k[i]);     }     while (!q.empty()) {       int t = q.front();       q.pop();       for (i = head[t]; i; i = nxt[i]) {         if (d[v[i]] > d[t] + w[i]) {           d[v[i]] = d[t] + w[i];           p[v[i]] = p[t];           q.push(v[i]);         }       }     }     for (i = 1; i <= n; i++) {       fa[i] = i;       rk[i] = 1;     }     for (i = 1; i <= m; i++) {       e[i].len = d[e[i].a] + d[e[i].b] + e[i].c;       e[i].a = p[e[i].a];       e[i].b = p[e[i].b];     }     sort(e + 1, e + m + 1, cmp);     long long ans = d[1];     for (i = 1; i <= m; i++) {       int faa = getf(e[i].a), fab = getf(e[i].b);       if (faa == fab) {         continue;       }       ans += e[i].len;       if (rk[faa] > rk[fab]) {         fa[fab] = faa;       } else {         fa[faa] = fab;       }       if (rk[faa] == rk[fab]) rk[fab]++;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   using vll = vector<long long>;   using vii = vector<pair<int, int>>;   const int N = 105;   int matrix[N][N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &matrix[i][j]);     int score = 0, replace = 0;     for (int j = 0; j < m; j++) {       int best = 0, chop = 0, one = 0;       for (int i = 0; i < n; i++) {         if (matrix[i][j] == 0) continue;         int tmp = 0;         for (int x = 0; x < k && i + x < n; x++) tmp += matrix[i + x][j];         if (tmp > best) {           best = tmp;           chop = one;         }         ++one;       }       score += best;       replace += chop;     }     printf( %d %d n , score, replace);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     while (q--) {       long long c, m, x;       cin >> c >> m >> x;       long long a = min(c, m);       long long left = m - a + x + c - a;       if (left >= a) {         cout << a << endl;       } else {         long long t;         t = x;         c -= x;         m -= x;         if (c == m) {           t += (c + m) / 3;         } else {           if (c > m) {             t += c - m;             long long x = c - m;             c = c - (2 * x);             m = m - x;             t += (c + m) / 3;           } else {             t += m - c;             long long x = m - c;             m = m - (2 * x);             c = c - x;             t += (c + m) / 3;           }         }         cout << t << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<double, double> midpoint(double x1, double y1, double x2, double y2) {     return {(x1 + x2) / 2, (y1 + y2) / 2};   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     map<pair<double, double>, int> mp;     pair<double, double> pr[n + 5];     for (int i = 0; i < n; i++) {       cin >> pr[i].first >> pr[i].second;       mp[pr[i]]++;     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (mp.find(midpoint(pr[i].first, pr[i].second, pr[j].first,                              pr[j].second)) != mp.end())           ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getFldsFromLine(char *line, std::vector<char *> &res,                       const char *sep =    t n v f r );   int main(int argc, char **argv) {     FILE *infile = stdin;     char *line;     line = (char *)calloc(5000000, sizeof(char));     if (line == NULL) {       fprintf(stderr,  Couldn t allocate space for  %s  nBye! n ,  line );       exit(-1);     };     std::vector<char *> flds;     int numFlds, numCases, caseNum = 0;     {       char *feabeqav = fgets(line, 5000000, infile);       numFlds = getFldsFromLine(line, flds);     };     int k = atoi(flds[0]);     if (k != 2) k = 1;     cout << k << endl;     return (0);     return (0);   }   int getFldsFromLine(char *line, std::vector<char *> &res, const char *sep) {     res.clear();     char *tok = strtok(line, sep);     while (tok) {       res.push_back(tok);       tok = strtok(0, sep);     }     return res.size();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int w, h, u1, d1, u2, d2;     cin >> w >> h >> u1 >> d1 >> u2 >> d2;     int ans = w;     if (d1 > d2) {       ans += ((d1 + h) * (h - d1 + 1)) / 2;       ans -= u1;       ans = max(0, ans);       ans += ((d1 + d2 - 1) * (d1 - d2) / 2);       ans -= u2;       ans = max(0, ans);       ans += ((d2) * (d2 - 1)) / 2;     } else {       ans += ((d2 + h) * (h - d2 + 1)) / 2;       ans -= u2;       ans = max(0, ans);       ans += ((d2 + d1 - 1) * (d2 - d1) / 2);       ans -= u1;       ans = max(0, ans);       ans += ((d1 - 1) * (d1)) / 2;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, r[1000], c[1000], min[1000], sum = 0;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> r[i] >> c[i];       min[i] = 9999999999;     }     for (int i = 0; i < n; i++)       if (min[r[i] - 1] > c[i]) min[r[i] - 1] = c[i];     for (int i = 0; i < m; i++) sum += min[i];     if (sum > k)       cout << k;     else       cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, f;   int m;   long long a[2 * 100005];   long long duc = 1e10;   inline long long get(long long pos) {     if (pos <= s)       return s - pos + 1;     else {       return n - pos + s + 1;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];     }     cin >> s >> f;     m = f - s;     long long ans = 0;     long long now = 0;     for (int i = 1; i <= m; i++) {       now += a[i];     }     ans = now;     long long opt = 1;     int l = 1, r = m;     while (l <= n) {       now -= a[l];       now += a[r + 1];       if (ans <= now) {         if (ans < now)           duc = get(l + 1);         else           duc = min(duc, get(l + 1));         ans = now;       }       l++;       r++;     }     cout << duc;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1002][20002];   int main() {     ios_base::sync_with_stdio;     int n, m, x, y, i, j, a;     cin >> n;     long long ans = 0;     for (i = 1; i <= n; i++) {       cin >> a;       for (j = 0; j < a; j++) {         dp[i][j] = dp[i - 1][j + a];       }       for (j = 20000; j > 20000 - a; j--) {         dp[i][j] = dp[i - 1][j - a];       }       for (j = a; j <= 20000 - a; j++) {         dp[i][j] = (dp[i - 1][j - a] + dp[i - 1][j + a]) % 1000000007;       }       dp[i][10000 + a] = (dp[i][10000 + a] + 1) % 1000000007;       ;       dp[i][10000 - a] = (dp[i][10000 - a] + 1) % 1000000007;       ans = (ans + dp[i][10000]) % 1000000007;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, mod2 = 998244353;   unsigned long long base = 131;   const int w = 5e5 + 5;   long long n, m;   struct node {     int x, y, z;   } s[w];   int cmp(node x, node y) {     if (x.x != y.x)       return x.x > y.x;     else       return x.y > y.y;   }   int main() {     long long i, j, t;     cin >> n;     cout << n / 2 + 1 << endl;     for (i = 1; i <= n; i++) scanf( %d , &s[i].x), s[i].z = i;     for (i = 1; i <= n; i++) scanf( %d , &s[i].y);     sort(s + 1, s + 1 + n, cmp);     cout << s[1].z <<    ;     for (i = 2; i <= n; i += 2) {       if (s[i].y > s[i + 1].y)         cout << s[i].z <<    ;       else         cout << s[i + 1].z <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 1;   int a[6];   int n;   int b[MAXN];   int ptr[MAXN];   int f[MAXN][6];   int main() {     for (int i = 0; i < 6; ++i) cin >> a[i];     cin >> n;     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 6; ++j) {         f[i][j] = b[i] - a[j];       }       sort(f[i], f[i] + 6);     }     fill(ptr, ptr + n, 0);     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         pq;     int maxv = -1;     for (int i = 0; i < n; ++i) {       pq.push(make_pair(f[i][ptr[i]], i));       maxv = max(maxv, f[i][ptr[i]]);     }     int minv = -1;     int mini = -1;     int diff = 1e9;     pair<int, int> top;     while (true) {       top = pq.top();       pq.pop();       minv = top.first;       diff = min(diff, maxv - minv);       mini = top.second;       if (ptr[mini] == 5) {         break;       }       ++ptr[mini];       pq.push(make_pair(f[mini][ptr[mini]], mini));       maxv = max(maxv, f[mini][ptr[mini]]);     }     cout << diff << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxi = 2000000000;   const int maxq = 1000000000;   const double eps = 1e-10;   const double pi = acos(-1);   const double inf = 1e+18;   const int mo = 1000000007;   using namespace std;   char s[111111], s1[111111];   int main() {     gets(s);     gets(s1);     int n = strlen(s);     int m = strlen(s1);     int kol = 0;     int kol1 = 0;     int sum = 0;     int ans = 0;     for (int i = 0; i < n; i++)       if (s[i] ==  4 ) kol++;     for (int i = 0; i < n; i++)       if (s1[i] ==  4 ) kol1++;     for (int i = 0; i < n; i++) {       if (kol < kol1 && s[i] ==  7  && s1[i] ==  4 ) {         s[i] =  4 ;         ans++;         kol++;       }       if (kol > kol1 && s[i] ==  4  && s1[i] ==  7 ) {         s[i] =  7 ;         ans++;         kol--;       }     }     for (int i = 0; i < n; i++)       if (s[i] != s1[i]) sum++;     cout << ans + sum / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   struct node {     int same, rev;   } T[524288];   int N, Q, a[100001];   inline void down(int p) {     if (T[p].same) {       T[p << 1].same = T[p].same;       T[p << 1 | 1].same = T[p].same;       T[p << 1].rev = T[p << 1 | 1].rev = 0;       T[p].same = 0;     } else if (T[p].rev) {       if (T[p << 1].same)         T[p << 1].same = -T[p << 1].same;       else         T[p << 1].rev ^= 1;       if (T[p << 1 | 1].same)         T[p << 1 | 1].same = -T[p << 1 | 1].same;       else         T[p << 1 | 1].rev ^= 1;       T[p].rev = 0;     }   }   void P(int p, int l, int r, int L, int R, int w) {     if (L <= l && r <= R) {       T[p] = {w, 0};       return;     }     int m = l + r >> 1;     down(p);     if (L <= m) P(p << 1, l, m, L, R, w);     if (R > m) P(p << 1 | 1, m + 1, r, L, R, w);   }   void REV(int p, int l, int r, int L, int R) {     if (L <= l && r <= R) {       if (T[p].same)         T[p].same = -T[p].same;       else         T[p].rev ^= 1;       return;     }     int m = l + r >> 1;     down(p);     if (L <= m) REV(p << 1, l, m, L, R);     if (R > m) REV(p << 1 | 1, m + 1, r, L, R);   }   int G(int x) {     int p = 1, l = -100000, r = 100000;     while (l < r) {       int m = l + r >> 1;       down(p);       if (x <= m)         p <<= 1, r = m;       else         p = p << 1 | 1, l = m + 1;     }     return T[p].same;   }   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1; i <= N; i++) scanf( %d , a + i);     T[1] = {1, 0};     while (Q--) {       char op[2];       int x;       scanf( %s%d , op, &x);       if (op[0] ==  < ) {         if (x <= 0) {           if (x != -100000) {             P(1, -100000, 100000, -100000, x - 1, -1);             P(1, -100000, 100000, -x + 1, 100000, 1);           }         } else {           REV(1, -100000, 100000, -x + 1, x - 1);           P(1, -100000, 100000, -100000, -x, -1);           P(1, -100000, 100000, x, 100000, 1);         }       } else {         if (x >= 0) {           if (x != 100000) {             P(1, -100000, 100000, x + 1, 100000, -1);             P(1, -100000, 100000, -100000, -x - 1, 1);           }         } else {           REV(1, -100000, 100000, x + 1, -x - 1);           P(1, -100000, 100000, -100000, x, 1);           P(1, -100000, 100000, -x, 100000, -1);         }       }     }     for (int i = 1; i <= N; i++) printf( %d%c , a[i] * G(a[i]),    n [i == N]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e6 + 3;   long long fastexp(long long a, long long b, long long n) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % n;       a = a * a % n;       b >>= 1;     }     return res;   }   int main() {     vector<long long> p(11), re(mod);     for (long long i = 1; i < mod; i++) {       re[i] = fastexp(i, mod - 2, mod);     }     for (int i = 0; i < 11; i++) {       cout <<  ?   << i << endl;       cin >> p[i];       if (p[i] == -1) {         return 0;       }       if (p[i] == 0) {         cout <<  !   << i << endl;         return 0;       }     }     for (int i = 0; i < 11; i++) {       for (int j = 0; j < 11; j++) {         if (j == i) continue;         p[i] = p[i] * re[(i - j + mod) % mod] % mod;       }     }     for (int x = 11; x < mod; x++) {       long long val = 0;       for (int i = 0; i < 11; i++) {         val += p[i] * re[x - i];       }       if (val % mod == 0) {         cout <<  !   << x << endl;         return 0;       }     }     cout <<  ! -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(0);   const long long MAXN = 2e6 + 1, MOD = 998244353, M = 1000000001;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (; t--;) {       long long n, m;       cin >> n >> m;       long long l = (n - m) / (m + 1);       long long k = n - m - (m + 1) * l;       long long ans = l * (l + 1) * (m + 1 - k) / 2 + k * (l + 1) * (l + 2) / 2;       cout << n * (n + 1) / 2 - ans <<   n ;     }     return 0;   }