malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const double eps = 1e-7;   struct node {     long long first;     node() {}     node(long long first) : first(first) {}     bool operator<(const node& a) const { return first < a.first; }   };   int dx[4] = {-1, 1, 0, 0};   int dy[4] = {0, 0, -1, 1};   const long long N = 6010;   long long mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       long long tmp = 0;       long long ans = 0;       priority_queue<node> q;       for (int i = 1; i <= n * k; i++) {         cin >> tmp;         node tt(tmp);         q.push(tt);       }       int cnt = 0;       if (n & 1) {         for (int i = 1; i <= k; i++) {           for (int j = 1; j <= (n + 1) / 2; j++) {             if (j == (n + 1) / 2) {               ans += q.top().first;               cnt++;             }             q.pop();           }         }       } else {         for (int i = 1; i <= k; i++) {           for (int j = 1; j <= n / 2 + 1; j++) {             if (j == n / 2 + 1) {               ans += q.top().first;               cnt++;             }             q.pop();           }         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int d[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};   int t, n, k;   struct edge {     string name;     int s, win[50];   } a[100];   bool cmp1(edge x, edge y) {     if (x.s != y.s) {       return x.s > y.s;     }     for (int i = 0; i < 50; i++) {       if (x.win[i] != y.win[i]) {         return x.win[i] > y.win[i];       }     }     return false;   }   bool cmp2(edge x, edge y) {     if (x.win[0] != y.win[0]) {       return x.win[0] > y.win[0];     } else {       return cmp1(x, y);     }   }   int main() {     cin >> t;     while (t--) {       cin >> n;       string name;       for (int i = 0; i < n; i++) {         cin >> name;         bool flag = false;         for (int j = 0; j < k; j++) {           if (a[j].name == name) {             if (i < 10) {               a[j].s += d[i];             }             a[j].win[i]++;             flag = true;             break;           }         }         if (flag == false) {           a[k].name = name;           if (i < 10) {             a[k].s = d[i];           }           a[k].win[i]++;           k++;         }       }     }     sort(a, a + k, cmp1);     cout << a[0].name << endl;     sort(a, a + k, cmp2);     cout << a[0].name;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ch[200][200];   int rp[200], cp[200];   int main() {     int n;     while (cin >> n) {       memset(rp, 0, sizeof(rp));       memset(cp, 0, sizeof(cp));       for (int i = 1; i <= n; i++) {         scanf( %s , ch[i] + 1);         for (int j = 1; j <= n; j++)           if (ch[i][j] ==  . ) rp[i] = 1;       }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (ch[j][i] ==  . ) cp[i] = 1;       bool rok, cok;       rok = cok = 0;       int k;       for (k = 1; k <= n; k++)         if (rp[k] == 0) break;       if (k > n) rok = 1;       for (k = 1; k <= n; k++)         if (cp[k] == 0) break;       if (k > n) cok = 1;       if (rok == 0 && cok == 0) {         puts( -1 );         continue;       }       if (rok) {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++)             if (ch[i][j] ==  . ) {               cout << i <<     << j << endl;               break;             }         }       } else {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++)             if (ch[j][i] ==  . ) {               cout << j <<     << i << endl;               break;             }         }       }     }     return 0;   }
#include <bits/stdc++.h>   long n, m, x, y, i, a[1000], z;   double aa, bb, sum;   int main() {     scanf( %ld%ld , &n, &m);     for (i = 1; i <= n; i++) scanf( %ld , &a[i]);     sum = 0;     for (i = 1; i <= m; i++) {       scanf( %ld%ld%ld , &x, &y, &z);       aa = a[x] + a[y];       bb = z;       if (aa / bb > sum) {         sum = aa / bb;       }     }     printf( %0.15lf , sum);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int tests;     cin >> tests;     for (int test = 0; test < tests; ++test) {       int n;       cin >> n;       vector<ll> a(n);       for (int i = 0; i < n; ++i) cin >> a[i];       ll x, y;       int fx, fy;       cin >> x >> fx >> y >> fy;       ll req;       cin >> req;       int lo = 1, hi = n + 1;       for (int i = 0; i < n; ++i) a[i] /= 100;       sort(a.begin(), a.end());       reverse(a.begin(), a.end());       while (lo < hi) {         int mid = (lo + hi) / 2;         vector<ll> c(mid);         for (int i = 0; i < mid; ++i) {           if (i % fx == fx - 1) c[i] += x;           if (i % fy == fy - 1) c[i] += y;         }         sort(c.begin(), c.end());         reverse(c.begin(), c.end());         ll sum = 0;         for (int i = 0; i < mid; ++i) sum += a[i] * c[i];         if (sum >= req)           hi = mid;         else           lo = mid + 1;       }       if (lo == n + 1) lo = -1;       cout << lo <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 100;   vector<int> adj[MAXN], *vec[MAXN];   int col[MAXN], pw[MAXN], goni[MAXN], sz[MAXN];   long long sum[MAXN];   void getsz(int v = 1, int pre = -1) {     sz[v] = 1;     for (auto u : adj[v]) {       if (u != pre) {         getsz(u, v);         sz[v] += sz[u];       }     }   }   void dfs(int v, int pre, bool type) {     int idx = -1;     int bigchild = -1;     for (auto i : adj[v])       if (sz[i] > idx && i != pre) idx = sz[i], bigchild = i;     for (auto i : adj[v])       if (i != bigchild && i != pre) dfs(i, v, 0);     if (bigchild != -1) {       dfs(bigchild, v, 1);       vec[v] = vec[bigchild];       sum[v] = sum[bigchild];       pw[v] = pw[bigchild];     } else       vec[v] = new vector<int>();     vec[v]->push_back(v);     goni[col[v]]++;     if (goni[col[v]] == pw[v])       sum[v] += col[v];     else if (goni[col[v]] > pw[v]) {       sum[v] = col[v];       pw[v] = goni[col[v]];     }     for (auto i : adj[v])       if (i != bigchild && i != pre)         for (auto j : *vec[i]) {           goni[col[j]]++;           vec[v]->push_back(j);           if (goni[col[j]] == pw[v])             sum[v] += col[j];           else if (goni[col[j]] > pw[v]) {             sum[v] = col[j];             pw[v] = goni[col[j]];           }         }     if (!type)       for (auto u : *vec[v]) goni[col[u]]--;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> col[i];     for (int i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     getsz();     dfs(1, -1, 0);     for (int i = 1; i <= n; ++i) cout << sum[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, k, tmp;     vector<long long> ans;     vector<int> vec;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n * k; i++) {         cin >> tmp;         vec.push_back(tmp);       }       int med;       if (n % 2 == 0)         med = n / 2;       else         med = n / 2 + 1;       long long medSum = 0;       int pos = vec.size() - (n - med) - 1;       for (int i = 0; i < k; i++) {         medSum += (long long)vec[pos];         pos -= (n - med + 1);       }       ans.push_back(medSum);       vec.clear();     }     for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, k;   void solve() {     scanf( %d%d , &n, &k);     if (n < k) {       printf( NO n );       return;     }     if ((n - (k - 1)) % 2 == 1) {       printf( YES n );       for (int i = 1; i <= k - 1; ++i) printf( 1  );       printf( %d n , n - (k - 1));     } else if ((n - (k - 1) * 2) > 0 && (n - (k - 1) * 2) % 2 == 0) {       printf( YES n );       for (int i = 1; i <= k - 1; ++i) printf( 2  );       printf( %d n , n - (k - 1) * 2);     } else       printf( NO n );   }   int main() {     scanf( %d , &t);     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, Q;   const int md = 998244353;   const int maxn = 200010;   int t[4 * maxn], tmul[4 * maxn], tadd[4 * maxn];   inline int mod(long long x) { return (x % md + md) % md; }   void build(int v, int vl, int vr) {     tmul[v] = 1, tadd[v] = 0;     if (vl == vr) return;     int vm = (vl + vr) >> 1;     build(2 * v, vl, vm);     build(2 * v + 1, vm + 1, vr);   }   void push(int v, int vl, int vr) {     t[v] = mod(mod(1ll * tmul[v] * t[v]) + mod(1ll * tadd[v] * (vr - vl + 1)));     if (vl != vr) {       tmul[2 * v] = mod(1ll * tmul[2 * v] * tmul[v]);       tmul[2 * v + 1] = mod(1ll * tmul[2 * v + 1] * tmul[v]);       tadd[2 * v] = mod(1ll * tadd[2 * v] * tmul[v] + tadd[v]);       tadd[2 * v + 1] = mod(1ll * tadd[2 * v + 1] * tmul[v] + tadd[v]);     }     tmul[v] = 1;     tadd[v] = 0;   }   void update(int v, int vl, int vr, int l, int r, int m, int a) {     push(v, vl, vr);     if (l > vr || r < vl) return;     if (l <= vl && vr <= r) {       tmul[v] = m;       tadd[v] = a;       push(v, vl, vr);       return;     }     int vm = (vl + vr) >> 1;     update(2 * v, vl, vm, l, r, m, a);     update(2 * v + 1, vm + 1, vr, l, r, m, a);     t[v] = (t[2 * v] + t[2 * v + 1]) % md;   }   int getsum(int v, int vl, int vr, int l, int r) {     push(v, vl, vr);     if (l > vr || r < vl) return 0;     if (l <= vl && vr <= r) return t[v];     int vm = (vl + vr) >> 1;     return mod(getsum(2 * v, vl, vm, l, r) + getsum(2 * v + 1, vm + 1, vr, l, r));   }   set<pair<int, int>> q[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> Q;     build(1, 0, n - 1);     for (int i = 0; i < Q; i++) {       int t, l, r;       cin >> t >> l >> r;       --l, --r;       if (t == 1) {         int x;         cin >> x;         auto itl = q[x].lower_bound({l + 1, 0});         if (itl != q[x].begin()) {           --itl;           if (itl->second >= l) {             int ll = itl->first, rr = itl->second;             q[x].erase(itl);             if (ll <= l - 1) q[x].insert({ll, l - 1});             q[x].insert({l, rr});           }         }         auto itr = q[x].lower_bound({r + 1, 0});         if (itr != q[x].begin()) {           --itr;           if (itr->second >= r) {             int ll = itr->first, rr = itr->second;             q[x].erase(itr);             if (r + 1 <= rr) q[x].insert({r + 1, rr});             q[x].insert({ll, r});           }         }         int prev = l;         while (true) {           auto it = q[x].lower_bound({l, 0});           if (it == q[x].end() || it->first > r) break;           int ll = it->first, rr = it->second;           q[x].erase(it);           if (prev <= ll - 1) update(1, 0, n - 1, prev, ll - 1, 1, 1);           update(1, 0, n - 1, ll, rr, 2, 0);           prev = rr + 1;         }         if (prev <= r) update(1, 0, n - 1, prev, r, 1, 1);         q[x].insert({l, r});       } else {         cout << getsum(1, 0, n - 1, l, r) <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int M = 1e9 + 7;   int sum_digit(int x) {     int sum = 0;     while (x > 0) {       sum += x % 10;       x /= 10;     }     return sum;   }   int reverse_num(int n) {     int tmp = n, ans = 0, r;     while (tmp > 0) {       r = tmp % 10;       ans = ans * 10 + r;       tmp /= 10;     }     return ans;   }   long long int factorial(long long int n) {     long long int i, ans = 1;     for (i = n; i > 1; i--) {       ans *= i;     }     return ans;   }   long long int gcd(long long int num1, long long int num2) {     long long int a, b, r;     a = num1;     b = num2;     r = a % b;     while (r > 0) {       a = b;       b = r;       r = a % b;     }     return b;   }   long long int lcm(long long int num1, long long int num2) {     return (num1 * num2) / gcd(num1, num2);   }   bool prime(long long int n) {     if (n < 2) return false;     for (long long int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return false;     }     return true;   }   bool vowel(char ch) {     ch = tolower(ch);     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u )       return true;     return false;   }   void solve() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double r = d / 2;     double v_in = 2 * acos(0) * r * r * h;     double L = 0, R = 1e4 + 10;     double ans = 0;     while (L < R) {       double t = L + (R - L) / 2;       double dif = (v_in + 2 * acos(0) * r * r * e * t) - v * t;       if (abs(dif) < 1e-4) {         ans = t;         break;       }       if (dif < 0)         R = t;       else         L = t;     }     if (ans != 0) {       cout <<  YES n ;       cout << setprecision(12) << fixed << ans << endl;     } else       cout <<  NO n ;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> adjlist[1000050], ans;   bool done[1000050], use[1000050];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adjlist[a].push_back(b);     }     for (int i = 1; i <= n; i++) {       if (!done[i]) {         use[i] = true;         for (auto j : adjlist[i]) done[j] = true;       }     }     memset(done, false, sizeof done);     for (int i = n; i >= 1; i--) {       if (use[i] and !done[i]) {         ans.push_back(i);         done[i] = true;         for (auto j : adjlist[i]) done[j] = true;       }     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, inf = 1e17, N = 1e6 + 10;   bool vowel(char che) {     if (che ==  A  || che ==  E  || che ==  I  || che ==  O  || che ==  U  ||         che ==  Y ) {       return true;     } else {       return false;     }   }   long long pw(long long a, long long b) {     long long ans = 1;     while (b) {       if (b % 2 == 1) {         ans = 1ll * ans * a;         ans %= mod;       }       b /= 2;       a = 1ll * a * a % mod;       a %= mod;     }     return ans % mod;   }   bool mark[N], ok[N], h;   char o;   pair<long long, long long> p;   vector<long long> vt[N], vec, jav, vs;   string s, s1;   int64_t a[N], b[N], c[N], d, dp, t, n, m, k, f, ans1, sum, ps;   int64_t fuc[N];   int64_t ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie();     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] %= mod;     }     fuc[0] = 1;     for (int i = 1; i <= n; i++) {       fuc[i] = 1ll * fuc[i - 1] * i;       fuc[i] %= mod;     }     sort(a, a + n);     f = 1;     a[n] = -25;     ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == a[i - 1])         f++;       else {         if (i != n) {           f %= mod;           k = fuc[n] * pw((n - i + f), mod - 2);           k %= mod;           k *= f;           k %= mod;           ans += 1ll * k * a[i - 1];         }         ans %= mod;         f = 1;       }     }     cout << (ans + mod) % mod << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, M;     cin >> N >> M;     set<long long> x_t;     set<long long> y_t;     vector<long long> ans;     for (long long i = 0; i < M; i++) {       long long x, y;       cin >> x >> y;       if (x_t.find(x) == x_t.end()) x_t.insert(x);       if (y_t.find(y) == y_t.end()) y_t.insert(y);       long long tam_x = x_t.size();       long long tam_y = y_t.size();       ans.push_back(N * N - (tam_x + tam_y) * N + (tam_x * tam_y));     }     for (long long i = 0; i < ans.size() - 1; i++) cout << ans[i] <<    ;     cout << ans[ans.size() - 1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, l, a, q[100001], w[100001], sum = 0, i;     cin >> n >> l >> a;     for (i = 0; i < n; i++) {       cin >> q[i] >> w[i];     }     if (n == 0) {       cout << l / a;       return 0;     }     sum = sum + q[0] / a;     for (i = 1; i < n; i++) {       sum = sum + (q[i] - w[i - 1] - q[i - 1]) / a;     }     sum = sum + (l - w[n - 1] - q[i - 1]) / a;     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> divi[2002];   long long dp[2002][2002];   int main() {     int n, k;     cin >> k >> n;     int i, j;     for (i = 1; i <= k; i++) {       for (j = i; j <= k; j += i) divi[i].push_back(j);     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= k; j++) {         if (i == 1)           dp[i][j] = 1;         else {           for (int x : divi[j]) dp[i][j] += dp[i - 1][x], dp[i][j] %= 1000000007;         }       }     }     long long ans = 0;     for (i = 1; i <= k; i++) ans += dp[n][i], ans %= 1000000007;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105, M = N * N * N;   int n, pos, l, r, i, j, k, f[N][N][N], h, t, q[M][3], ans;   inline void ext(int x, int y, int z, int d) {     if (y > z) return;     if (y > l || z < r) return;     if (x < y || x > z) return;     if (~f[x][y][z]) return;     f[x][y][z] = d;     q[++t][0] = x;     q[t][1] = y;     q[t][2] = z;   }   int main() {     scanf( %d%d%d%d , &n, &pos, &l, &r);     for (i = 1; i <= n; i++)       for (j = 1; j <= l; j++)         for (k = r; k <= n; k++) f[i][j][k] = -1;     h = 1;     t = 0;     ext(pos, 1, n, 0);     while (h <= t) {       int x, y, z, w;       x = q[h][0];       y = q[h][1];       z = q[h++][2];       w = f[x][y][z] + 1;       ext(x - 1, y, z, w);       ext(x + 1, y, z, w);       ext(x, x, z, w);       ext(x, y, x, w);     }     ans = ~0U >> 1;     for (i = 1; i <= n; i++)       if (~f[i][l][r]) ans = min(ans, f[i][l][r]);     printf( %d , ans);   }
#include <bits/stdc++.h>   int32_t gcd(int32_t a, int32_t b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int32_t mpf(int32_t n, std::vector<int32_t>& primes) {     for (int32_t i = 0; i < primes.size(); i++)       if (n % primes[i] == 0) return primes[i];     return 1;   }   int main() {     int32_t num_tests;     std::cin >> num_tests;     for (int32_t t = 0; t < num_tests; t++) {       int32_t n;       std::cin >> n;       int32_t n2 = n;       std::vector<int32_t> primes;       std::map<int32_t, int32_t> powers;       for (int32_t i = 2; i * i <= n2; i++)         if (n2 % i == 0) {           primes.push_back(i);           while (n2 % i == 0) {             powers[i]++;             n2 /= i;           }         }       if (n2 != 1) {         primes.push_back(n2);         powers[n2]++;       }       std::map<int32_t, std::vector<int32_t> > mpf2;       for (int32_t i = 1; i * i <= n; i++) {         if (n % i == 0) {           mpf2[mpf(i, primes)].push_back(i);           if (i * i != n) mpf2[mpf(n / i, primes)].push_back(n / i);         }       }       mpf2.erase(1);       std::vector<int32_t> answer;       std::unordered_set<int32_t> used;       for (int32_t i = 0; i < primes.size(); i++) {         int32_t next =             primes.size() != 1 ? primes[i] * primes[(i + 1) % primes.size()] : -1;         for (int32_t j = 0; j < mpf2[primes[i]].size(); j++)           if (mpf2[primes[i]][j] != next &&               used.find(mpf2[primes[i]][j]) == used.end()) {             used.insert(mpf2[primes[i]][j]);             answer.push_back(mpf2[primes[i]][j]);           }         if (primes.size() != 1 && used.find(next) == used.end()) {           answer.push_back(next);           used.insert(next);         }       }       for (int32_t j = 0; j < answer.size(); j++) std::cout << answer[j] <<    ;       std::cout <<   n ;       int32_t actions = 0;       for (int32_t j = 0; j < answer.size(); j++) {         if (gcd(answer[j], answer[(j + 1) % answer.size()]) == 1) actions++;       }       std::cout << actions <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   inline int read() {     register int s = 0, f = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     while (c >=  0  && c <=  9 ) s = (s * 10 + (c ^  0 )), c = getchar();     return s * f;   }   inline void print(register int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 ^  0 );   }   using namespace std;   int ans, prim[20000005], l, r, tot;   bitset<300000005> vis;   inline void Get_Prime(register int l, register int r) {     vis[0] = vis[1] = 1;     for (register int i = 2; i <= r; ++i) {       if (!vis[i]) prim[++tot] = i;       for (register int j = 1; j <= tot && i * prim[j] <= r; ++j) {         vis[i * prim[j]] = 1;         if (i % prim[j] == 0) break;       }     }   }   int main() {     l = read(), r = read(), Get_Prime(l, r);     for (register int i = 5; i <= r; i += 4)       if (i >= l && !vis[i]) ++ans;     if (l <= 2 && r >= 2) ++ans;     print(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Max = 2e5 + 10;   const int LOG = 30;   const int INF = 1e9 + 10;   struct Trie {     int l[Max * LOG], r[Max * LOG];     int cnt[Max * LOG];     int sz = 1;     int index[Max * LOG];     int dp[Max * LOG][2];     void insert(int x, int ind) {       int p = 1;       for (int lg = LOG; lg--;) {         cnt[p]++;         if (x & (1 << lg))           if (r[p])             p = r[p];           else             p = r[p] = ++sz;         else if (l[p])           p = l[p];         else           p = l[p] = ++sz;       }       cnt[p]++;       index[p] = ind;     }     int mnxor(int x) {       int p = 1;       bool firstdiff = false;       for (int lg = LOG; lg--;) {         if (!firstdiff) {           if (x & (1 << lg))             if (cnt[r[p]] > 1)               p = r[p];             else {               p = l[p];               firstdiff = true;             }           else if (cnt[l[p]] > 1)             p = l[p];           else {             p = r[p];             firstdiff = true;           }         } else {           if (x & (1 << lg))             if (r[p])               p = r[p];             else               p = l[p];           else if (l[p])             p = l[p];           else             p = r[p];         }       }       return index[p];     }     void DP(int v) {       if (r[v]) DP(r[v]);       if (l[v]) DP(l[v]);       dp[v][0] = cnt[v] - 1;       dp[v][1] = min(dp[l[v]][0] + dp[r[v]][1], dp[r[v]][0] + dp[l[v]][1]);     }   };   Trie t;   int A[Max];   vector<int> N[Max];   bool seen[Max];   int DFS(int v) {     seen[v] = true;     int res = 1;     for (int u : N[v])       if (!seen[u]) res += DFS(u);     return res;   }   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       A[i] = a;       t.insert(a, i);     }     for (int i = 0; i < n; i++) {       int from = i;       int to = t.mnxor(A[i]);       N[from].push_back(to);       N[to].push_back(from);     }     int molcnt = 0;     int mxmol = 0;     for (int i = 0; i < n; i++)       if (!seen[i]) {         molcnt++;         mxmol = max(mxmol, DFS(i));       }     t.DP(1);     cout << t.dp[1][1];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }