malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int BUFFER_SIZE = 1 << 20;   char rb[BUFFER_SIZE], *rp = rb, *rt = rb;   inline char read_char() {     return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp++)                     : *rp++;   }   inline int read_int() {     int x = 0;     char ch = read_char(), flag = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) {       ch = read_char();     }     if (ch ==  - ) {       flag = 1;       ch = read_char();     }     for (x = 0; ch >=  0  && ch <=  9 ; ch = read_char()) {       x = x * 10 + (ch -  0 );     }     return flag ? -x : x;   }   const int MAX_N = 200000 + 5;   int N, n[2], siz[MAX_N];   int ey[MAX_N << 1], enext[MAX_N << 1], elast[MAX_N];   void dp(int u, int fa, int dep) {     n[dep & 1]++;     siz[u] = 1;     for (int j = elast[u]; j; j = enext[j]) {       int v = ey[j];       if (v != fa) {         dp(v, u, dep ^ 1);         siz[u] += siz[v];       }     }   }   int main() {     N = read_int();     for (int i = 1, j = 1; i < N; i++) {       int x = read_int();       int y = read_int();       ey[j] = y;       enext[j] = elast[x];       elast[x] = j++;       ey[j] = x;       enext[j] = elast[y];       elast[y] = j++;     }     dp(1, 0, 0);     long long ans = 0;     for (int i = 1; i <= N; i++) {       ans += 1ll * siz[i] * (N - siz[i]);     }     ans += 1ll * n[0] * n[1];     printf( %lld n , ans >> 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     string s;     cin >> s;     int x = -1, y = -1;     for (int i = 0; i < s.size(); ++i) {       for (int j = 0; j < i; ++j) {         if (s[i] == s[j]) {           x = j, y = i;         }       }     }     if (abs(y - x) == 1) {       cout <<  Impossible  << endl;       return 0;     }     int len = y - x;     char ans[2][13];     for (int i = 0; i < 13; ++i) {       ans[0][i] = ans[1][i] =  * ;     }     for (int i = (len + 1) / 2 - 1; i >= 0; i--) {       ans[0][i] = s[x + ((len + 1) / 2 - 1 - i)];     }     for (int i = 0; i < len - (len + 1) / 2; ++i) {       ans[1][i] = s[x + (len + 1) / 2 + i];     }     int pos0 = (len + 1) / 2, pos1 = len - (len + 1) / 2;     if (13 - pos0 > x) {       for (int i = 0; i < x; ++i) {         ans[0][pos0 + i] = s[x - 1 - i];       }       for (int i = pos1; i < 13; ++i) {         ans[1][i] = s[y + 1 + (i - pos1)];       }       for (int i = pos0 + x; i < 13; ++i) {         ans[0][i] = s[27 - (i - pos0 - x) - 1];       }     } else {       for (int i = 0; i < 13 - pos0; ++i) {         ans[0][pos0 + i] = s[x - 1 - i];       }       for (int i = pos1; i < pos1 + (26 - y); ++i) {         ans[1][i] = s[y + 1 + (i - pos1)];       }       pos1 += 26 - y;       for (int i = 0; i + pos1 < 13; ++i) {         ans[1][i + pos1] = s[i];       }     }     for (int i = 0; i < 13; ++i) {       cout << ans[0][i];     }     cout << endl;     for (int i = 0; i < 13; ++i) {       cout << ans[1][i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int dem = 1, i, n, c;     scanf( %d %d , &n, &c);     int a[n];     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (i = 1; i < n; i++) {       if (a[i] - a[i - 1] <= c) {         dem++;       }       if (a[i] - a[i - 1] > c) {         dem = 1;       }     }     printf( %d , dem);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int m = 1e9 + 7;   const int N = 3e5 + 15;   const int64_t INF = 100000000000000018LL;   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                  greater<pair<long long, long long>>>       pq;   vector<vector<long long>> graph(N);   vector<long long> collect;   map<long long, long long> mpp;   set<pair<long long, long long>> s;   set<long long> second;   long long odd = 0, even = 0;   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   long long inv(long long a) { return pow(a, m - 2, m); }   void dfs(long long ind, vector<bool>& visited) {     visited[ind] = true;     for (auto it : graph[ind]) {       {         if (!visited[it]) dfs(it, visited);       }     }   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   void solve() {     long long a, b, n, x;     cin >> a >> b >> n >> x;     long long ans = pow(a, n, m);     n = n % m;     long long aa = ans * x;     if (aa < 0) aa += m;     aa = aa % m;     long long aa1 = 1;     if (a == 1) {       long long z1 = b * n;       z1 = z1 % m;       cout << (x + z1) % m;       return;     }     aa1 = ((ans - 1 + m) % m) * inv(a - 1);     aa1 = aa1 % m;     if (aa1 < 0) aa1 += m;     aa1 = aa1 * b;     cout << (aa + aa1 + m) % m <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     int x, y;     Point(int x0, int y0) : x(x0), y(y0) {}     Point() : x(0), y(0) {}   };   int t;   int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};   int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};   int n, m;   long long maxx;   int d[100005][4];   int a[100005], h[100005];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> h[i];     }     memset(d, 0, sizeof(d));     d[0][0] = 1;     d[0][1] = 0;     if (a[1] - a[0] > h[1])       d[0][2] = 1;     else       d[0][2] = 0;     int res = 1;     for (int i = 1; i < n; i++) {       int dis = a[i] - a[i - 1];       if (h[i] < dis) d[i][0] = max(d[i - 1][0] + 1, d[i - 1][1] + 1);       if (h[i] + h[i - 1] < dis) d[i][0] = max(d[i][0], d[i - 1][2] + 1);       d[i][1] = max(d[i - 1][0], d[i - 1][1]);       if (h[i - 1] < dis) d[i][1] = max(d[i][1], d[i - 1][2]);       if (h[i] < a[i + 1] - a[i] || i == n - 1)         d[i][2] = max(d[i - 1][0] + 1, d[i - 1][1] + 1);       if (h[i - 1] < dis) d[i][2] = max(d[i][2], d[i - 1][2] + 1);       res = max(res, max(d[i][0], max(d[i][1], d[i][2])));     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str;     cin >> n >> str;     int sum = 0;     bool flag = false;     for (int i = 0; i < n - 1; i++) {       sum += str[i] - 48;       int ts = 0, ti = i + 1;       while (ti < n && ts <= sum) {         if (ts == sum && str[ti] != 48) {           ts = 0;         }         ts += str[ti] - 48;         ti++;       }       if (ti == n && ts == sum) {         flag = true;         break;       }     }     if (flag) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, st;   int tmp, tmp2;   vector<int> adj[200005];   int memo[200005][5];   bool vis[200005][5];   int stc, stn;   pair<int, int> par[200005][5];   int dp(int node, int cur) {     if (adj[node].size() == 0) {       if (cur == 2) {         stc = cur;         stn = node;         return 1;       }       if (cur == 1) {         stc = cur;         stn = node;       }       return cur;     }     if (memo[node][cur] != -1) return memo[node][cur];     int ret = 0;     pair<int, int> cp;     cp.first = node;     cp.second = cur;     for (int i = 0; i < adj[node].size(); i++) {       if (cur == 2) {         if (vis[adj[node][i]][cur]) {           if (ret == 0) ret = 2;           continue;         }         vis[adj[node][i]][cur] = 1;         par[adj[node][i]][cur] = cp;         int now = dp(adj[node][i], cur);         if (now == 1) ret = 1;         vis[adj[node][i]][cur] = 0;       } else {         if (vis[adj[node][i]][(cur + 1) % 2]) {           if (ret == 0) ret = 2;           continue;         }         vis[adj[node][i]][(cur + 1) % 2] = 1;         par[adj[node][i]][(cur + 1) % 2] = cp;         int now = dp(adj[node][i], (cur + 1) % 2);         if (now == 1)           ret = 1;         else if (now == 2 && ret == 0)           ret = 2;         vis[adj[node][i]][(cur + 1) % 2] = 0;       }     }     return memo[node][cur] = ret;   }   void dfs(int node, int cur) {     if (node == st && cur == 0) {       printf( %d , node);       return;     }     dfs(par[node][cur].first, par[node][cur].second);     printf(  %d , node);     return;   }   int main() {     memset(memo, -1, sizeof(memo));     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &tmp);       for (int j = 1; j <= tmp; j++) {         scanf( %d , &tmp2);         adj[i].push_back(tmp2);       }     }     scanf( %d , &st);     int ans = dp(st, 0);     if (ans == 0) {       printf( Lose n );     } else if (ans == 2) {       printf( Draw n );     } else {       printf( Win n );       dfs(stn, stc);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   char ch[111111];   int main() {     scanf( %d%d , &n, &k);     scanf( %s , ch);     int pos = 0;     for (int act = 0; act <= 1000000 && act < k && pos < n - 1; ++act) {       if (act >= 1000000 && act % 2 == k % 2) break;       while (pos < n - 1 && !(ch[pos] ==  4  && ch[pos + 1] ==  7 )) pos++;       if (pos == n - 1) break;       if (pos % 2 == 0)         ch[pos] = ch[pos + 1] =  4 ;       else         ch[pos] = ch[pos + 1] =  7 ;       --pos;       if (pos < 0) pos = 0;     }     printf( %s n , ch);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   const int MAXV = 100;   double prob[MAXN + 5][MAXV + 5];   int sz[MAXN + 5];   double temp[MAXV + 5];   int n;   double ncr(int r, int n) {     if (r > n) return 0;     double ret = 1;     for (int c = 0; c < r; c++) ret *= n - c;     for (int c = 0; c < r; c++) ret /= c + 1;     return ret;   }   double probabilityToTaketakeFromVuntasted(int take, int k, int untasted,                                             int from) {     int tasted = sz[from] - untasted;     return ncr(take, untasted) * ncr(k - take, tasted) / ncr(k, sz[from]);   }   int main() {     int c, c2;     memset(prob, 0, sizeof(prob));     double ret = 0;     scanf( %d , &n);     for (c = 0; c < n; c++) {       scanf( %d , &sz[c]);       prob[c][sz[c]] = 1.0;     }     for (c = 0; c < n; c++) ret += prob[c][0];     int qs;     for (scanf( %d , &qs); qs; qs--) {       int from, to, k;       scanf( %d%d%d , &from, &to, &k);       from--;       to--;       memset(temp, 0, sizeof(temp));       double denominator = ncr(k, sz[from]);       for (int untasted = 0; untasted <= MAXV; untasted++) {         int newk = min(k, untasted);         int tasted = sz[from] - untasted;         double n1 = 1, n2 = 1;         double d1 = 1, d2 = 1;         for (int i = 0; i < min(tasted, k); i++) {           d2 *= i + 1;           n2 *= tasted - i;         }         for (int take = 0; take <= k; take++) {           if (take > 0) {             d1 *= take;             if (take <= untasted)               n1 *= untasted - take + 1;             else               n1 = 0;           }           if (k - take > tasted) continue;           temp[untasted - take] +=               prob[from][untasted] * (n1 / d1) * (n2 / d2) / denominator;           if (k - take > 0) {             d2 /= k - take;             n2 /= tasted - (k - take) + 1;           }         }       }       ret += temp[0] - prob[from][0];       for (int i = 0; i <= MAXV; i++) prob[from][i] = temp[i];       sz[from] -= k;       sz[to] += k;       printf( %.10lf n , ret);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:500000000 )   using namespace std;   vector<int> A[2];   int main() {     int n, i, j, t, w;     cin >> n;     for (i = 0; i < n; i++) {       cin >> t >> w;       A[t - 1].push_back(w);     }     for (i = 0; i < 2; i++) sort(A[i].begin(), A[i].end(), greater<int>());     int res = 0x3F3F3F3F;     for (int x = -1; x < (int)A[0].size(); x++) {       for (int y = -1; y < (int)A[1].size(); y++) {         w = (x + 1) + 2 * (y + 1);         int s = 0;         for (i = x + 1; i < A[0].size(); i++) s += A[0][i];         for (i = y + 1; i < A[1].size(); i++) s += A[1][i];         if (s <= w) res = min(res, w);       }     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int a, b, k;     cin >> a >> b >> k;     long long int total = 0;     if (k % 2 != 0) {       total -= b * (k / 2);       total += a * (k / 2 + 1);     } else {       total -= b * (k / 2);       total += a * (k / 2);     }     cout << total << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int a[503][503];   int max_row[503];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, q, i, j, mxi, cnt, x, y;     cin >> n >> m >> q;     for (i = 1; i <= n; i++) {       mxi = 0, cnt = 0;       for (j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j])           cnt++;         else           cnt = 0;         mxi = ((mxi > cnt) ? mxi : cnt);       }       max_row[i] = mxi;     }     for (i = 0; i < q; i++) {       cin >> x >> y;       a[x][y] ^= 1;       cnt = 0, mxi = 0;       for (j = 1; j <= m; j++) {         if (a[x][j])           cnt++;         else           cnt = 0;         mxi = ((mxi > cnt) ? mxi : cnt);       }       max_row[x] = mxi;       mxi = 0;       for (j = 1; j <= n; j++) mxi = ((mxi > max_row[j]) ? mxi : max_row[j]);       cout << mxi << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char A[200006];   int S[200006], T[200006];   void solve() {     cin >> n >> m;     scanf( %s , A + 1);     long long re = 0;     for (int i = (1), iend = (n); i <= iend; ++i) {       S[i] = (A[i] != A[i + 1]) + S[i - 1];       if (i >= 2 && A[i] == A[i - 2])         T[i] = T[i - 1] + 1;       else if (i >= 2)         T[i] = 2;       else         T[i] = 1;     }     for (int r = (1), rend = (n); r <= rend; ++r) {       if (A[r] != A[r - 1]) re += (m - 1) * 1ll * (r - 1);       re += m - 1;       re += S[r - 1] * 1ll * (m - 1);       if (A[r] != A[r - 1]) re -= T[r] - 1;     }     cout << re << endl;   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, m, n, x, y;     cin >> n;     if (n == 1) {       x = 9;       y = 8;     }     if (n == 2) {       x = 6;       y = 4;     }     if (n == 3) {       x = 9;       y = 6;     }     if ((n != 2) && (n != 1) && (n != 3)) {       if (n % 2 == 0) {         x = 2 * n;         y = n;       } else {         x = n + 9;         y = 9;       }     }     cout << x <<     << y <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long A, B, D;   int a[70], b[70], len1, len2;   int main() {     cin >> A >> B;     D = A - B;     unsigned long long temp = A;     if (A < B) {       cout << -1 << endl;       return 0;     }     while (A) {       a[len1++] = A % 2;       A /= 2;     }     while (B) {       b[len2++] = B % 2;       B /= 2;     }     unsigned long long res = 0;     for (int i = len1 - 1; i >= 0; --i) {       if (!b[i]) {         unsigned long long n = (1ULL << i);         if (n <= D / 2.0) {           D -= 2 * n;           res += n;         }       }     }     if (D) {       cout << -1 << endl;       return 0;     }     cout << res <<     << temp - res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, d;     while (~scanf( %lld%lld , &x, &d)) {       vector<pair<long long, int> > counts;       long long sum = 0;       long long num = 1;       while (x > 0) {         long long two = 1;         int count = 0;         while (two - 1 <= x) two *= 2, count++;         two /= 2, count--;         sum += count;         counts.emplace_back(num, count);         x -= two - 1;         num += d;       }       printf( %lld n , sum);       for (int i = 0; i < counts.size(); i++)         for (int j = 0; j < counts[i].second; j++)           printf( %lld  , counts[i].first);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int long long x, y, l, r, k, i, j, ans;   vector<int long long> mex, mey, my;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> x >> y >> l >> r;     for (k = 1; k <= 1e18 / x; k *= x) mex.push_back(k);     if (k <= 1e18) mex.push_back(k);     for (k = 1; k <= 1e18 / y; k *= y) mey.push_back(k);     if (k <= 1e18) mey.push_back(k);     for (i = 0; i < mex.size(); i++) {       for (j = 0; j < mey.size(); j++) {         if (mex[i] + mey[j] > r) break;         if (mex[i] + mey[j] >= l) {           my.push_back(mex[i] + mey[j]);         }       }     }     my.push_back(l - 1);     x = l;     sort(my.begin(), my.end());     my.push_back(r + 1);     for (i = 1; i < my.size(); i++) {       ans = max(ans, my[i] - my[i - 1] - 1);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int N, P;   bool can = false;   string word;   int main() {     scanf( %d%d , &N, &P);     cin >> word;     if (P == 1) {       cout <<  NO n ;       return 0;     } else if (P == 2) {       if (N == 1) {         if (word ==  a )           cout <<  b n ;         else           cout <<  NO n ;       } else if (N == 2) {         if (word ==  ab )           cout <<  ba n ;         else           cout <<  NO n ;       } else if (N > 2)         cout <<  NO n ;       return 0;     }     for (int i = N - 1; i >= 0; --i) {       ++word[i];       while ((i >= 1 && word[i] == word[i - 1]) ||              (i >= 2 && word[i] == word[i - 2]))         ++word[i];       if ((word[i] -  a ) + 1 <= P) {         can = true;         for (int j = i + 1; j < N; ++j) {           word[j] =  a ;           while ((j >= 1 && word[j] == word[j - 1]) ||                  (j >= 2 && word[j] == word[j - 2]))             ++word[j];         }         break;       }     }     if (can)       cout << word;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int ts;     cin >> ts;     while (ts--) {       long long n, i, vis[500] = {0}, a;       cin >> n;       for (i = 1; i <= 2 * n; i++) {         cin >> a;         if (vis[a] == 0) {           cout << a <<    ;         }         vis[a] = 1;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   int a[1003][1003], p[maxn], num[maxn], n, m, vis[1003][1003];   long long k;   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   int fi(int x) { return p[x] == x ? x : p[x] = fi(p[x]); }   void uni(int x, int y) {     int p1 = fi(x), p2 = fi(y);     if (p1 == p2) return;     p[p1] = p2;     num[p2] += num[p1];     num[p1] = 0;   }   struct node {     int x, y, z;     node(int x1, int y1, int z1) { x = x1, y = y1, z = z1; }   };   bool cmp(node a, node b) { return a.x > b.x; }   vector<node> Q;   void solve(int x, int y, int z, int v) {     queue<node> Q;     Q.push(node(x, y, 0));     vis[x][y] = 1;     z--;     while (!Q.empty()) {       node now = Q.front();       Q.pop();       for (int i = 0; i < 4; i++) {         int xx = now.x + dx[i];         int yy = now.y + dy[i];         if (z == 0) continue;         if (xx <= 0 || xx > n) continue;         if (yy <= 0 || yy > m) continue;         if (vis[xx][yy]) continue;         if (a[xx][yy] < v) continue;         vis[xx][yy] = 1, z--;         Q.push(node(xx, yy, 0));       }     }     for (int i = 1; i <= n; i++, cout << endl)       for (int j = 1; j <= m; j++)         if (vis[i][j])           printf( %d  , v);         else           printf( 0  );   }   int main() {     scanf( %d%d%lld , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         scanf( %d , &a[i][j]), Q.push_back(node(a[i][j], i, j));     for (int i = 0; i < maxn; i++) p[i] = i, num[i] = 1;     sort(Q.begin(), Q.end(), cmp);     for (int i = 0; i < Q.size(); i++) {       int v = Q[i].x;       if (v == 0) break;       int x = Q[i].y;       int y = Q[i].z;       for (int j = 0; j < 4; j++) {         int xx = x + dx[j];         int yy = y + dy[j];         if (a[xx][yy] >= v) uni((xx - 1) * m + yy, (x - 1) * m + y);       }       long long Num = k / v;       if (k % v) continue;       int fa = fi((x - 1) * m + y);       if (Num <= num[fa]) {         printf( YES n );         solve(x, y, Num, v);         return 0;       }     }     printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   bool prime[100005];   int dp[505][505], dp2[505][505];   int main() {     long long int h, w, i, j, a, b, c, d, q, sum;     cin >> h >> w;     char arr[h][w + 1];     for (i = 0; i <= h - 1; i++) cin >> arr[i];     for (i = 0; i <= h - 1; i++) {       for (j = 1; j <= w - 1; j++) {         if (arr[i][j] ==  .  && arr[i][j - 1] ==  . )           dp[i][j] = dp[i][j - 1] + 1;         else           dp[i][j] = dp[i][j - 1];       }     }     for (i = 0; i <= w - 1; i++) {       for (j = 1; j <= h - 1; j++) {         if (arr[j][i] ==  .  && arr[j - 1][i] ==  . )           dp2[j][i] = dp2[j - 1][i] + 1;         else           dp2[j][i] = dp2[j - 1][i];       }     }     cin >> q;     while (q--) {       sum = 0;       cin >> a >> b >> c >> d;       for (i = a - 1; i <= c - 1; i++) sum = sum + dp[i][d - 1] - dp[i][b - 1];       for (i = b - 1; i <= d - 1; i++) sum = sum + dp2[c - 1][i] - dp2[a - 1][i];       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 2e6 + 14;   int n, a[Maxn], b[Maxn], ans, m;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = a[i], m = max(m, a[i]);     sort(a, a + n);     for (int i = 1; i <= 2 * m; i++) {       if (b[i] == 0) b[i] = b[i - 1];     }     for (int i = m - 1; i > ans; i--) {       if (b[i] == i)         for (int j = i * 2 - 1; j < 2 * m; j += i) {           ans = max(ans, b[j] % i);         }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   const int MX = 1e6 + 5;   const int MD = 1e9 + 7;   int next(vector<int> &a, int pos, long long p) {     long long cnt = 2;     int l = pos, r = pos;     while (r < ((int)a.size())) {       while (r < ((int)a.size()) && cnt > 0 && a[r] == a[l]) r++, cnt--;       if (cnt == 0) return r;       if (r == ((int)a.size())) return -1;       for (int i = 0; cnt <= ((int)a.size()) && i < a[l] - a[r]; i++) cnt *= p;       if (cnt > ((int)a.size())) return -1;       l = r;     }     return -1;   }   long long pt(long long b, long long e) {     long long ans = 1;     while (e > 0) {       if (e & 1) ans = (ans * b) % MD;       b = (b * b) % MD;       e >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, p;       cin >> n >> p;       vector<int> a(n);       for (int &x : a) cin >> x;       if (p == 1) {         cout << n % 2 <<   n ;         continue;       }       sort(a.begin(), a.end());       reverse(a.begin(), a.end());       int last = -1;       for (int l = 0, r = 0; l < n; l = r) {         r = next(a, l, p);         if (r == -1) {           last = l;           break;         }       }       if (last == -1) {         cout << 0 <<   n ;         continue;       }       long long ans = pt(p, a[last]);       for (int i = last + 1; i < n; i++) ans = (ans - pt(p, a[i]) + MD) % MD;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char a[15], b[15], c[15];     scanf( %s%s , a, b);     scanf( %d , &n);     printf( %s %s n , a, b);     for (int i = 1; i <= n; i++) {       scanf( %s , c);       int l = strlen(c);       int la = strlen(a);       int lb = strlen(b);       if (memcmp(a, c, l) == 0 && l == la) {         scanf( %s , a);         printf( %s %s n , a, b);       }       if (memcmp(b, c, l) == 0 && l == lb) {         scanf( %s , b);         printf( %s %s n , a, b);       }     }     return 0;   }