malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e18;   long long int mul(long long int a, long long int b) {     return ((a % mod) * (b % mod)) % mod;   }   long long int add(long long int a, long long int b) {     return ((a % mod) + (b % mod)) % mod;   }   long long int sub(long long int a, long long int b) {     return ((a % mod) - (b % mod) + mod) % mod;   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long int modInverse(long long int b) {     long long int x, y;     long long int g = gcdExtended(b, mod, &x, &y);     if (g != 1) return -1;     return (x % mod + mod) % mod;   }   long long int modDivide(long long int a, long long int b) {     a = a % mod;     long long int inv = modInverse(b);     if (inv == -1)       return -1;     else       return (inv * a) % mod;   }   long long int expFactor2(long long int n, long long int p) {     long long int exponent = 0;     while (n % p == 0) {       exponent++;       n /= p;     }     return exponent;   }   void sieve(long long int n, vector<bool> &prime, vector<long long int> &p) {     prime[1] = 0;     for (long long int i = 2; i <= n; i++) {       if (prime[i]) {         for (long long int j = i; j <= n; j += i) {           if (j > i) prime[j] = 0;           p[j] += expFactor2(j, i);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, t, j, inp, n, a, b;     cin >> t;     vector<long long int> p(5000001, 0);     vector<bool> prime(5000001, 1);     sieve(5000001, prime, p);     for (i = 2; i <= 5000000; i++) {       p[i] += p[i - 1];     }     for (i = 0; i < t; i++) {       cin >> a >> b;       long long int ans = 0;       ans = p[a] - p[b];       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int n, k, m;   int a[N];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     long long ans = 0;     ans += 1ll * (m / (k + 1)) * (1ll * k * a[n] + a[n - 1]);     ans += 1ll * (m % (k + 1)) * a[n];     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int val[10010], nval[10010], pos[10010], buf[10010];   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i < N - 1; ++i) val[i] = 1;     int br = 0;     for (;;) {       for (int i = 0; i < N; ++i) pos[i] = -1, nval[i] = val[i];       for (int i = N - 1; i >= 0; --i)         if (pos[val[i]] == -1) pos[val[i]] = i;       if (pos[N - 1] != -1) break;       ++br;       for (int i = N - 1; i >= 0; --i) {         int tar = N - 1 - i;         if (val[i] == tar)           buf[i] = N - 1;         else {           if (pos[tar - val[i]] != -1)             buf[i] = pos[tar - val[i]], nval[i] = tar;           else             buf[i] = buf[i + 1], nval[i] += val[buf[i]];         }       }       for (int i = 0; i < N; ++i)         printf( %d%c , buf[i] + 1, (i + 1 == N ?   n  :    ));       for (int i = 0; i < N; ++i) val[i] = nval[i];     }     while (br < K) {       ++br;       for (int i = 0; i < N; ++i) printf( %d%c , N, (i + 1 == N ?   n  :    ));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const double PI = 3.14159265358979323846;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<int> bit(64);     LL sum = 0, ans = 0;     for (int i = 0; i < int(n); ++i) {       LL num;       cin >> num;       sum += num;       ans ^= num;     }     cout << 2 << endl;     cout << ans <<     << ans + sum << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const mxsz = 509;   long long w[mxsz][mxsz];   bool ver[mxsz];   int main() {     vector<int> er;     vector<long long> res;     int n;     scanf( %d , &n);     er.resize(n);     for (int i = 0; i < n; ++i) {       int x;       for (int j = 0; j < n; ++j) {         scanf( %d , &x);         w[i][j] = x;       }     }     for (int i = 0; i < n; ++i) scanf( %d , &er[i]);     reverse(er.begin(), er.end());     for (int k = 0; k < n; ++k) {       er[k]--;       ver[er[k]] = 1;       long long R = 0;       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           w[i][j] = min(w[i][j], w[i][er[k]] + w[er[k]][j]);       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           if (ver[i] && ver[j]) R += w[i][j];       res.push_back(R);     }     for (int i = n - 1; i >= 0; --i) cout << res[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   vector<vector<long long>> g;   vector<long long> a;   vector<long long> ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     g = vector<vector<long long>>(n + 1);     a = vector<long long>(n + 1);     ans = vector<long long>(n + 1, LLONG_MAX);     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i - a[i] >= 1) {         g[i - a[i]].push_back(i);       }       if (i + a[i] <= n) {         g[i + a[i]].push_back(i);       }     }     set<long long> toUp;     for (int i = 1; i <= n; i++) {       for (auto x : g[i]) {         if (a[x] % 2 != a[i] % 2) {           ans[x] = 1;           toUp.insert(x);         }       }     }     while (!toUp.empty()) {       vector<long long> temp(toUp.begin(), toUp.end());       toUp.clear();       for (auto i : temp) {         for (auto x : g[i]) {           if (ans[x] > ans[i] + 1) {             ans[x] = ans[i] + 1;             toUp.insert(x);           }         }       }     }     for (int i = 1; i <= n; i++) {       if (ans[i] == LLONG_MAX)         cout <<  -1  ;       else         cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   char map[101][10001];   long long mic[101][10001];   int n, m;   long long max = 1000000000;   int check = 0;   void find(int x) {     int sum = 0;     for (int i = 0; i < n; i++) {       sum += mic[i][x];       if (sum > max) return;     }     max = sum;   }   int main() {     scanf( %d %d  , &n, &m);     for (int i = 0; i < n; i++) {       gets(map[i]);       int temp = 0;       int mul = 0;       for (int j = 0; j < m; j++) mic[i][j] = 1000000000;       for (int j = 0; j <= m * 2; j++) {         if (map[i][j % m] ==  1 ) {           temp = 0;           mul = 1;         }         if ((temp < mic[i][j % m] && mul == 1) || mic[i][j % m] == 0)           mic[i][j % m] = temp;         temp += mul;       }       temp = 0;       mul = 0;       for (int j = (2 * m); j >= 0; j--) {         if (map[i][j % m] ==  1 ) {           temp = 0;           mul = 1;         }         if ((temp < mic[i][j % m] && mul == 1) || mic[i][j % m] == 0)           mic[i][j % m] = temp;         temp += mul;       }     }     for (int i = 0; i < m; i++) find(i);     if (max >= 1000000000)       printf( -1 );     else       printf( %d , max);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000003;   int a[maxn];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int ans = 0;     int N = 1000000;     while (n--) {       int x;       cin >> x;       a[x]++;       ans = max(ans, a[x]);       for (int i = x * 2; i <= N; i += x) a[i] = max(a[i], a[x]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6 + 5;   const long long int mod = 1e18 + 7;   const double E = 2.71828;   const double PI = 3.14159265;   long long int arr[24][6] = {       {0, 1, 2, 3, 4, 5}, {0, 2, 3, 4, 1, 5}, {0, 3, 4, 1, 2, 5},       {0, 4, 1, 2, 3, 5}, {1, 2, 0, 4, 5, 3}, {1, 0, 4, 5, 2, 3},       {1, 4, 5, 2, 0, 3}, {1, 5, 2, 0, 4, 3}, {2, 5, 3, 0, 1, 4},       {2, 3, 0, 1, 5, 4}, {2, 0, 1, 5, 3, 4}, {2, 1, 5, 3, 0, 4},       {3, 2, 5, 4, 0, 1}, {3, 5, 4, 0, 2, 1}, {3, 4, 0, 2, 5, 1},       {3, 0, 2, 5, 4, 1}, {4, 0, 3, 5, 1, 2}, {4, 3, 5, 1, 0, 2},       {4, 5, 1, 0, 3, 2}, {4, 1, 0, 3, 5, 2}, {5, 4, 3, 2, 1, 0},       {5, 3, 2, 1, 4, 0}, {5, 2, 1, 4, 3, 0}, {5, 1, 4, 3, 2, 0}};   set<string> ss;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     sort(s.begin(), s.end());     ss.insert(s);     while (next_permutation(s.begin(), s.end())) {       bool presen = false;       for (long long int i = 0; i < 24; i++) {         string x =   ;         for (long long int j = 0; j < 6; j++) {           x += s[arr[i][j]];         }         if ((ss.find(x) != ss.end())) {           presen = true;         }       }       if (!presen) {         ss.insert(s);       }     }     cout << ss.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool op = false;     char c = getchar();     while (!isdigit(c)) op |= (c ==  - ), c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return op ? -x : x;   }   const int N = 2e5 + 10;   int n, m, B;   int dif[N], d[500][500], lst[N];   struct Node {     int x, y;     Node() {}     Node(int x, int y) : x(x), y(y) {}   } a[N];   void update(int t, int x, int v) {     int p = a[x].x + a[x].y;     int l = (t + a[x].x) % p, r = (t - 1) % p;     if (l <= r)       for (int i = l; i <= r; i++) d[p][i] += v;     else {       for (int i = 0; i <= r; i++) d[p][i] += v;       for (int i = l; i < p; i++) d[p][i] += v;     }   }   int main() {     n = read();     m = read();     B = sqrt(m);     for (int i = 1; i <= n; i++) {       int x = read(), y = read();       a[i] = Node(x, y);     }     int ans = 0;     for (int t = 1; t <= m; t++) {       int op = read(), x = read();       if (op == 1) {         if (a[x].x + a[x].y > B) {           for (int i = t + a[x].x; i <= m; i += a[x].x + a[x].y) {             dif[i]++;             if (i + a[x].y <= m) dif[i + a[x].y]--;           }         } else           update(t, x, 1);         lst[x] = t;       } else {         if (a[x].x + a[x].y > B) {           for (int i = lst[x] + a[x].x; i <= m; i += a[x].x + a[x].y) {             dif[i]--;             if (i + a[x].y <= m) dif[i + a[x].y]++;             if (i < t && i + a[x].y >= t) ans--;           }         } else           update(lst[x], x, -1);       }       int res = 0;       ans += dif[t];       for (int i = 1; i <= B; i++) res += d[i][t % i];       printf( %d n , res + ans);     }   }
#include <bits/stdc++.h>   using namespace std;   long long LLINF = (long long)1000000000 * 1000000010;   const int MAXN = 410;   int g[MAXN], g1[MAXN];   int c[MAXN];   int M, m;   int solve(int x, int *a) {     int ans = 0;     for (int i = 0; i < m; i++) {       a[i] = x / c[i];       x %= c[i];       ans += a[i];     }     return ans;   }   int main() {     int t, good;     while (scanf( %d , &m) != EOF) {       for (int i = 0; i < m; i++) scanf( %d , &c[i]);       sort(c, c + m, greater<int>());       good = 1;       long long best = LLINF;       for (int i = 1; i < m; i++) {         solve(c[i - 1] - 1, g);         for (int j = i; j < m; j++) {           long long w = 0, v = 0;           for (int k = 0; k < j; k++) {             w += (long long)g[k] * c[k];             v += g[k];           }           w += (long long)(g[j] + 1) * c[j];           v += g[j] + 1;           if (solve(w, g1) > v) {             good = 0;             if (w < best) best = w;           }         }       }       if (good)         cout << -1 << endl;       else         cout << best << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, h, x, r = 0;     cin >> n >> h;     for (int i = 0; i < n; i++) {       cin >> x;       if (x > h) {         r += 2;       } else {         r += 1;       }     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1E3 + 5;   int n;   struct line {     int x, y, w, num;     line(int a = 0, int b = 0, int c = 0, int d = 0) : x(a), y(b), w(c), num(d) {}     bool operator<(const line& A) const { return w > A.w; }   } a[maxn], b[maxn];   vector<line> ans;   inline bool inter(line x, line y) {     int l1 = min(x.x, x.y), r1 = max(x.x, x.y);     int l2 = min(y.x, y.y), r2 = max(y.x, y.y);     return (l1 < l2 && l2 < r1 && r1 < r2) || (l2 < l1 && l1 < r2 && r2 < r1);   }   inline int dis(line A, int x) {     int l = min(A.x, A.y), r = max(A.x, A.y);     if (l <= x && x <= r) return n - (r - l);     return r - l;   }   inline void solve(int x, int y) {     vector<line> wait;     for (int i = 1; i <= n - 3; ++i)       if (inter(a[i], line(x, y)))         wait.push_back(line(a[i].x, a[i].y, dis(a[i], x), i));     if (wait.size() == 0) return;     sort(wait.begin(), wait.end());     for (int i = 0; i < wait.size() - 1; ++i) {       ans.push_back(wait[i]);       int p = wait[i].num;       if (wait[i].x == wait[i + 1].x) {         a[p].x = wait[i + 1].y;         a[p].y = x;       } else if (wait[i].y == wait[i + 1].x) {         a[p].y = wait[i + 1].y;         a[p].x = x;       } else if (wait[i].x == wait[i + 1].y) {         a[p].x = wait[i + 1].x;         a[p].y = x;       } else {         a[p].y = wait[i + 1].x;         a[p].x = x;       }     }     ans.push_back(wait[wait.size() - 1]);     int p = wait[wait.size() - 1].num;     a[p].x = x, a[p].y = y;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n - 3; ++i) cin >> a[i].x >> a[i].y;     for (int i = 1; i <= n - 3; ++i) cin >> b[i].x >> b[i].y;     random_shuffle(b + 1, b + n - 3 + 1);     for (int i = 1; i <= n - 3; ++i) solve(b[i].x, b[i].y);     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i)       cout << ans[i].x <<     << ans[i].y <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 100;   const long long INF = 1e13;   int u, v, c, b, laz[MAXN], C[MAXN], n, m, st[MAXN];   bool vis[MAXN];   multiset<pair<int, int> > Q[MAXN];   multiset<pair<int, int> >::iterator it;   vector<pair<int, int> > W[MAXN];   vector<int> G[MAXN];   pair<int, int> k;   void merg(int v, int u) {     if (Q[v].size() >= Q[u].size()) {       while (!(Q[u].empty())) {         it = Q[u].begin();         int i = (*(it)).second;         C[i] += laz[u] - laz[v];         c = (*it).first;         Q[v].insert({c + laz[u] - laz[v], i});         Q[u].erase(it);       }       return;     }     merg(u, v);     Q[v].swap(Q[u]);     laz[v] = laz[u];     return;   }   long long ans = 0;   int TIM = 0;   bool dfs(int v, int f = -1) {     st[v] = TIM;     TIM++;     for (auto u : G[v]) {       if (u == f) {         continue;       }       bool r = dfs(u, v);       if (!r) {         return 0;       }       merg(v, u);     }     for (auto k : W[v]) {       if (st[k.first] < st[v]) {         C[k.second] -= laz[v];         Q[v].insert({C[k.second], k.second});       } else {         Q[v].erase({C[k.second], k.second});       }     }     if (!v) {       return 1;     }     if (!(Q[v].size())) {       return 0;     }     int h = (*(Q[v].begin())).first;     ans += (h + laz[v]);     laz[v] -= (h + laz[v]);     return 1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       u--;       v--;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 0; i < m; i++) {       cin >> u >> v >> C[i];       u--;       v--;       W[u].push_back({v, i});       W[v].push_back({u, i});     }     bool r = dfs(0);     if (!r) {       cout << -1 << endl;       return 0;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int v, d;     bool operator<(const node &a) const {       if (d == a.d) return v < a.v;       return a.d < d;     }   };   set<node> s;   vector<int> adj[200005];   int d[200005], p[200005];   bool vis[200005];   void dfs(int u) {     int l = adj[u].size();     node nd;     vis[u] = true;     for (int a = 0; a < l; a++) {       int v = adj[u][a];       if (!vis[v] && v != p[u]) dfs(v);     }     nd.v = u, nd.d = d[u];     s.erase(nd);   }   int main() {     int n, ans = 0;     cin >> n;     for (int a = 1; a < n; a++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     queue<int> q;     node nd;     q.push(1);     d[1] = p[1] = 0, vis[1] = true;     while (!q.empty()) {       int u = q.front();       q.pop();       nd.v = u, nd.d = d[u];       s.insert(nd);       int l = adj[u].size();       for (int a = 0; a < l; a++) {         int v = adj[u][a];         if (vis[v]) continue;         d[v] = 1 + d[u], p[v] = u;         q.push(v), vis[v] = true;       }     }     memset(vis, false, sizeof(vis));     while (!s.empty()) {       nd = *(s.begin());       if (nd.d > 2) {         dfs(p[nd.v]), ans++;         nd.v = p[p[nd.v]];         nd.d = d[nd.v];         s.erase(nd);       } else         break;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> G[1000005];   int n, L[1000005], R[1000005], ind;   void dfs(int u, int pre) {     for (int i = G[u].size() - 1; i >= 0; i--) {       int v = G[u][i];       if (v != pre) L[v] = ++ind;     }     R[u] = ++ind;     for (auto v : G[u])       if (v != pre) dfs(v, u);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     L[1] = ++ind;     dfs(1, 1);     for (int i = 1; i <= n; i++) cout << L[i] <<     << R[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long A, B;       cin >> A >> B;       long long hb = (floor(log10(B + 1)) == log10(B + 1)) ? (floor(log10(B)) + 1)                                                            : floor(log10(B));       cout << hb * A << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct rect {     int x1, y1, x2, y2;   };   struct rect a[40001], c[40001];   int b[40001];   int w, h, n, nr;   void enter() {     scanf( %d%d%d , &w, &h, &n);     nr = 1;     a[1].x1 = 0;     a[1].y1 = 0;     a[1].x2 = w;     a[1].y2 = h;   }   void call1(int x1, int y1, int x2, int y2) {     int i;     for (i = 1; i <= nr; i++)       if ((a[i].x1 < x1) && (x2 < a[i].x2) && (a[i].y1 == y1) && (a[i].y2 == y2))         break;     nr++;     a[nr] = a[i];     a[i].x2 = x2;     a[nr].x1 = x2;   }   void call2(int x1, int y1, int x2, int y2) {     int i;     for (i = 1; i <= nr; i++)       if ((a[i].y1 < y1) && (y2 < a[i].y2) && (a[i].x1 == x1) && (a[i].x2 == x2))         break;     nr++;     a[nr] = a[i];     a[i].y2 = y2;     a[nr].y1 = y2;   }   void solve() {     int x1, y1, x2, y2, t;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       c[i].x1 = x1;       c[i].x2 = x2;       c[i].y1 = y1;       c[i].y2 = y2;       b[i] = 1;     }     for (int i = 1; i <= n; i++) {       t = 0;       for (int j = 1; j <= n; j++)         if ((b[j] == 1) && (t == 0)) {           x1 = c[j].x1;           x2 = c[j].x2;           y1 = c[j].y1;           y2 = c[j].y2;           for (int k = 1; k <= nr; k++)             if (((y1 == y2) && (a[k].y1 < y1) && (y2 < a[k].y2) &&                  (a[k].x1 == x1) && (a[k].x2 == x2)) ||                 ((x1 == x2) && (a[k].x1 < x1) && (x2 < a[k].x2) &&                  (a[k].y1 == y1) && (a[k].y2 == y2)))               t = j;         }       b[t] = 0;       x1 = c[t].x1;       x2 = c[t].x2;       y1 = c[t].y1;       y2 = c[t].y2;       if (x1 == x2)         call1(x1, y1, x2, y2);       else         call2(x1, y1, x2, y2);     }     for (int i = 1; i <= w * h; i++) b[i] = 0;     for (int i = 1; i <= nr; i++) b[(a[i].x2 - a[i].x1) * (a[i].y2 - a[i].y1)]++;   }   void print() {     for (int i = 1; i <= w * h; i++)       for (int j = 1; j <= b[i]; j++) printf( %d  , i);   }   int main() {     enter();     solve();     print();     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int a[1010][1010];   int p[1010][1010];   int w[1010];   int n, m;   int ok(int d) {     int cur, i, j, k;     for (i = 0; i < m; i++)       for (j = 0; j < m; j++) p[i][j] = 0;     for (i = 0; i < n; i++) {       cur = 0;       for (j = 0; j < m; j++)         if (a[i][j] >= d) w[cur++] = j;       for (j = 0; j < cur; j++) {         for (k = 0; k < j; k++) {           if (1 == p[w[k]][w[j]]) return 1;           p[w[k]][w[j]] = 1;         }       }     }     return 0;   }   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) scanf( %d , &a[i][j]);     int l, r, res, mid;     res = 0;     l = 0;     r = 1000000000;     ok(11);     while (l < r) {       mid = (l + r + 1) / 2;       if (1 == ok(mid)) {         res = mid;         l = mid;       } else         r = mid - 1;     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int main() {     cin.tie(nullptr)->sync_with_stdio(false);     int T;     vector<int> f(3e5 + 5);     f[0] = 0;     for (int i = 1; i < 3e5 + 5; i++) f[i] = f[i - 1] ^ i;     for (cin >> T; T; T--) {       int a, b;       cin >> a >> b;       int ans = a;       if (f[a - 1] == 0) {         if (f[a - 1] == b)           ans = ans;         else if (a == b)           ans += 2;         else           ans++;       } else {         if (f[a - 1] == b)           ans = ans;         else if ((f[a - 1] ^ b) != a)           ans++;         else           ans += 2;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<string> S;   string line[1010], a[1010], s;   int n = 0, ans = 0, file = 0;   int main() {     while (getline(cin, s)) line[++n] = s;     for (int i = 1; i <= n; i++) {       int cur = 0;       a[i] =   ;       for (int j = 0; j < line[i].size(); j++) {         a[i] += line[i][j];         if (line[i][j] ==     ) cur++;         if (cur == 2) break;       }     }     for (int i = 1; i <= n; i++) {       string fd = a[i];       S.clear();       int files = 0, F = 0;       for (int j = 1; j <= n; j++)         if (a[j] == fd) {           files++;           string v =   ;           int cur = 0;           for (int k = 0; k < line[j].size(); k++) {             v += line[j][k];             if (line[j][k] ==     ) cur++;             if (line[j][k] ==      && cur > 2)               if (!S.count(v)) S.insert(v), F++;           }         }       ans = max(ans, F);       file = max(file, files);     }     cout << ans <<     << file << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     stack<pair<int, int> > S;     S.push(make_pair(0, -1));     vector<pair<int, int> > ans;     for (int i = 0; i <= n; i++) {       int a;       if (i < n)         cin >> a;       else         a = 0;       while (S.top().first > a) {         pair<int, int> last = S.top();         S.pop();         ans.push_back(make_pair(last.second, i - 1));         last.first--;         if (last.first > S.top().first) S.push(last);       }       if (S.top().first != a) S.push(make_pair(a, i));     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;   }