malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000 + 3000;   int n, m;   int a[maxn], l[maxn], r[maxn], pos[maxn];   struct Segtree {     int l, r;     int val;   } node[maxn << 3];   inline int read() {     int x;     scanf( %d , &x);     return x;   }   inline void build(int p, int l, int r) {     node[p].l = l, node[p].r = r;     node[p].val = 0;     if (l == r) return;     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);   }   inline void update(int p) {     node[p].val = node[p << 1].val + node[p << 1 | 1].val;   }   inline void change(int p, int vl, int vr, int c) {     if (node[p].l == vl && node[p].r == vr) {       node[p].val += c;       return;     }     int mid = (node[p].l + node[p].r) >> 1;     if (vr <= mid)       change(p << 1, vl, vr, c);     else       change(p << 1 | 1, vl, vr, c);     update(p);   }   inline int query(int p, int vl, int vr) {     if (node[p].l == vl && node[p].r == vr) return node[p].val;     int mid = (node[p].l + node[p].r) >> 1;     if (vr <= mid)       return query(p << 1, vl, vr);     else if (vl > mid)       return query(p << 1 | 1, vl, vr);     else       return query(p << 1, vl, mid) + query(p << 1 | 1, mid + 1, vr);   }   int main() {     n = read(), m = read();     build(1, 1, n + m);     for (int i = 1; i <= n; ++i)       change(1, m + i, m + i, 1), pos[i] = m + i, l[i] = r[i] = i;     for (int i = 1; i <= m; ++i) {       scanf( %d , &a[i]);       l[a[i]] = min(1, l[a[i]]);       r[a[i]] = max(r[a[i]], query(1, 1, pos[a[i]]));       change(1, pos[a[i]], pos[a[i]], -1);       pos[a[i]] = m - i + 1;       change(1, pos[a[i]], pos[a[i]], 1);     }     for (int i = 1; i <= n; ++i) {       r[i] = max(r[i], query(1, 1, pos[i]));       printf( %d %d n , l[i], r[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   int n, m, k, s;   vector<int> e[200005];   vector<int> dfn, res[200005];   bool vis[200005];   void dfs(int u) {     vis[u] = 1;     dfn.push_back(u);     for (auto v : e[u])       if (!vis[v]) dfs(v), dfn.push_back(u);   }   signed main() {     n = read(), m = read(), k = read(), s = ceil(2.0 * n / k);     for (register int i = (1); i <= (m); ++i) {       int u = read(), v = read();       e[u].push_back(v), e[v].push_back(u);     }     dfs(1);     for (register int i = (0); i <= ((int)dfn.size() - 1); ++i)       res[i / s + 1].push_back(dfn[i]);     for (register int i = (1); i <= (k); ++i) {       if (!res[i].size()) res[i].push_back(1);       cout << res[i].size() <<    ;       for (auto x : res[i]) cout << x <<    ;       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct sb {     long long x;     long long y;     bool operator<(const sb &wakaka) const { return x < wakaka.x; }   } test;   set<sb> node;   int main() {     long long x;     cin >> x;     long long len = 2 * pow((double)x, (double)1 / (double)3);     long long cnt = 0;     long long n = 0;     while (1) {       n++;       if (n > len) break;       long long en = x * 6;       long long i2 = (n - 1) * n * (2 * n - 1);       en = en - i2;       long long he = (n - 1) * n * 3;       en = en + he * n;       long long la = 6 * n * n - he;       if (en % la == 0) {         long long ans = en / la;         test.x = n;         test.y = ans;         if (ans < n) break;         node.insert(test);         test.y = n;         test.x = ans;         node.insert(test);         cnt = cnt + 2;       }     }     cout << node.size() << endl;     for (set<sb>::iterator it = node.begin(); it != node.end(); it++) {       test = *it;       cout << test.x <<     << test.y << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int N = 30 + 7;   const int mod = 1e9 + 7;   const int B = 317;   int n;   int u, r;   int a[N][N];   int b[N];   int c[N];   int p[N];   long long foo(int x, bool f) {     long long s = -1e18;     if (x % 2 == 0) {       s = 0;       for (int i = 1; i <= n; i++) s += a[x][i] * 1LL * c[i];     }     if (x == 0) return s;     if (f) {       for (int i = 1; i <= n; i++) {         a[x - 1][i] = a[x][i] ^ b[i];       }       s = max(s, foo(x - 1, false));     }     for (int i = 1; i <= n; i++) {       a[x - 1][i] = a[x][p[i]] + r;     }     s = max(s, foo(x - 1, true));     return s;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) cin >> a[u][i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++) cin >> p[i];     cout << foo(u, true);   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   int n, l, w, x, pn;   vector<int> pos, neg;   int cal(long long a, int b) {     if (b == 0) return (a > 0 ? INT_MAX : -INT_MAX);     if (a < 0) {       if (a % b != 0) return (a / b - 1);     }     return a / b;   }   int main() {     ios::sync_with_stdio(false);     scanf( %d%d%d , &n, &l, &w);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &pn);       if (pn == -1)         neg.push_back(x);       else         pos.push_back(x);     }     sort(neg.begin(), neg.end());     sort(pos.begin(), pos.end());     for (int i = 0; i < neg.size(); i++) {       int v = neg[i];       auto now = lower_bound(pos.begin(), pos.end(), -v - l);       int max1 = cal((long long)(v + l) * (w + 1) - 1, w - 1);       int max2 = cal((long long)(v + l) * (w - 1) - 1, w + 1);       ans += (upper_bound(pos.begin(), now, max1) - pos.begin()) +              (upper_bound(now, pos.end(), min(max2, v)) - now);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> mp;   set<int> s;   int m;   pair<int, int> p[100001];   long long ans;   const long long md = 1e9 + 9;   int up[3][2] = {-1, 1, 0, 1, 1, 1};   int dwn[3][2] = {-1, -1, 0, -1, 1, -1};   int cnt(int ind) {     int res = 0;     int x = p[ind].first, y = p[ind].second;     for (int i = 0; i < 3; i++) {       int xx = x + dwn[i][0], yy = y + dwn[i][1];       if (mp.find(make_pair(xx, yy)) != mp.end()) res++;     }     return res;   }   bool chk(int ind) {     int x = p[ind].first, y = p[ind].second;     for (int i = 0; i < 3; i++) {       int xx = x + up[i][0], yy = y + up[i][1];       if (mp.find(make_pair(xx, yy)) != mp.end()) {         int d = mp[make_pair(xx, yy)];         if (cnt(d) <= 1) {           return false;         }       }     }     return true;   }   void work(int ind) {     ans = (ans * (long long)m % md + ind) % md;     int x = p[ind].first, y = p[ind].second;     mp.erase(make_pair(x, y));     for (int i = 0; i < 3; i++) {       int xx = x + dwn[i][0], yy = y + dwn[i][1];       if (mp.find(make_pair(xx, yy)) != mp.end()) {         int d = mp[make_pair(xx, yy)];         if (chk(d)) {           s.insert(d);         }       }     }   }   void mx() {     set<int>::iterator it;     int x;     while (!s.empty()) {       it = s.end();       it--;       if (chk(*it)) {         x = *it;         s.erase(it);         break;       }       s.erase(it);     }     work(x);   }   void mn() {     set<int>::iterator it;     int x;     while (!s.empty()) {       it = s.begin();       if (chk(*it)) {         x = *it;         s.erase(it);         break;       }       s.erase(it);     }     work(x);   }   int main() {     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &p[i].first, &p[i].second);       mp[make_pair(p[i].first, p[i].second)] = i;       s.insert(i);     }     for (int i = 0; i < m; i++) {       if (i & 1)         mn();       else         mx();     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 50050;   const long long bign = 55000;   long long n, m;   long long tmp[bign], judge[bign];   long long ans, head[maxn], sz[maxn], maxp[maxn];   long long dis[bign], size;   long long q[bign], targetnum;   long long rt, tot, vis[maxn];   struct edge {     long long next, to, dis;   } e[maxn * 2];   inline void addedge(long long next, long long to, long long dis) {     e[++size].to = to;     e[size].dis = dis;     e[size].next = head[next];     head[next] = size;   }   void getzx(long long t, long long fat) {     long long i, j;     maxp[t] = sz[t] = 1;     for (i = head[t]; i; i = e[i].next) {       j = e[i].to;       if (j == fat || vis[j]) continue;       getzx(j, t);       sz[t] += sz[j];       maxp[t] = max(maxp[t], sz[j]);     }     maxp[t] = max(maxp[t], tot - sz[t]);     if (maxp[t] < maxp[rt]) rt = t;   }   inline void getdis(long long t, long long fat) {     long long i, j, k;     tmp[++tmp[0]] = dis[t];     for (i = head[t]; i; i = e[i].next) {       j = e[i].to;       k = e[i].dis;       if (j == fat || vis[j]) continue;       dis[j] = dis[t] + k;       getdis(j, t);     }   }   inline void calc(long long t) {     long long i, j, k, l, p = 0;     for (i = head[t]; i; i = e[i].next) {       j = e[i].to;       k = e[i].dis;       if (vis[j]) continue;       dis[j] = k;       tmp[0] = 0;       getdis(j, t);       for (k = tmp[0]; k; k--)         if (targetnum >= tmp[k]) ans += judge[targetnum - tmp[k]];       for (k = tmp[0]; k; k--) {         q[++p] = tmp[k];         judge[tmp[k]]++;       }     }     for (k = p; k; k--) judge[k] = 0;   }   inline void solve(long long t) {     long long i, j;     vis[t] = judge[0] = 1;     calc(t);     for (i = head[t]; i; i = e[i].next) {       j = e[i].to;       if (vis[j]) continue;       tot = sz[j];       maxp[rt = 0] = 0x3f3f3f3f;       getzx(j, 0);       solve(rt);     }   }   signed main() {     ios::sync_with_stdio(false);     register long long i, j;     cin >> n >> targetnum;     long long t1, t2;     for (i = 1; i < n; i++) {       cin >> t1 >> t2;       addedge(t1, t2, 1);       addedge(t2, t1, 1);     }     maxp[rt = 0] = 0x3f3f3f3f;     tot = n;     getzx(1, 0);     solve(rt);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 12, mod = 1e9 + 7;   long long dp[maxn][2][maxn];   int num[maxn];   long long dfs(int pos, bool bnd, int ned) {     if (ned < 0) return 0;     if (pos < 0) return ned == 0;     long long& ndp = dp[pos][bnd][ned];     if (~ndp) return ndp;     ndp = 0;     int bound = bnd ? num[pos] : 9;     for (int i = 0; i <= bound; i++)       ndp += dfs(pos - 1, bnd && i == bound, ned - (i == 4 || i == 7));     return ndp;   }   long long cnt[maxn];   int init(long long x) {     int len = 0;     while (x) {       num[len++] = x % 10;       x /= 10;     }     memset(dp, -1, sizeof(dp));     for (int i = len; i >= 0; i--) {       cnt[i] = dfs(len - 1, true, i);     }     cnt[0]--;     return len;   }   long long ans;   void dfs(int st, long long v, int len, int adder) {     if (st == 7) {       for (int i = adder + 1; i <= len; i++) {         (ans += v * cnt[i] % mod) %= mod;       }       return;     }     if (adder >= len) return;     for (int i = 0; i <= len; i++) {       if (cnt[i] == 0) continue;       long long mid = v * cnt[i] % mod;       cnt[i]--;       dfs(st + 1, mid, len, adder + i);       cnt[i]++;     }   }   int main() {     long long n;     scanf( %I64d , &n);     int len = init(n);     ans = 0;     dfs(1, 1, len, 0);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100][100];   bool dp[100][100][1000];   bool W[100][100][1000];   int main() {     int N;     int M;     int K;     scanf( %d %d %d , &N, &M, &K);     K++;     char ch[101];     for (int n = 0; n < N; n++) {       scanf( %s , ch);       for (int m = 0; m < M; m++) {         arr[n][m] = ch[m] -  0 ;       }     }     memset(dp, false, sizeof(dp));     for (int m = 0; m < M; m++) {       dp[N - 1][m][arr[N - 1][m]] = true;     }     for (int n = N - 2; n >= 0; n--) {       for (int m = 0; m < M; m++) {         int y[] = {n + 1, n + 1};         int x[] = {m - 1, m + 1};         for (int pos = 0; pos < 2; pos++) {           int Y = y[pos];           int X = x[pos];           if (Y >= 0 && Y < N && X >= 0 && X < M) {             for (int k = 0; k < 1000; k++) {               if (dp[Y][X][k]) {                 dp[n][m][k + arr[n][m]] = true;                 W[n][m][k + arr[n][m]] = pos;               }             }           }         }       }     }     int sol = -1;     int pos = -1;     for (int k = 0; k < 1000; k += K) {       for (int m = 0; m < M; m++) {         if (dp[0][m][k]) {           sol = k;           pos = m;         }       }     }     printf( %d n , sol);     if (sol != -1) {       int help = sol;       stack<int> st;       for (int n = 0; n < N - 1; n++) {         st.push(W[n][pos][help]);         if (W[n][pos][help] == 0) {           help -= arr[n][pos];           pos--;         } else {           help -= arr[n][pos];           pos++;         }       }       printf( %d n , pos + 1);       while (!st.empty()) {         if (st.top() == 0) {           printf( R );         } else {           printf( L );         }         st.pop();       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long len;   string a, b;   const long long mo = 1000000007;   long long good[200001], bad[200001];   int x, y, n;   int main() {     cin >> a >> b >> n;     if (a.length() != b.length()) {       cout << 0;       return 0;     }     len = a.length();     bool f;     for (int i = 0; i < len; i++) {       f = false;       for (int j = 0; j < len; j++) {         if (b[j] != b[(j + i) % len]) {           f = true;           break;         }       }       if (f == false) {         x++;       } else {         y++;       }     }     if (a == b) {       good[0] = 1;       bad[0] = 0;     } else {       good[0] = 0;       bad[0] = 1;     }     f = false;     b = b + b;     bool p;     for (int i = 0; i < len; i++) {       p = false;       for (int j = 0; j < len; j++) {         if (b[j + i] != a[j]) {           p = true;           break;         }       }       if (p == false) {         f = true;         break;       }     }     if (f == false) {       cout << 0;       return 0;     }     for (int i = 1; i <= n; i++) {       good[i] =           ((good[i - 1] % mo) * ((x - 1) % mo) + (bad[i - 1] * x) % mo) % mo;       bad[i] =           ((good[i - 1] % mo) * (y % mo) + (bad[i - 1] % mo) * ((y - 1) % mo)) %           mo;     }     for (int i = 1; i <= n; i++) {     }     cout << good[n] % mo;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   unordered_map<bitset<maxn>, int> ma, flag;   bitset<maxn> s[35];   int t1, t2;   void dfs1(bitset<maxn> z, int cost, int pos) {     if (pos > t1 + t2) {       if (flag[z] == 0)         ma[z] = cost;       else         ma[z] = min(ma[z], cost);       flag[z] = 1;       return;     }     dfs1(z ^ s[pos], cost + 1, pos + 1);     dfs1(z, cost, pos + 1);   }   int dfs2(bitset<maxn> z, int cost, int pos) {     int res = 1e9;     if (flag[z] != 0) res = cost + ma[z];     if (pos <= t1) {       res = min(res, dfs2(z ^ s[pos], cost + 1, pos + 1));       res = min(res, dfs2(z, cost, pos + 1));     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, d;     cin >> n >> m >> d;     t1 = m / 3;     t2 = m - t1;     for (int i = 1; i <= m; i++) {       int cnt;       cin >> cnt;       for (int j = 1; j <= cnt; j++) {         int x;         cin >> x;         s[i][x] = 1;       }     }     bitset<maxn> tmp;     dfs1(tmp, 0, t1 + 1);     while (d--) {       int cnt;       cin >> cnt;       bitset<maxn> q;       for (int i = 1; i <= cnt; i++) {         int x;         cin >> x;         q[x] = 1;       }       int ans = dfs2(q, 0, 1);       if (ans == 1e9)         cout << -1 <<   n ;       else         cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 3e3 + 4;   struct Node {     int la, nx;   } nodes[maxn];   int X[maxn], Y[maxn];   std::vector<int> yp[maxn];   int R, C, N, K;   int ordX[maxn], ord[maxn];   int ans[maxn], xans = 0;   inline void update(int x) {     int c = x;     for (int k = 1; k < K && c; ++k) c = nodes[c].nx;     xans -= ans[x];     if (!nodes[x].la)       ans[x] = X[c] * (R + 1 - X[x]);     else       ans[x] = X[c] * (X[nodes[x].la] - X[x]);     xans += ans[x];   }   int main() {     cin >> R >> C >> N >> K;     for (int i = 1; i <= N; ++i) {       cin >> X[i] >> Y[i];       yp[Y[i]].push_back(i);     }     iota(ordX + 1, ordX + N + 1, 1);     sort(ordX + 1, ordX + N + 1, [&](int a, int b) { return X[a] > X[b]; });     long long rans = 0;     for (int ups = 1; ups <= C; ++ups) {       xans = 0;       memset(ans, 0, sizeof(ans));       int cn = 0;       for (int i = 1; i <= N; ++i) {         if (Y[ordX[i]] >= ups) ord[++cn] = ordX[i];       }       memset(nodes, 0, sizeof(nodes));       for (int i = 1; i <= cn; ++i) {         nodes[ord[i]].la = ord[i - 1];         nodes[ord[i - 1]].nx = ord[i];       }       for (int i = 1; i <= cn; ++i) update(ord[i]);       rans += xans;       for (int i = C; i > ups; --i) {         for (int j : yp[i]) {           nodes[nodes[j].la].nx = nodes[j].nx;           nodes[nodes[j].nx].la = nodes[j].la;         }         for (int j : yp[i]) {           for (int k = 1, c = nodes[j].la; k < K && c; ++k, c = nodes[c].la)             update(c);           if (nodes[j].nx) update(nodes[j].nx);           xans -= ans[j];         }         rans += xans;       }     }     cout << rans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:247474112 )   #pragma GCC optimize( Ofast )   using namespace std;   string ans[2] = { Bob ,  Alice };   void solve() {     long long n, k;     cin >> n >> k;     if (k % 3 != 0) {       if (n % 3)         cout << ans[1];       else         cout << ans[0];       return;     }     long long per_cycle = (k / 3 - 1) * 3 + 4;     n %= per_cycle;     if (n == 0) n = per_cycle;     if (n <= (k / 3 - 1) * 3) {       if (n % 3)         cout << ans[1];       else         cout << ans[0];     } else {       n -= (k / 3 - 1) * 3;       if (n != 4)         cout << ans[1];       else         cout << ans[0];     }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 0; i < n - 2; i++) {       if (a[i] == a[i + 1] && a[i] == a[i + 2]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES  << endl;     vector<int> v1, v2;     v1.push_back(a[0]);     for (int i = 1; i < n; i++) {       if (a[i] != a[i - 1])         v1.push_back(a[i]);       else         v2.push_back(a[i]);     }     int p = v1.size();     int r = v2.size();     cout << p << endl;     for (int i = 0; i < p; i++) {       cout << v1[i] <<    ;     }     cout << endl;     cout << r << endl;     for (int i = r - 1; i >= 0; i--) {       cout << v2[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   int maxt[5210][5210];   int a[5210][5210];   char str[5210];   int getn(char ch) {     if (ch >=  0  && ch <=  9 ) {       return ch -  0 ;     } else {       return 10 + ch -  A ;     }   }   int main() {     scanf( %d , &n);     memset(maxt, 0, sizeof(maxt));     for (int i = 1; i <= n; i++) {       scanf( %s , str + 1);       int In = 0, len = strlen(str + 1);       for (int j = len; j >= 1; j--) {         int N = getn(str[j]);         int Jn = 0;         while (N) {           a[i][n - In - Jn] = N % 2;           N /= 2;           Jn++;         }         for (; Jn < 4; Jn++) {           if (n - In - Jn == 0) {             break;           }           a[i][n - In - Jn] = 0;         }         In += Jn;       }       for (int j = n - In; j >= 1; j--) {         a[i][j] = 0;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         maxt[i][j] =             a[i][j] + maxt[i - 1][j] + maxt[i][j - 1] - maxt[i - 1][j - 1];       }     }     for (int I = n; I >= 1; I--) {       if (n % I == 0) {         int flag = 1;         for (int i = 1; i <= (n / I); i++) {           for (int j = 1; j <= (n / I); j++) {             int cnt = maxt[i * I][j * I] - maxt[(i - 1) * I][j * I] -                       maxt[i * I][(j - 1) * I] + maxt[(i - 1) * I][(j - 1) * I];             if (cnt != I * I * a[i * I][j * I]) {               flag = 0;               break;             }           }           if (!flag) {             break;           }         }         if (flag) {           printf( %d n , I);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   int n, k, mn, mx, ans = INF;   int a[8] = {0, 1, 2, 3, 4, 5, 6, 7};   char s[8][10];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> s[i];     int num;     do {       mn = 1e9;       mx = 0;       for (int i = 0; i < n; i++) {         num = 0;         for (int j = 0; j < k; j++) num = num * 10 + (s[i][a[j]] -  0 );         if (mn > num) mn = num;         if (mx < num) mx = num;       }       if (mx - mn < ans) ans = mx - mn;     } while (next_permutation(a, a + k));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 4;   long long int a[N][20], pre[N][20], ans;   struct node {     node *left, *right;     long long int cnt;     node() {       left = NULL;       right = NULL;       cnt = 0;     }   };   struct trie {     node *x;   };   void insert(node *t, long long int x) {     for (long long int i = 31; i >= 0; i--) {       if (x & (1 << i)) {         if (t->right == NULL) t->right = new node();         t = t->right;         t->cnt++;       } else {         if (t->left == NULL) t->left = new node();         t = t->left;         t->cnt++;       }     }   }   void del(node *t, long long int x) {     for (long long int i = 31; i >= 0; i--) {       if (x & (1 << i)) {         t = t->right;         t->cnt--;       } else {         t = t->left;         t->cnt--;       }     }   }   long long int query(node *t, long long int x) {     long long int ret = 0;     for (long long int i = 31; i >= 0; i--) {       if (x & (1 << i)) {         if (t->left && t->left->cnt != 0) {           ret |= (1 << i);           t = t->left;         } else           t = t->right;       } else {         if (t->right && t->right->cnt != 0) {           ret |= (1 << i);           t = t->right;         } else           t = t->left;       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     trie t;     t.x = new node();     long long int n;     cin >> n;     insert(t.x, 0);     for (long long int i = 1; i <= n; i++) {       char ch;       cin >> ch;       long long int x;       cin >> x;       if (ch ==  + ) insert(t.x, x);       if (ch ==  - ) del(t.x, x);       if (ch ==  ? ) cout << query(t.x, x) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100004;   long long a[N], b[N];   int n, p = 0;   long long fun(int n) {     long long ans = 0, sum = 0;     for (int i = 1; i <= n; i++) {       sum += b[i];       if (sum < 0) sum = 0;       ans = max(ans, sum);     }     return ans;   }   int main() {     long long ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i < n; i++)       a[i] = ((a[i + 1] - a[i]) > 0 ? (a[i + 1] - a[i]) : -(a[i + 1] - a[i]));     --n;     for (int i = 1; i <= n; i++) b[i] = i & 1 ? a[i] : -a[i];     ans = fun(n);     for (int i = 2; i <= n; i++) b[++p] = i & 1 ? -a[i] : a[i];     ans = max(ans, fun(p));     printf( %lld n , ans);   }