malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 150;   const int M = 6e4 + 5;   int n, m;   struct Node {     int a, b;   } s[N];   bool cmp(Node a, Node b) {     if (a.b > 0 && b.b < 0) return 1;     if (a.b < 0 && b.b > 0) return 0;     if (a.b > 0 && b.b > 0) return a.a < b.a;     return a.a + a.b > b.a + b.b;   }   int dp[N][M];   int main() {     cin >> n >> m;     memset(dp, 0, sizeof dp);     for (int i = 1; i <= n; i++) cin >> s[i].a >> s[i].b;     sort(s + 1, s + 1 + n, cmp);     int ans = 0;     dp[0][m] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < M; j++) {         dp[i][j] = max(dp[i][j], dp[i - 1][j]);         if (j - s[i].b >= 0 && j - s[i].b < M && dp[i - 1][j - s[i].b] &&             j - s[i].b >= s[i].a)           dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - s[i].b] + 1);         ans = max(ans, dp[i][j]);       }     }     cout << ans - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans, k, cnt1[200010], cnt2[200010][10];   vector<long long> adj[200010];   long long sub(long long a, long long b) { return (a - b + k) % k; }   void dfs(long long st, long long par, long long depth) {     cnt2[st][depth % k] = 1;     cnt1[st] = 1;     for (int l = 0; l < adj[st].size(); l++) {       long long to = adj[st][l];       if (to != par) {         dfs(to, st, depth + 1);         for (int i = 0; i < k; i++) {           for (int j = 0; j < k; j++) {             long long rem = sub(i + j, 2 * depth);             long long need = sub(k, rem);             ans += need * cnt2[st][i] * cnt2[to][j];           }         }         for (int i = 0; i < k; i++) {           cnt2[st][i] += cnt2[to][i];         }         cnt1[st] += cnt1[to];       }     }     long long sv = cnt1[st];     ans += sv * (n - sv);   }   int main() {     ans = 0;     memset(cnt1, 0, sizeof(cnt1));     ;     memset(cnt2, 0, sizeof(cnt2));     ;     cin >> n >> k;     for (int i = 1; i < n; i++) {       long long a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, -1, 0);     cout << ans / k << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 233;   struct item {     int ini, num;   } t[MAXN];   int vis1[MAXN] = {0}, vis2[MAXN] = {0};   int cg[MAXN] = {0};   int n;   bool cmp1(const item &a, const item &b) { return a.num < b.num; }   bool cmp2(const item &a, const item &b) { return a.ini < b.ini; }   int main() {     int cnt = 1;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &t[i].num);       t[i].ini = i;       if (vis1[t[i].num] == 0 && t[i].num <= n) {         vis2[i] = 1;       }       vis1[t[i].num] = 1;     }     sort(t + 1, t + 1 + n, cmp1);     for (int i = 1; i <= n; i++) {       while (vis1[cnt] != 0) cnt++;       if (vis2[t[i].ini] == 0) {         t[i].num = cnt;         cnt++;       }     }     sort(t + 1, t + 1 + n, cmp2);     for (int i = 1; i <= n; i++) {       printf( %d  , t[i].num);     }   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[3], ans, a, b, c, ma, t;   multiset<int> s;   int main() {     scanf( %d , &n);     for (int i = 0; i < 3; i++) scanf( %d , arr + i);     for (int i = 0; i < n; i++) {       scanf( %d , &t);       s.insert(t);       ma = max(t, ma);     }     sort(arr, arr + 3);     a = arr[0];     b = arr[1];     c = arr[2];     if (a + b + c < ma) return 0 * printf( -1 n );     multiset<int>::iterator now, it = s.upper_bound(b + c);     while (it != s.end()) s.erase(it++), ans++;     it = s.upper_bound(a + c);     while (it != s.end()) {       ans++;       s.erase(it++);       now = s.upper_bound(a);       now--;       if (now != s.end()) s.erase(now);     }     it = s.upper_bound(max(a + b, c));     while (it != s.end()) {       ans++;       s.erase(it++);       now = s.upper_bound(b);       now--;       if (now != s.end()) s.erase(now);     }     if (a + b > c) {       now = it = s.upper_bound(c);       now--;       while (it != s.end()) {         ans++;         s.erase(it++);         if (now != s.end()) s.erase(now--);       }     }     while (!s.empty()) {       ans++;       it = s.end();       it--;       s.erase(it);       if (s.empty()) break;       now = s.upper_bound(b);       now--;       if (now != s.end() && b >= *now) {         s.erase(now);         if (s.empty()) break;         now = s.upper_bound(a);         now--;         if (now != s.end() && a >= *now) s.erase(now);       } else {         now = s.upper_bound(a + b);         now--;         if (now != s.end() && a + b >= *now) s.erase(now);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       set<char> res;       vector<char> ans;       for (int i = 0; i < s.length(); i++) {         if (s[i] == s[i + 1]) {           i++;         } else {           char c = s[i];           res.insert(c);         }       }       for (auto i : res) cout << i;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int x[1010], y[1010], cnt, _cnt;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]);     while (true) {       int cnt = 0;       for (int i = 1; i <= n; i++)         if ((x[i] + y[i]) & 1 == 1) cnt++;       if (cnt >= 1 && cnt <= n - 1) {         cout << cnt << endl;         for (int i = 1; i <= n; i++)           if ((x[i] + y[i]) & 1 == 1) printf( %d  , i);         return 0;       }       if (cnt == n) {         for (int i = 1; i <= n; i++) x[i]--;       }       for (int i = 1; i <= n; i++) {         cnt = (x[i] - y[i]) / 2;         _cnt = (x[i] + y[i]) / 2;         x[i] = cnt;         y[i] = _cnt;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 123;   const long double EPS = 1e-9;   const int MX = 1e9 + 1;   const int inf = 1e9 + 123;   const int MOD = 1e9 + 7;   const int N = 1e5 + 123;   const int dx[] = {0, 0, 1, -1};   const int dy[] = {1, -1, 0, 0};   int n, m;   long long dp[1001], a[13], b[13], c[13], d[13];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> c[0] >> d[0];     for (int i = 1; i <= m; ++i) {       cin >> a[i] >> b[i] >> c[i] >> d[i];     }     for (int i = 1; i <= m; ++i) {       for (int l = n; l >= 0; --l) {         for (int j = 1; j <= a[i] / b[i]; ++j) {           if (l + j * c[i] > n) {             continue;           }           dp[l + j * c[i]] = max(dp[l + j * c[i]], dp[l] + j * d[i]);         }       }     }     for (int l = n; l >= 0; --l) {       for (int j = 1; j <= n / c[0]; ++j) {         if (l + j * c[0] > n) {           continue;         }         dp[l + j * c[0]] = max(dp[l + j * c[0]], dp[l] + d[0] * j);       }     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans = max(ans, dp[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   const double PI = acos(-1.0);   const int EPS = (1e-10);   const int N = 1e5 * 2 + 10;   const int inf = 1e9 * 2 + 10;   const ll INF = 1e18 * 2 + 10;   const int MOD = 1e9 + 7;   int nxt() {     int x;     cin >> x;     return x;   }   int fcmp(double a, double b) {     return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1);   }   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     int mx = 0, p = 0;     for (int i = (1); i <= (n); ++i) {       int k, a;       cin >> k >> a;       mx = max(mx, k);       ll s = 1;       int m = 0;       while (s < a) {         s *= 4;         m++;       }       p = max(p, k + m);     }     if (mx == p) p++;     cout << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   int i, j, n, ans;   int a[N], f[N][300], d[20], sum[N][10];   void init() {     d[1] = 1;     for (i = 2; i <= 9; i++) d[i] = d[i - 1] * 2;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       for (j = 1; j <= 8; j++) sum[i][j] = sum[i - 1][j];       sum[i][a[i]]++;     }   }   void mark(int st, int k, int len, int v, int s) {     for (i = st; i <= n; i++) {       int t = sum[i][k] - sum[st][k];       if (t > len) return;       if (t == len)         if (f[i][s] == -1 || f[i][s] < v) f[i][s] = v;     }   }   int cal(int len) {     int ans = -1;     memset(f, 255, sizeof(f));     f[0][0] = 0;     int i, j, k;     for (i = 0; i <= n; i++)       for (j = 0; j <= d[9] - 1; j++)         if (f[i][j] != -1) {           if (j == d[9] - 1 && f[i][j] > ans) ans = f[i][j];           for (k = 1; k <= 8; k++)             if ((d[k] & j) == 0) {               mark(i, k, len, f[i][j] + len, d[k] + j);               mark(i, k, len + 1, f[i][j] + len + 1, d[k] + j);             }         }     return ans;   }   void work() {     int l = 0, r = n, mid, ans = 0, t;     while (l <= r) {       mid = (l + r) / 2;       t = cal(mid);       if (t != -1)         l = mid + 1, ans = t;       else         r = mid - 1;     }     printf( %d n , ans);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 5;   vector<int> adj[N];   int n, m, eu[N], ev[N], ew[N], a[N], b[N], g[N];   bool dfs1(int u, int t, int w, int p = -1) {     if (u == t) {       return 1;     }     for (int e : adj[u]) {       int v = eu[e] ^ ev[e] ^ u;       if (v == p) {         continue;       }       if (dfs1(v, t, w, u)) {         ew[e] = max(ew[e], w);         return 1;       }     }     return 0;   }   int dfs2(int u, int t, int p = -1) {     if (u == t) {       return 1e9;     }     for (int e : adj[u]) {       int v = eu[e] ^ ev[e] ^ u;       if (v == p) {         continue;       }       int a = dfs2(v, t, u);       if (~a) {         return min(a, ew[e]);       }     }     return -1;   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> eu[i] >> ev[i], eu[i]--, ev[i]--;       adj[eu[i]].push_back(i);       adj[ev[i]].push_back(i);     }     fill(ew + 1, ew + n, 1);     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> g[i], --a[i], --b[i];       dfs1(a[i], b[i], g[i]);     }     for (int i = 0; i < m; i++) {       if (dfs2(a[i], b[i]) ^ g[i]) {         cout <<  -1 ;         exit(0);       }     }     for (int i = 1; i < n; i++) {       cout << ew[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   long long mod(long long n) {     n %= MOD;     if (n < 0)       return n + MOD;     else       return n;   }   long long fp(long long a, long long p) {     long long ans = 1, c = a;     for (long long i = 0; (1ll << i) <= p; ++i) {       if ((p >> i) & 1) ans = mod(ans * c);       c = mod(c * c);     }     return ans;   }   long long dv(long long a, long long b) { return mod(a * fp(b, MOD - 2)); }   const long long N = 2e6 + 7;   long long first[N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     first[0] = 1;     for (long long i = 1; i < N; ++i) first[i] = mod(first[i - 1] * i);     long long n;     cin >> n;     ++n;     long long a = mod(2 * first[2 * n - 1]);     long long b = mod(first[n] * first[n - 1]);     long long ans = mod(dv(a, b) - 1);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long arr[n][n];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) cin >> arr[i][j];     }     long long ans[n];     ans[2] = sqrt(arr[1][2] * arr[2][0] / arr[1][0]);     ans[1] = arr[1][2] / ans[2];     ans[0] = arr[1][0] / ans[1];     for (long long i = 3; i < n; i++) {       ans[i] = arr[i][0] / ans[0];     }     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, p, q, l, b = 0, i, d, m, n, k, sum = 0, t = 1, x = 0, z = 0,                               y = 0;     vector<long long int> v;     cin >> a;     for (int i = 0; i < a; i++) {       cin >> x;       if (x > 0) {         sum = sum + (x - 1);       } else if (x == 0) {         y++;       } else {         p = -x - 1;         sum = sum + p;         z++;       }     }     sum = sum + y;     if (z % 2 == 1 && y == 0) {       sum = sum + 2;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, oo = 1e9 + 10, MOD = 1e9 + 7;   void solve() {     long long a, b;     cin >> a >> b;     if (a > b) {       long long ans = 0;       while (b != a) {         b *= 2;         ans++;         if (b > a) {           cout <<  -1 n ;           return;         }       }       int q = 0, q1 = 0;       if (ans >= 3) {         long long k = ans / 3;         k += ans % 3;         q = ans % 3;         ans = k;         q1 = 1;       }       if (q >= 2 && q1) {         ans -= q / 2;       }       if (!q1) {         ans = (ans + 1) / 2;       }       cout << ans <<   n ;     } else {       if (a == b) {         cout <<  0 n ;         return;       }       long long ans = 0;       while (a != b) {         a *= 2;         ans++;         if (a > b) {           cout <<  -1 n ;           return;         }       }       int q = 0, q1 = 0;       if (ans >= 3) {         long long k = ans / 3;         k += ans % 3;         q = ans % 3;         ans = k;         q1 = 1;       }       if (q >= 2 && q1) {         ans -= q / 2;       }       if (!q1) {         ans = (ans + 1) / 2;       }       cout << ans <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     vector<long long> a(m);     for (int i = 0; i < m; i++) {       cin >> a[i];     }     long long count = 0;     for (int i = 0; i < m - 1; i++) {       if (a[i] > a[i + 1]) {         count++;       }     }     cout << count * n + a[m - 1] - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000007;   const int maxn = 300010;   int vis[maxn], cnt[maxn];   long long sum[maxn];   int mod(int x, int u) {     int ret = 0;     for (int i = 2; i <= u; ++i)       if (vis[i]) {         ret += x % i;       }     return ret;   }   long long cal(int x) {     long long ret = 0, xx = x;     for (int i = 1;; ++i) {       int d = x / (i + 1), u = x / i;       if (u <= 500) {         return ret + mod(x, u);       }       ret += xx * (cnt[u] - cnt[d]) - (sum[u] - sum[d]) * i;     }     return ret;   }   int main() {     static int a[maxn];     static long long p[maxn];     int n, N = 300000;     cin >> n;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i += 400) {       int j = min(n, i + 400);       for (int k = i; k < j; ++k) {         long long ak = a[k];         p[k] = cal(a[k]) + ak * (cnt[N] - cnt[a[k]]);         for (int kk = 0; kk < N; kk += a[k]) {           int rig = min(kk + a[k] - 1, N);           p[k] += (sum[rig] - sum[kk]) - (long long)kk * (cnt[rig] - cnt[kk]);         }         for (int kk = i; kk < k; ++kk) {           p[k] += a[kk] % a[k] + a[k] % a[kk];         }       }       for (int k = i; k < j; ++k) {         vis[a[k]] = 1;       }       for (int k = 1; k <= N; ++k) {         cnt[k] = vis[k] + cnt[k - 1];         sum[k] = vis[k] * k + sum[k - 1];       }     }     long long pp = 0;     for (int i = 0; i < n; ++i) {       pp += p[i];       printf( %lld  , pp);     }     puts(  );     return 0;   }
/*-- ILSH  --*/   #include  bits/stdc++.h    using namespace std;   typedef long long ll;   typedef double ld;   #define pb push_back    #define pop pop_back   #define mp make_pair   #define vii vector < ll >   #define dt cout<< HERE n ;   #define pii pair < ll , ll >   #define vpi vector < pii >   #define fi first   #define se second    #define sz(x) ((ll)x.size())   #define len(x) ((ll)x.length())   void up(vii &v){ for ( ll i=0;i<sz(v);i++) cout<<v[i]<<   ; cout<<  n ;}   const ll inf=1e18+1e17;   const ll mod =1e9+7;   using cd= complex < double > ;      //const ll mod = 998244353;   ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}     ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}   const ll N = 5e3 +5;   bool check(int fx, int fy, int pos, string &s, int x, int y){    int n=len( s);    for ( int i=pos;i<n;i++){     int nx=x, ny=y;     if ( s[i]== R )      nx=x+1;     if ( s[i]== L )      nx=x-1;     if ( s[i]== U )      ny=y+1;     if ( s[i]== D )      ny=y-1;     if ( nx==fx&&ny==fy)      continue;     else{      x=nx;      y=ny;     }    }    if ( x==0&&y==0)     return true;    return false;   }   void solve(){    map< pii , bool > m;       string s;    cin>> s;    int n=len( s);    int x_pos=0,y_pos=0;    for ( int i=0;i<n;i++){     int nx=x_pos, ny=y_pos;     if ( s[i]== R )      nx=x_pos+1;     if ( s[i]== L )      nx=x_pos-1;     if ( s[i]== U )      ny=y_pos+1;     if ( s[i]== D )      ny=y_pos-1;     if ( m[{nx,ny}]==0){      m[{nx, ny}]=1;      if ( check( nx , ny,i,s, x_pos,y_pos)){       cout<<nx<<   <<ny<<  n ;       return;      }     }     x_pos=nx;     y_pos=ny;    }    cout<< 0 0 n ;         }         int main(){    ios_base::sync_with_stdio(false);    cin.tie( NULL);    cout.tie(NULL);    #ifndef ONLINE_JUDGE     freopen ( INPUT.txt  ,  r  , stdin);     freopen ( OUTPUT.txt ,  w  , stdout);    #endif    ll t=1;       cin>>t;    for ( ll i=1;i<=t;i++){     //cout<< Case  <<i<< :  ;        solve();       }   }
#include <bits/stdc++.h>   using namespace std;   const long long int Maxn3 = 1e3 + 10;   const long long int Maxn4 = 1e4 + 10;   const long long int Maxn5 = 1e5 + 10;   const long long int Maxn6 = 1e6 + 10;   const long long int Maxn7 = 1e7 + 10;   const long long int Maxn8 = 1e8 + 10;   const long long int Maxn9 = 1e9 + 10;   const long long int Maxn18 = 1e18 + 10;   const long long int Mod1 = 1e7 + 7;   const long long int Mod2 = 1e9 + 7;   const long long int LLMax = LLONG_MAX;   const long long int LLMin = LLONG_MIN;   const long long int INTMax = INT_MAX;   const long long int INTMin = INT_MIN;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int a, b, n;     cin >> a >> b >> n;     bool mark[n + 1];     for (long long int i = 0; i <= n; i++) mark[i] = 0;     for (long long int i = a; i <= n; i += a) mark[i] = 1;     long long int res = 0;     for (long long int i = b; i <= n; i += b)       if (mark[i]) res++;     return cout << res, 0;   }
#include <bits/stdc++.h>   int main() {     int n, a, sum;     scanf( %d , &n);     int k = 0;     int arr[100];     for (int i = n - 9 * (log10(n) + 1 + 1); i <= n; i++) {       sum = a = i;       while (a != 0) {         sum += a % 10;         a /= 10;       }       if (sum == n) {         arr[k++] = i;       }     }     printf( %d n , k);     for (int i = 0; i < k; i++) {       printf( %d n , arr[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = ((int)5e2) + 5;   vector<string> str;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       str.push_back(s);     }     vector<string> comb = { 12 ,  23 ,  34 ,  31 ,  14 ,  24 };     for (int i = 0; i < 2; i++) {       for (int c = 0; c < 6; c++) {         string first[2];         first[0] = comb[c];         first[1] = comb[c];         reverse(first[1].begin(), first[1].end());         set<char> t = { 1 ,  2 ,  3 ,  4 };         t.erase(comb[c][0]);         t.erase(comb[c][1]);         string sec[2];         sec[0] += (*t.begin());         t.erase(t.begin());         sec[0] += (*t.begin());         sec[1] = sec[0];         reverse(sec[1].begin(), sec[1].end());         vector<string> board;         for (int row = 0; row < n; row++) {           string r;           string* pattern = first;           if (row & 1) pattern = sec;           bool ok = true;           for (int ver = 0; ver < 2; ver++) {             ok = true;             for (int col = 0; col < m; col++) {               r += pattern[ver][col & 1];               if (str[row][col] !=  0  && r[col] != str[row][col]) {                 ok = false;                 break;               }             }             if (ok)               break;             else               r =   ;           }           if (ok) board.push_back(r);         }         if (board.size() == n) {           if (i == 0)             for (int j = 0; j < n; j++) cout << board[j] << endl;           else {             for (int col = 0; col < m; col++) {               string temp;               for (int row = 0; row < n; row++) {                 temp.push_back(board[row][col]);               }               cout << temp << endl;             }           }           return 0;         }       }       vector<string> arr;       for (int col = 0; col < m; col++) {         string temp;         for (int row = 0; row < n; row++) {           temp.push_back(str[row][col]);         }         arr.push_back(temp);       }       str = arr;       swap(n, m);     }     cout <<  0 ;     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a + b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long mul(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a * b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int N = 300000 + 5;   const int L = 30;   const int SUML = 300000 * 30 + 5;   const int E = 2;   int n;   int a[N];   int nodes = 1;   int frec[SUML];   int trie[SUML][E];   void insert(int x) {     int pos = 0;     for (int i = L - 1; i >= 0; i--) {       int nxt = (x >> i) & 1;       if (trie[pos][nxt] == 0) {         trie[pos][nxt] = nodes++;       }       pos = trie[pos][nxt];       frec[pos] += 1;     }   }   void erase(int val) {     int pos = 0;     for (int i = L - 1; i >= 0; i--) {       int nxt = (val >> i) & 1;       pos = trie[pos][nxt];       frec[pos] -= 1;     }   }   int getMin(int x) {     int ans = 0;     int pos = 0;     for (int i = L - 1; i >= 0; i--) {       int have = (x >> i) & 1;       int nxt = have;       if (frec[trie[pos][nxt]] == 0) nxt ^= 1;       ans |= (nxt ^ have) << i;       pos = trie[pos][nxt];     }     return ans;   }   int main() {     scanf( %d , &(n));     for (int i = 1; i <= n; i++) scanf( %d , &(a[i]));     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &(x));       insert(x);     }     for (int i = 1; i <= n; i++) {       int cur = getMin(a[i]);       erase(cur ^ a[i]);       printf( %d%c , cur,    n [i == n]);     }     return 0;   }