malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[5000], a[5000];     char b[] =  bear ;     int count = 0, j = 0;     scanf( %s , &s);     int i = 0;     int n = strlen(s);     printf( %s , a);     for (i = 0; i < n; i++) {       for (j = i; j < n; j++) {         if (s[j] ==  b  && s[j + 1] ==  e  && s[j + 2] ==  a  &&             s[j + 3] ==  r ) {           count = count + n - j - 3;           count = count + j - i;           count = count + (n - j - 4) * (j - i);           i = j + 1;         }       }     }     printf( %d , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   bool odd(ll num) { return ((num & 1) == 1); }   bool even(ll num) { return ((num & 1) == 0); }   ll sum(ll n) { return ((n * (n + 1)) / 2); }   ll ceil(ll a, ll b) { return ((a + (b - 1)) / b); }   void InputOutput() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   ll calculation(vector<ll> &v, ll k) {     ll dis, cnt, len, index;     dis = cnt = 0;     len = (ll)v.size();     len -= k;     index = len - 1;     for (ll i = len - 1; i >= 0; i--) {       cnt++;       if (cnt == k) {         dis += (v[index] * 2);         cnt = 0;         index = i - 1;       }     }     if (cnt) dis += (v[index] * 2);     return dis;   }   void solve() {     ll n, k;     cin >> n >> k;     vector<ll> pos, neg;     ll temp, dis;     for (ll i = 0; i < n; i++) {       cin >> temp;       if (temp < 0)         neg.push_back(abs(temp));       else if (temp > 0)         pos.push_back(temp);     }     if (pos.empty() and neg.empty()) {       cout << 0 <<   n ;       return;     }     sort(pos.begin(), pos.end());     sort(neg.begin(), neg.end());     dis = 0;     dis += calculation(pos, k);     dis += calculation(neg, k);     if (pos.empty())       dis += neg.back();     else if (neg.empty())       dis += pos.back();     else {       if (pos.back() < neg.back()) {         dis += (pos.back() * 2);         dis += neg.back();       } else {         dis += (neg.back() * 2);         dis += pos.back();       }     }     cout << dis <<   n ;   }   int main() {     InputOutput();     int t = 1;     cin >> t;     for (int test_case = 1; test_case <= t; test_case++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m, i, j, b = 0;     scanf( %d %d , &n, &m);     int pass[n];     int finger[m];     int print[m];     for (i = 0; i < n; i++) {       scanf( %d , &pass[i]);     }     for (i = 0; i < m; i++) {       scanf( %d , &finger[i]);     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (pass[i] == finger[j]) {           print[b] = pass[i];           b++;         }       }     }     for (i = 0; i < b; i++) {       printf( %d  , print[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_map<string, vector<string> > m;   set<string> q;   string SS(char C) {     string p =   ;     p += C;     return p;   }   void dfs(string s, long n) {     if (n == 0) {       q.insert(s);       return;     }     for (auto i : m[SS(s[0])]) dfs(i + s.substr(1, s.size() - 1), n - 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long n, t;     cin >> n >> t;     string s, p;     for (long i = long(0); i < long(t); i++) {       cin >> s >> p;       m[p].push_back(s);     }     for (auto i : m[ a ]) dfs(i, n - 2);     cout << q.size();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3700, maxd = 1850, mod = 998244353;   int h, w, tr[maxn], tc[maxn], x, y, n;   vector<int> rs, cs;   long long f[maxd], c[maxn][maxn], dpr[maxn][maxd], dpc[maxn][maxd], ans;   long long C(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return c[a][b];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     f[0] = 1;     for (int i = 1; i < maxd; i++) f[i] = (f[i - 1] * i) % mod;     for (int i = 0; i < maxn; i++) c[i][0] = 1;     for (int i = 1; i < maxn; i++) {       for (int j = 1; j < maxn; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     }     cin >> h >> w >> n;     for (int i = 0; i < 2 * n; i++) {       cin >> x >> y;       x--;       y--;       tr[x]++;       tc[y]++;     }     dpr[0][0] = dpc[0][0] = 1;     for (int i = 0; i < h; i++) {       if (tr[i] == 0) {         for (int j = 0; j <= ((((int)rs.size())) + 1) / 2; j++) {           dpr[(((int)rs.size())) + 1][j] = dpr[(((int)rs.size()))][j];           if (!rs.empty() && rs.back() == i - 1 && j > 0) {             dpr[(((int)rs.size())) + 1][j] += dpr[(((int)rs.size())) - 1][j - 1];             dpr[(((int)rs.size())) + 1][j] %= mod;           }         }         rs.push_back(i);       }     }     for (int i = 0; i < w; i++) {       if (tc[i] == 0) {         for (int j = 0; j <= ((((int)cs.size())) + 1) / 2; j++) {           dpc[(((int)cs.size())) + 1][j] = dpc[(((int)cs.size()))][j];           if (!cs.empty() && cs.back() == i - 1 && j > 0) {             dpc[(((int)cs.size())) + 1][j] += dpc[(((int)cs.size())) - 1][j - 1];             dpc[(((int)cs.size())) + 1][j] %= mod;           }         }         cs.push_back(i);       }     }     for (int i = 0; i <= (((int)rs.size())) / 2; i++) {       for (int j = 0; j <= (((int)cs.size())) / 2; j++) {         ans +=             ((((dpr[(((int)rs.size()))][i] * dpc[(((int)cs.size()))][j]) % mod) *               ((C((((int)rs.size())) - 2 * i, j) *                 C((((int)cs.size())) - 2 * j, i)) %                mod)) %              mod) *             ((f[i] * f[j]) % mod);         ans %= mod;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T maxs(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T mins(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long N = (1 << 21);   const long long M = N - 1;   pair<long long, long long> dp[N];   long long solve() {     long long n;     cin >> n;     vector<long long> a(n + 1);     auto add = [&](long long mask, long long j) {       if (dp[mask].first == -1)         dp[mask].first = j;       else if (dp[mask].second == -1) {         dp[mask].second = j;         if (dp[mask].second < dp[mask].first)           swap(dp[mask].first, dp[mask].second);       } else if (dp[mask].second < j) {         dp[mask].first = dp[mask].second;         dp[mask].second = j;       } else if (dp[mask].first < j && j != dp[mask].second) {         dp[mask].first = j;       }     };     for (long long i = 1; i < n + 1; i++) {       cin >> a[i];       add(a[i], i);     }     for (long long i = 0; i < 21; i++) {       for (long long mask = 0; mask < N; mask++) {         if ((mask) & (1 << i)) {           if (dp[mask].first != -1) add(mask ^ (1 << i), dp[mask].first);           if (dp[mask].second != -1) add(mask ^ (1 << i), dp[mask].second);         }       }     }     long long ans = 0;     for (long long i = 1; i < n + 1; i++) {       long long rev_mask = M - a[i];       long long best = 0;       for (long long j = 20; j >= 0; j--) {         if (rev_mask & (1 << j)) {           if (dp[best ^ (1 << j)].second != -1 && dp[best ^ (1 << j)].first > i) {             best ^= (1 << j);           }         }       }       if (i + 2 <= n) maxs(ans, a[i] + best);     }     cout << ans <<   n ;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string a(n,  0 );       string b(n,  0 );       int flag = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  2 ) {           if (flag == 0) {             a[i] =  1 ;             b[i] =  1 ;           } else {             a[i] =  0 ;             b[i] =  2 ;           }         }         if (s[i] ==  1 ) {           if (flag == 0) {             a[i] =  1 ;             flag = 1;           } else {             b[i] =  1 ;           }         }       }       cout << a <<   n ;       cout << b <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6;   const long long MX = -1e7 - 3;   const long long MN = 1e7 + 3;   long long n, m, cnt, ans, x, y, mx = MX, mn = MN, a, b, c, d, T, l, r, k;   float p = 3.14159;   bool bl, bl1;   string str =   , s;   map<char, long long> mp, mp1;   vector<long long> v;   deque<long long> q;   bool used[N];   pair<long long, long long> pr[N];   pair<long long, char> pr1[N];   int main() {     cin >> T;     for (long long i = 0; i < T; i++) {       cin >> n >> x >> a >> b;       if (a > b) {         c = a;         a = b;         b = c;       }       if (a - x >= 1) {         a -= x;         x = 0;       } else {         x -= a - 1;         a = 1;       }       if (b + x <= n) {         b += x;         x = 0;       } else         b = n;       v.push_back(b - a);     }     for (long long i = 0; i < v.size(); i++) cout << v[i] <<   n ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long ts, tf, t;     cin >> ts >> tf >> t;     int n;     cin >> n;     map<long long, int> T;     for (int i = 0; i < n; ++i) {       long long t;       cin >> t;       ++T[t];     }     long long bt = 0, ans = ts + t;     for (const auto &s : T) {       if (ts + t > tf) break;       if (ts < s.first) {         bt = ts;         break;       }       if (s.first > 0) {         long long ta = s.first - 1;         if (ts + t - ta < ans) {           ans = ts + t - ta;           bt = ta;         }       }       ts += t * s.second;     }     if (ts + t <= tf) bt = ts;     cout << bt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 200010, INF = 1e9;   int cnt[MAX];   int n, c, ans = INF;   int mx[MAX], v[MAX];   bool f[MAX];   vector<int> a;   bool ok(int x, int y) {     if (x == 0) return 1;     if (y == 0) return 0;     x -= a[y] * min(cnt[a[y]], x / a[y]);     if (mx[x] > y - 1)       return ok(x, y - 1);     else       return f[x];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> c >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;     }     a.push_back(0);     for (int i = 1; i <= c; i++)       if (cnt[i]) a.push_back(i);     a.push_back(c);     int cur = c;     for (int i = a.size() - 1; i >= 1; i--)       cur -= a[i] * min(cnt[a[i]], cur / a[i]), v[i] = cur;     memset(mx, -1, sizeof mx);     for (int i = 0; i < a.size() - 1; i++) {       for (int j = a[i]; j < a[i + 1]; j++) {         mx[j] = i;         f[j] = ok(j, i);       }     }     for (int i = 0; i < a.size() - 1; i++) {       for (int j = a[i]; j < a[i + 1]; j++) {         if (v[i + 1] >= j && !ok(v[i + 1] - j, i)) ans = min(ans, j);       }     }     if (ans != INF)       cout << ans << endl;     else       cout <<  Greed is good  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       s.insert(x);     }     set<int>::iterator it = s.begin();     int c = 0;     while (it != s.end()) {       if (*it == 0) c++;       it++;     }     cout << s.size() - c << endl;   }
#include <bits/stdc++.h>   inline int read() {     int data = 0, w = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + (ch ^ 48), ch = getchar();     return data * w;   }   const int N(205), LIM(20010), M(20000), INF(0x3f3f3f3f);   struct edge {     int next, to, cap;   } e[N * N * 2];   int n, A[N], not_prime[LIM], head[N], e_num = -1, lev[N], cur[N], S, T;   inline void Add(int from, int to, int cap) {     e[++e_num] = (edge){head[from], to, cap}, head[from] = e_num;     e[++e_num] = (edge){head[to], from, 0}, head[to] = e_num;   }   void Init() {     not_prime[1] = 1;     for (int i = 2; i <= M; i++)       if (!not_prime[i])         for (int j = i * i; j <= M; j += i) not_prime[j] = 1;   }   int bfs() {     std::queue<int> Q;     Q.push(S);     memset(lev, 0, (T + 1) << 2), lev[S] = 1;     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = head[x]; ~i; i = e[i].next) {         int to = e[i].to;         if (!e[i].cap || lev[to]) continue;         lev[to] = lev[x] + 1, Q.push(to);       }     }     return lev[T];   }   int dfs(int x, int f) {     if (x == T || !f) return f;     int ans = 0, cap;     for (int i = head[x]; ~i; i = e[i].next) {       int to = e[i].to;       if (e[i].cap && lev[to] == lev[x] + 1) {         cap = dfs(e[i].to, std::min(f - ans, e[i].cap));         e[i].cap -= cap, e[i ^ 1].cap += cap, ans += cap;         if (ans == f) break;       }     }     if (!ans) lev[x] = 0;     return ans;   }   int Dinic() {     int ans = 0;     while (bfs()) memcpy(cur, head, (T + 1) << 2), ans += dfs(S, INF);     return ans;   }   std::vector<int> cir[N];   int tot, vis[N];   void find(int x) {     if (1 <= x && x <= n) cir[tot].push_back(x);     vis[x] = 1;     for (int i = head[x]; ~i; i = e[i].next)       if (!vis[e[i].to] && e[i | 1].cap == 1) find(e[i].to);   }   int main() {     memset(head, -1, sizeof head);     Init(), n = read(), S = 0, T = n + 1;     int p = 0, q = 0;     for (int i = 1; i <= n; i++) A[i] = read(), ((A[i] & 1) ? ++p : ++q);     if (p != q) return puts( Impossible ), 0;     for (int i = 1; i <= n; i++)       if (A[i] & 1)         for (int j = (Add(S, i, 2), 1); j <= n; j++) {           if (!not_prime[A[i] + A[j]]) Add(i, j, 1);         }       else         Add(i, T, 2);     if (Dinic() != n) return puts( Impossible ), 0;     for (int i = 1; i <= n; i++)       if (!vis[i]) ++tot, find(i);     printf( %d n , tot);     for (int i = 1; i <= tot; i++, puts(  )) {       printf( %lu  , cir[i].size());       for (int j : cir[i]) printf( %d  , j);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> vec(n);     for (int i = 0; i < n; i++) {       cin >> vec[i];     }     if (n == 1) {       if (vec[0] == 15)         cout <<  DOWN  << endl;       else if (vec[0] == 0)         cout <<  UP  << endl;       else         cout <<  -1  << endl;     } else {       if (vec[n - 1] == 0 || (vec[n - 1] > vec[n - 2] && vec[n - 1] != 15))         cout <<  UP  << endl;       else         cout <<  DOWN  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100010], g, cnt;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       scanf( %d , &a[i]), g = g == 0 ? a[i] : gcd(a[i], g), cnt += a[i] & 1;     printf( %d n , cnt > 1 ? 0 : g);     string str, ans;     for (int i = 0; i < n; i++)       for (int j = 1; j <= a[i] / g / 2; j++) str = str + char( a  + i);     for (int i = 0; i < n; i++)       if (a[i] / g & 1) str = str + char(i +  a );     for (int i = n - 1; i >= 0; i--)       for (int j = 1; j <= a[i] / g / 2; j++) str = str + char(i +  a );     while (g--) ans = ans + str, reverse(str.begin(), str.end());     return cout << ans, 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> V;   void dfs(long long x) {     if (x < 1000000000) {       V.push_back(x);       dfs(x * 10 + 4);       dfs(x * 10 + 7);     }   }   int main() {     dfs(0);     V.push_back(INT_MAX);     sort(V.begin(), V.end());     int pl, pr, vl, vr, k;     cin >> pl >> pr >> vl >> vr >> k;     double cnt = 0;     double all = ((vr - vl) + 1.0) * ((pr - pl) + 1.0);     for (int i = 1; i < V.size() - k; i++) {       int hll = V[i - 1] + 1;       int hl = V[i];       int hr = V[(i + k) - 1];       int hrr = V[(i + k)] - 1;       if (pl <= hl && pr >= hll && vl <= hrr && vr >= hr) {         cnt += (min(pr, hl) - max(pl, hll) + 1.0) *                (min(vr, hrr) - max(vl, hr) + 1.0);       }       if (vl <= hl && vr >= hll && pl <= hrr && pr >= hr) {         cnt += (min(vr, hl) - max(vl, hll) + 1.0) *                (min(pr, hrr) - max(pl, hr) + 1.0);         if (k == 1) cnt -= 1.0;       }     }     printf( %.12f , cnt / all);   exit:     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int cnt = 0;     string ans =  1 ;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       while (str.size() && str.back() ==  0 ) str.pop_back(), cnt++;       if (str.size() == 0) {         cout <<  0 ;         exit(0);       }       if (str.size() != 1 || str.back() !=  1 ) ans = str;     }     cout << ans;     for (int i = 0; i < cnt; i++) cout <<  0 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T& x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T& x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 16;   int n, a[maxn], b[maxn][maxn], ex;   bool mark[maxn];   vector<vector<int> > all;   void bt(int s = 0) {     if (s == n) {       for (int i = 0, sum = 0; i < n; i++, sum = 0) {         for (int j = 0; j < n; j++) sum += b[j][i];         if (sum != ex) return;       }       {         int sum = 0;         for (int i = 0; i < n; i++) sum += b[i][i];         if (sum != ex) return;       }       {         int sum = 0;         for (int i = 0; i < n; i++) sum += b[i][n - i - 1];         if (sum != ex) return;       }       for (int i = 0; i < n; i++, cout <<   n )         for (int j = 0; j < n; j++) cout << b[i][j] <<    ;       exit(0);     }     for (auto v : all) {       bool reval = 1;       for (auto x : v)         if (mark[x]) {           reval = 0;           break;         }       if (!reval) continue;       do {         for (int i = 0; i < n; i++) b[s][i] = a[v[i]], mark[v[i]] = 1;         bt(s + 1);         for (int i = 0; i < n; i++) mark[v[i]] = 0;       } while (next_permutation(v.begin(), v.end()));     }   }   int main() {     ios::sync_with_stdio(0), cin.tie();     cin >> n;     for (int i = 0; i < n * n; i++) cin >> a[i], ex += a[i];     ex /= n;     cout << ex <<   n ;     for (int i = 0; i < 1 << n * n; i++)       if (__builtin_popcount(i) == n) {         int sum = 0;         for (int j = 0; j < n * n; j++) sum += (i >> j & 1) * a[j];         if (sum == ex) {           all.push_back({});           for (int j = 0; j < n * n; j++)             if (i >> j & 1) all.back().push_back(j);           sort(all.back().begin(), all.back().end());         }       }     bt();     return 0;   }
#include <bits/stdc++.h>   int main() {     char p[1000001];     int n, m, y2;     int y1 = -1;     long long ans = 1;     scanf( %d %d , &n, &m);     scanf( %s , p);     int plen = strlen(p);     for (int i = 0; i < m; ++i) {       scanf( %d , &y2);       if (-1 == y1) {         n -= plen;       } else if (y2 - y1 < plen) {         if (p[y2 - y1] != p[0]) {           printf( 0 n );           return 0;         }         n -= y2 - y1;       } else {         n -= plen;       }       y1 = y2;     }     for (int i = 0; i < n; ++i) {       ans = ans * 26 % 1000000007;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int tcase;     for (scanf( %d , &tcase); tcase--;) {       long long l, r;       scanf( %lld%lld , &l, &r);       if (l == r) {         printf( %lld n , r);         continue;       }       int p = 63 - __builtin_clzll(l ^ r);       long long temp = 0;       for (int i = 63; i > p; --i)         if (l >> i & 1) temp |= 1LL << i;       long long a = (1LL << p) - 1, b = (1LL << (p + 1)) - 1;       a |= temp, b |= temp;       if (l <= b && b <= r) a = b;       printf( %lld n , a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   struct dsu {     vector<int> par, rnk, size;     int c;     dsu(int n) : par(n + 1), rnk(n + 1, 0), size(n + 1, 1), c(n) {       for (int i = 1; i <= n; ++i) par[i] = i;     }     int find(int i) { return (par[i] == i ? i : (par[i] = find(par[i]))); }     bool same(int i, int j) { return find(i) == find(j); }     int get_size(int i) { return size[find(i)]; }     int count() { return c; }     int merge(int i, int j) {       if ((i = find(i)) == (j = find(j)))         return -1;       else         --c;       if (rnk[i] > rnk[j]) swap(i, j);       par[i] = j;       size[j] += size[i];       if (rnk[i] == rnk[j]) rnk[j]++;       return j;     }   };   const int N = 1e5 + 9;   long long d[N];   int near[N], vis[N];   vector<pair<int, int>> g[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<array<long long, 3>> edges, ed;     for (int i = 1; i <= m; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});       edges.push_back({u, v, w});     }     for (int i = 1; i <= n; i++) {       d[i] = inf;     }     int k;     cin >> k;     set<pair<long long, int>> se;     for (int i = 1; i <= k; i++) {       int u;       cin >> u;       se.insert({0, u});       near[u] = u;       d[u] = 0;     }     while (!se.empty()) {       auto x = *se.begin();       se.erase(se.begin());       int u = x.second;       if (vis[u]) continue;       vis[u] = 1;       for (auto e : g[u]) {         int v = e.first, w = e.second;         if (d[u] + w < d[v]) {           d[v] = d[u] + w;           near[v] = near[u];           se.insert({d[v], v});         }       }     }     for (auto e : edges) {       if (near[e[0]] == near[e[1]]) continue;       ed.push_back({d[e[0]] + d[e[1]] + e[2], near[e[0]], near[e[1]]});     }     sort(ed.begin(), ed.end());     dsu D(n);     long long ans = d[1];     for (auto e : ed) {       int u = e[1], v = e[2];       long long w = e[0];       if (D.same(u, v)) continue;       ans += w;       D.merge(u, v);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool b[31];   struct trie {     trie* nt[2];     int tot;     trie() {       nt[0] = nt[1] = NULL;       tot = 0;     }   };   trie* root = new trie();   void insert(trie* cur, int idx) {     if (idx == -1)       return;     else {       int x = b[idx];       if (cur->nt[x] == NULL) cur->nt[x] = new trie();       cur->nt[x]->tot++;       insert(cur->nt[x], idx - 1);     }   }   void del(trie* cur, int idx) {     if (idx == -1)       return;     else {       int x = b[idx];       del(cur->nt[x], idx - 1);       cur->nt[x]->tot--;       if (cur->nt[x]->tot == 0) cur->nt[x] = NULL;     }   }   int query(trie* cur, int idx) {     if (idx == -1)       return 0;     else {       int x = 1 - b[idx];       int add = 1 << idx;       if (cur->nt[x] == NULL) x = 1 - x, add = 0;       return query(cur->nt[x], idx - 1) + add;     }   }   int main() {     insert(root, 30);     int q;     scanf( %d , &q);     while (q--) {       char s[2];       int x;       scanf( %s%d , s, &x);       for (int i = 0; i <= 30; i++) {         b[i] = x % 2;         x /= 2;       }       if (s[0] ==  + )         insert(root, 30);       else if (s[0] ==  - )         del(root, 30);       else         printf( %d n , query(root, 30));     }   }