malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline bool chmax(int& a, int b) {     if (a < b) {       a = b;       return true;     }     return false;   }   constexpr int B = 210;   int q, n, e, i, j, ans, res, l, r, val, x, mid;   void solve() {     cin >> n;     vector<vector<int>> sum(n + 1, vector<int>(B, 0));     for (i = 0; i < n; i++) {       for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];       cin >> e;       sum[i + 1][e]++;     }     ans = 0;     for (x = 0; x < B; x++) {       res = 0;       l = 0;       r = n;       val = 0;       while (l < r) {         mid = 0;         while (l < n and sum[l][x] < val) l++;         while (0 < r and sum[n][x] - sum[r][x] < val) r--;         if (r <= l) break;         for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);         chmax(res, mid + sum[l][x] + sum[l][x]);         val++;       }       chmax(ans, res);     }     cout << ans <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> q;     while (q--) {       cin >> n;       vector<vector<int>> sum(n + 1, vector<int>(B, 0));       for (i = 0; i < n; i++) {         for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];         cin >> e;         sum[i + 1][e]++;       }       ans = 0;       for (x = 0; x < B; x++) {         res = 0;         l = 0;         r = n;         val = 0;         while (l < r) {           mid = 0;           while (l < n and sum[l][x] < val) l++;           while (0 < r and sum[n][x] - sum[r][x] < val) r--;           if (r < l) break;           for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);           chmax(res, mid + sum[l][x] + sum[l][x]);           val++;         }         chmax(ans, res);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 100000 + 5;   using namespace std;   int main() {     int n, a[maxn];     cin >> n;     bool flag = false;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 2; i < n; i++) {       int x = a[i], y = a[i - 1];       int z = a[i - 2];       if ((y + z) > x && (x - y) < z) flag = true;     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 998244353;   const ll MX = 3e5 + 5;   ll fct[MX] = {1}, inv[MX] = {1};   ll power(ll a, ll b, ll p = 1) {     if (b == 0) return 1;     ll res = power(a, b / 2) % MOD;     if (b & 1) {       return (((res * res) % MOD) * a) % MOD;     } else {       return (((res * res) % MOD) * 1) % MOD;     }   }   void func() {     ll i;     fct[1] = 1;     for (i = 2; i < MX; i++) {       fct[i] = fct[i - 1] * i;       fct[i] %= MOD;     }     for (i = 1; i < MX; i++) {       inv[i] = power(fct[i], MOD - 2);     }   }   int main() {     func();     ll n, i, k;     cin >> n >> k;     vector<pair<ll, ll>> vt;     for (i = 0; i < n; i++) {       ll l, r;       cin >> l >> r;       vt.push_back({l, -1});       vt.push_back({r, 1});     }     sort(vt.begin(), vt.end());     ll cur = 0, ans = 0;     for (i = 0; i < vt.size(); i++) {       if (vt[i].second < 0) {         cur++;       } else {         cur--;         if (cur >= k - 1)           ans += (((fct[cur] * inv[k - 1]) % MOD) * inv[cur - k + 1]) % MOD;         ans %= MOD;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int a[100][100], n, row[55][100005], col[55][100005];   bool valid(int i, int j) {     for (int k = 0; k < n; k++) {       if (k == i) continue;       int x = a[i][j] - a[k][j];       if (x > 0 && row[i][x] && (x != a[i][j] || row[i][x] > 1)) return 1;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);         row[i][a[i][j]]++;         col[j][a[i][j]]++;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j] != 1 && !valid(i, j)) {           printf( No n );           return 0;         }     printf( Yes n );   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long mo = 1000000007;   int n, k;   long long c[15][15];   long long f[210][210][10];   int flag[10][10] =       {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0, 0, 0},        {1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {1, 2, 0, 1, 0, 0, 0, 0, 0, 0},        {1, 2, 0, 0, 1, 0, 0, 0, 0, 0}, {1, 1, 1, 0, 0, 1, 0, 0, 0, 0},        {1, 0, 2, 0, 0, 0, 1, 0, 0, 0}, {1, 3, 0, 2, 1, 0, 0, 1, 0, 0},        {1, 2, 1, 1, 0, 2, 0, 0, 1, 0}, {1, 4, 0, 4, 2, 0, 0, 4, 0, 1}},       dt1[10] = {12, 9, 6, 6, 6, 3, 0, 3, 0, 0},       dt2[10] = {4, 2, 1, 1, 0, 0, 0, 0, 0, 0};   int main() {     f[0][0][0] = 1;     f[0][1][1] = 4;     f[0][1][2] = 4;     f[0][2][3] = 4;     f[0][2][4] = 2;     f[0][2][5] = 8;     f[0][2][6] = 2;     f[0][3][7] = 4;     f[0][3][8] = 4;     f[0][4][9] = 1;     scanf( %d%d , &n, &k);     c[0][0] = 1;     for (int i = 1; i < 15; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mo;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < 10; j++)         for (int p = 0; p <= k; p++) {           if (!f[i][p][j]) continue;           for (int q = 0; q < 10; q++) {             if (!flag[j][q]) continue;             for (int r = 0; p + r <= k && r <= dt2[q]; r++)               for (int t = 0; r + p + t <= k && t <= dt1[q] - 2 * r; t++)                 (f[i + 1][p + r + t][q] +=                  (f[i][p][j] * c[dt2[q]][r] % mo * c[dt1[q] - 2 * r][t] % mo *                   flag[j][q] % mo)) %= mo;           }         }     long long ans = 0;     for (int i = 0; i < 10; i++) (ans += f[n][k][i]) %= mo;     for (int i = 1; i <= k; i++) (ans *= i) %= mo;     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   int mobius[500005], prime_cnt[500005], prime[500005], present[500005],       nums[500005], cnt[500005];   vector<int> divisors[500005];   void calc_divisors(int val) {     int i;     if (divisors[val].size() > 0) return;     int foo = sqrt(val);     for (i = 1; i <= foo; i++) {       if ((val % i) == 0) {         divisors[val].push_back(i);         divisors[val].push_back(val / i);       }     }     if ((foo * foo) == val) {       int temp = divisors[val].size();       divisors[val][temp - 1] = 0;     }     return;   }   void calc_mobius() {     mobius[0] = 0;     long long int i, j, temp;     prime[1] = 1;     mobius[1] = 1;     for (i = 2; i < 500005; i++) {       if (prime[i] == 0) {         for (j = 2 * i; j < 500005; j += i) {           prime[j] = 1;           prime_cnt[j]++;         }         temp = i * i;         j = 1;         while (temp < 500005) {           mobius[temp] = 0;           j++;           temp = j * i * i;         }         mobius[i] = -1;       } else {         if (mobius[i] == 500005) {           if ((prime_cnt[i] % 2) == 0)             mobius[i] = 1;           else             mobius[i] = -1;         }       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     int i, j, t, n, m, k, l, r, temp, mini, maxi, flag;     long long int result = 0LL;     for (i = 0; i < 500005; i++) {       mobius[i] = 500005;       prime[i] = 0;       prime_cnt[i] = 0;       cnt[i] = 0;       present[i] = 0;     }     calc_mobius();     divisors[1].push_back(1);     divisors[2].push_back(1);     divisors[2].push_back(2);     divisors[3].push_back(1);     divisors[3].push_back(3);     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> nums[i];       calc_divisors(nums[i]);     }     for (i = 0; i < m; i++) {       cin >> k;       temp = nums[k];       if (present[k] == 0) {         present[k] = 1;         for (j = 0; j < divisors[temp].size(); j++) {           result = result + (long long int)mobius[divisors[temp][j]] *                                 cnt[divisors[temp][j]];           cnt[divisors[temp][j]]++;         }       } else {         present[k] = 0;         for (j = 0; j < divisors[temp].size(); j++) {           result = result - (long long int)mobius[divisors[temp][j]] *                                 (cnt[divisors[temp][j]] - 1LL);           cnt[divisors[temp][j]]--;         }       }       cout << result << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, T, i, j, temp, le, ri, mid, ma = 0;     cin >> n >> a >> b >> T;     char str[n];     cin >> str;     int r[n], l[n];     if (str[0] ==  h )       r[0] = 1;     else       r[0] = b + 1;     for (i = 1; i < n; i++) {       if (str[i] ==  h )         r[i] = r[i - 1] + a + 1;       else         r[i] = r[i - 1] + a + b + 1;     }     if (str[n - 1] ==  h )       l[0] = a + 1;     else       l[0] = a + b + 1;     for (i = 1; i < n - 1; i++) {       if (str[n - 1 - i] ==  h )         l[i] = l[i - 1] + a + 1;       else         l[i] = l[i - 1] + a + b + 1;     }     for (i = 0; i < n; i++)       if (r[i] <= T) ma = max(ma, i + 1);     for (i = 0; i < n - 1; i++) {       temp = l[i];       if (temp >= T) continue;       le = 0;       ri = n - 1 - i - 1;       while (ri - le > 1) {         mid = (le + ri) / 2;         temp = l[i] + min(i + 1, mid) * a;         if (temp + r[mid] < T)           le = mid;         else           ri = mid;       }       if (l[i] + r[le] + min(i + 1, le) * a <= T) ma = max(ma, i + le + 2);       if (l[i] + r[ri] + min(i + 1, ri) * a <= T) ma = max(ma, i + ri + 2);     }     cout << ma;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e3 + 10;   char s[N], x[N], y[N];   int n, d;   namespace Trie {   const int M = N * 60;   int ch[M][10], tot = 1, rt = 1, fail[M];   bool ed[M];   inline void insert(int l, int r) {     int now = rt;     for (int i = l; i <= r; ++i) {       int v = s[i] -  0 ;       if (!ch[now][v]) ch[now][v] = ++tot;       now = ch[now][v];     }     ed[now] = true;   }   inline void getfail() {     for (int i = 0; i < 10; ++i) ch[0][i] = rt;     fail[rt] = 0;     queue<int> q;     q.push(rt);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < 10; ++i) {         if (!ch[u][i])           ch[u][i] = ch[fail[u]][i];         else           fail[ch[u][i]] = ch[fail[u]][i], q.push(ch[u][i]);       }     }   }   }  // namespace Trie   using namespace Trie;   int dp[2][N * 50][2][2][2];   inline void upd(int &x, int y) { x = (x + y >= mod) ? x + y - mod : x + y; }   int main() {     scanf( %s%s%s , s + 1, x + 1, y + 1);     n = strlen(s + 1);     d = strlen(x + 1);     int nd = d / 2;     for (int i = 1; i + nd - 1 <= n; ++i) insert(i, i + nd - 1);     getfail();     dp[0][rt][1][1][0] = 1;     for (int i = 1; i <= d; ++i) {       int cur = i & 1, last = !cur;       for (int pos = 0; pos <= tot; ++pos)         for (int limx = 0; limx <= 1; ++limx)           for (int limy = 0; limy <= 1; ++limy)             for (int ok = 0; ok <= 1; ++ok) {               int &d = dp[last][pos][limx][limy][ok];               if (!d) continue;               int s = limx ? x[i] -  0  : 0, t = limy ? y[i] -  0  : 9;               for (int c = s; c <= t; ++c) {                 int npos = ch[pos][c];                 upd(dp[cur][npos][limx && c == x[i] -  0 ]                       [limy && c == y[i] -  0 ][ok | ed[npos]],                     d);               }               d = 0;             }     }     int ans = 0;     for (int pos = 0; pos <= tot; ++pos)       for (int limx = 0; limx <= 1; ++limx)         for (int limy = 0; limy <= 1; ++limy)           upd(ans, dp[d & 1][pos][limx][limy][1]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int inp[105][105];   int a[105];   int b[105];   int temp[105];   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &inp[i][j]);     for (int i = 0; i < m; i++) b[i] = inp[0][i];     int up = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) up = max(up, inp[i][j]);     int prevk = 0;     for (int i = 1; i <= n - 1; i++) {       map<int, int> mp;       for (int j = 0; j < m; j++) {         temp[j] = inp[i][j] - b[j];         mp[temp[j]] = 1;       }       int currk = 0;       if (mp.size() == 2) {         int f = mp.rbegin()->first;         int s = mp.begin()->first;         if (max(f, s) >= 0 && min(f, s) <= 0)           currk = max(s, f) - min(s, f);         else           currk = -1;       }       if (mp.size() > 2 || (currk && prevk && currk != prevk) ||           (currk != 0 && currk <= up)) {         printf( NO n );         return 0;       }       prevk = max(prevk, currk);       a[i] = max(mp.rbegin()->first, mp.begin()->first);     }     printf( YES n );     if (prevk == 0) prevk = 2e9 + 7;     printf( %d n , prevk);     for (int i = 0; i < n; i++)       printf( %d  , (a[i] >= 0) ? a[i] : (a[i] + prevk));     cout << endl;     for (int i = 0; i < m; i++) printf( %d  , b[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55, maxm = 9;   int loc[maxn][2], col[maxn];   char s[maxn][maxn], res[maxn][maxn];   int num[maxn][maxn], used[maxm][maxm];   int n, m, ans, cnt;   void dfs(int u, int v) {     int i, j, x, y;     if (u > 14) {       memset(used, 0, sizeof used);       for (i = 1; i <= 28; ++i) {         x = col[loc[i][0]];         y = col[loc[i][1]];         if (used[x][y]) return;         used[x][y] = used[y][x] = true;       }       ++ans;       if (ans == 1) {         for (i = 1; i <= n; ++i)           for (j = 1, res[i][m + 1] =   0 ; j <= m; ++j)             res[i][j] = num[i][j] ? col[num[i][j]] - 1 +  0  :  . ;       }       return;     }     if (col[u])       dfs(u + 1, v);     else {       for (i = u + 1, col[u] = v; i <= 14; ++i)         if (!col[i]) {           col[i] = v;           dfs(u + 1, v + 1);           col[i] = 0;         }       col[u] = 0;     }   }   int main() {     int i, j, t;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i) scanf( %s , s[i] + 1);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j)         if (s[i][j] !=  . ) {           if (!num[i][j])             num[i][j] = num[i + 1][j] = num[i][j + 1] = num[i + 1][j + 1] = ++cnt;           t = s[i][j] <  a  ? s[i][j] -  A  + 27 : s[i][j] -  a  + 1;           if (!loc[t][0])             loc[t][0] = num[i][j];           else             loc[t][1] = num[i][j];         }     dfs(1, 1);     printf( %I64d n , (long long)ans * 5040);     for (i = 1; i <= n; ++i) puts(res[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   vector<int> num, low, S, vis;   int cntr, numCC;   int par[N];   vector<int> adj[N];   void tarjanSCC(int v) {     low[v] = num[v] = ++cntr;     vis[v] = 1;     S.push_back(v);     for (auto u : adj[v]) {       if (num[u] == -1) tarjanSCC(u);       if (vis[u]) low[v] = min(low[v], low[u]);     }     if (low[v] == num[v]) {       while (1) {         int u = S.back();         S.pop_back();         vis[u] = 0;         par[u] = numCC;         if (u == v) break;       }       numCC++;     }   }   int u[N], v[N], w[N];   vector<pair<int, long long>> edge[N];   long long gain[N], del[N];   long long sum(long long n) { return n * (n + 1) / 2; }   long long get(int c) {     long long l = 0, r = c;     while (l < r) {       long long mid = (l + r + 1) >> 1;       if (sum(mid) <= c) {         l = mid;       } else {         r = mid - 1;       }     }     return 1LL * c * (l + 1) - del[l];   }   long long dp[N];   long long dfs(int now) {     if (dp[now] != -1) return dp[now];     long long best = 0;     for (auto it : edge[now]) {       best = max(best, dfs(it.first) + it.second);     }     return dp[now] = best + gain[now];   }   int main() {     for (int i = 1; i < N; i++) del[i] = del[i - 1] + sum(i);     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d %d , u + i, v + i, w + i);       adj[u[i]].push_back(v[i]);     }     int s;     scanf( %d , &s);     num.assign(n + 1, -1);     low.assign(n + 1, 0);     vis.assign(n + 1, 0);     cntr = numCC = 0;     for (int i = 1; i <= n; i++)       if (num[i] == -1) tarjanSCC(i);     for (int i = 0; i < m; i++) {       int a = par[u[i]];       int b = par[v[i]];       if (a == b) {         gain[a] += get(w[i]);       } else {         edge[a].emplace_back(b, w[i]);       }     }     memset(dp, -1, sizeof(dp));     cout << dfs(par[s]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, size_t... Is>   struct arr_helper;   template <class T, size_t... Is>   using arr = typename arr_helper<T, Is...>::type;   template <class T>   struct arr_helper<T> {     using type = T;   };   template <class T, size_t I, size_t... Is>   struct arr_helper<T, I, Is...> {     using type = array<arr<T, Is...>, I>;   };   using ll = long long;   using u64 = uint64_t;   using u32 = uint32_t;   using vi = vector<int>;   using vl = vector<ll>;   using vvi = vector<vi>;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using vpi = vector<pi>;   [[maybe_unused]] const int INF = (int)1e9;   [[maybe_unused]] const ll INFL = (ll)1e18;   ll M = 998244353;   int mod_pow(ll b, ll e) {     ll res = 1;     for (; e; b = b * b % M, e /= 2)       if (e % 2) res = res * b % M;     return (int)res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, k;     cin >> n >> m >> k;     vi f(k + 1), fi(k + 1), fn(k + 1);     f[0] = 1;     for (int i = (1); i < (k + 1); ++i) f[i] = (ll)f[i - 1] * i % M;     for (int i = 0; i < (k + 1); ++i) fi[i] = mod_pow(f[i], M - 2);     fn[0] = 1;     for (int i = (1); i < (k + 1); ++i) fn[i] = fn[i - 1] * (ll)(n - i + 1) % M;     auto choose = [&](int n, int k) {       if (k > n) return 0ll;       return (ll)f[n] * fi[n - k] % M * (ll)fi[k] % M;     };     auto choose_n = [&](int k) { return fn[k] * (ll)fi[k] % M; };     ll sum = 0;     auto p = mod_pow(m, M - 2);     auto q = (ll)(m - 1) * p % M;     vi nmkitok(k + 1);     for (int i = 0; i < (k + 1); ++i) nmkitok[i] = mod_pow(n - i, k);     for (int j = 0; j < (k + 1); ++j) {       ll si = 0;       for (int ki = 0; ki < (j + 1); ++ki) {         si += (ll)(ki % 2 ? M - 1 : 1) * choose(j, ki) % M * nmkitok[ki] % M;         si %= M;       }       sum += mod_pow(M - q, j) * (ll)choose_n(j) % M * si % M;       sum %= M;     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int t;     cin >> n >> t;     if (t == 10 && n == 1) return cout << -1, 0;     string s;     if (t == 10)       s +=  10 , n -= 2;     else       s += (char)(t + 48), n--;     while (n--) s +=  0 ;     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     if (b == 1) return a;     long long int c = power(a, b / 2);     if (b % 2 == 0) return ((c % 1000000007) * (c % 1000000007)) % 1000000007;     return ((((c % 1000000007) * (c % 1000000007)) % 1000000007) *             (a % 1000000007)) %            1000000007;   }   int main() {     long long int n, i;     cin >> n;     long long int a[n];     long long int hash[100005] = {0};     long long int mini = 99999999999999;     long long int t = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       hash[a[i]]++;     }     for (i = 1; i <= 100; i++) {       long long int sum = 0;       for (long long int j = 1; j <= 100; j++) {         if (j < i)           sum += (hash[j] * (i - 1 - j));         else if (j > i)           sum += (hash[j] * (j - 1 - i));       }       if (sum < mini) {         mini = sum;         t = i;       }     }     cout << t <<     << mini << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s[n + 1];     if (n % 2 == 0)       cout << n * n / 2 << endl;     else       cout << ((n * n) + 1) / 2 << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i % 2 != 0 && j % 2 != 0)           cout <<  C ;         else if (i % 2 != 0 && j % 2 == 0)           cout <<  . ;         else if (i % 2 == 0 && j % 2 != 0)           cout <<  . ;         else           cout <<  C ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   const long long LLINF = numeric_limits<long long>::max();   const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();   vector<vector<int>> g;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> a(n);     for (int i = 0; i < n; i++) {       int d, b;       cin >> d >> b;       a[i] = {d, b};     }     queue<int> q;     for (int i = 0; i < n; i++) {       if (a[i].first == 1) q.push(i);     }     vector<pair<int, int>> ans;     while (!q.empty()) {       int v = q.front();       q.pop();       if (a[v].first == 0) continue;       ans.push_back({v, a[v].second});       a[a[v].second].first--;       a[a[v].second].second ^= v;       if (a[a[v].second].first == 1) q.push(a[v].second);     }     cout << ans.size() <<   n ;     for (auto k : ans) cout << k.first <<     << k.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, an;   int f[(1 << 20)], h[(1 << 20)];   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &k), f[k]++;     m = (1 << 20) - 1;     for (i = 0; i <= 19; i++)       for (j = 0; j <= m; j++)         if (!(j & (1 << i))) f[j] += f[j | (1 << i)];     h[0] = 1;     for (i = 1; i <= (1 << 20) - 1; i++) h[i] = h[i - 1] * 2 % 1000000007;     for (i = 0; i <= m; i++) {       int s = 0;       for (j = 0; j <= 19; j++) s += i >> j & 1;       if (f[i]) an = ((s & 1 ? -1 : 1) * (h[f[i]] - 1) + an) % 1000000007;     }     if (an < 0) an += 1000000007;     printf( %d n , an);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int lg[1000005], jump[1000005][20], depth[1000005], head[1000005], cnt = 4;   int q, tot, s, t, zj;   struct edge {     int to, next;   } e[2000005];   void add(int x, int y) {     e[++tot].to = y;     e[tot].next = head[x];     head[x] = tot;   }   void dfs(int now, int fa) {     for (int i = head[now]; i; i = e[i].next) {       if (e[i].to != fa) {         dfs(e[i].to, now);       }     }   }   int LCA(int x, int y) {     if (depth[x] < depth[y]) {       swap(x, y);     }     while (depth[x] > depth[y]) {       x = jump[x][lg[depth[x] - depth[y]] - 1];     }     if (x == y) {       return x;     }     for (int i = lg[depth[x]] - 1; i >= 0; i--) {       if (jump[x][i] != jump[y][i]) {         x = jump[x][i];         y = jump[y][i];       }     }     return jump[x][0];   }   int dis(int a, int b) {     int lca = LCA(a, b);     return depth[a] + depth[b] - 2 * depth[lca];   }   int main() {     ios::sync_with_stdio(false);     cin >> q;     for (int i = 1; i <= q * 2 + 4; i++) {       lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);     }     add(1, 2), add(1, 3), add(1, 4);     jump[2][0] = jump[3][0] = jump[4][0] = 1;     depth[1] = 1, depth[2] = depth[3] = depth[4] = 2;     s = 2, t = 4, zj = 2;     for (int i = 0; i < q; i++) {       int v;       cin >> v;       cnt++;       add(v, cnt);       add(cnt, v);       depth[cnt] = depth[v] + 1;       jump[cnt][0] = v;       for (int j = 1; j <= lg[depth[cnt]]; j++) {         jump[cnt][j] = jump[jump[cnt][j - 1]][j - 1];       }       if (dis(cnt, s) > dis(s, t)) {         t = cnt;         zj = dis(cnt, s);       }       if (dis(cnt, t) > dis(s, t)) {         s = cnt;         zj = dis(cnt, t);       }       cnt++;       add(v, cnt);       add(cnt, v);       depth[cnt] = depth[v] + 1;       jump[cnt][0] = v;       for (int j = 1; j <= lg[depth[cnt]]; j++) {         jump[cnt][j] = jump[jump[cnt][j - 1]][j - 1];       }       if (dis(cnt, s) > dis(s, t)) {         t = cnt;         zj = dis(cnt, s);       }       if (dis(cnt, t) > dis(s, t)) {         s = cnt;         zj = dis(cnt, t);       }       cout << zj << endl;     }   }