malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int m = 1e9 + 7;   int bin_pow(int x, int k) {     if (k == 0) return 1;     int g = bin_pow(x, k / 2);     g = (1ll * g * g) % m;     if (k % 2 > 0) g = (1ll * g * x) % m;     return g;   }   signed main() {     iostream::sync_with_stdio(0);     cin.tie(0);     setlocale(LC_ALL,  Russian );     int tt, n, p, i, j, r, second, ans, add;     vector<int> read, k, cnt, st;     cin >> tt;     for (; tt > 0; tt--) {       cin >> n >> p;       read.assign(n, 0);       k.clear();       cnt.clear();       st.clear();       for (i = 0; i < n; i++) cin >> read[i];       if (p == 1) {         if (n % 2 > 0)           cout <<  1 n ;         else           cout <<  0 n ;         continue;       }       sort(read.begin(), read.end());       for (i = 0; i < n; i++) {         j = i + 1;         while (j < n && read[i] == read[j]) j++;         k.push_back(read[i]);         cnt.push_back(j - i);         i = j - 1;       }       st.push_back(bin_pow(p, k[0]));       for (i = 1; i < k.size(); i++)         st.push_back((1ll * st[i - 1] * bin_pow(p, k[i] - k[i - 1])) % m);       ans = 0;       for (i = k.size() - 1; i >= 0; i--) {         if (cnt[i] % 2 == 0) continue;         j = i - 1;         second = 1;         while (j >= 0) {           for (r = 0; r < k[j + 1] - k[j] && second <= n; r++) second *= p;           if (r < k[j + 1] - k[j] || second > n) break;           add = min(second, cnt[j]);           second -= add;           ans = (ans - 1ll * cnt[j] * st[j] + 2ll * m * m) % m;           cnt[j] -= add;           if (second == 0) break;           j--;         }         if (second > 0) {           while (j >= 0) {             ans = (ans - 1ll * cnt[j] * st[j] + 2ll * m * m) % m;             j--;           }           ans = (ans + st[i]) % m;           break;         }         ans = 0;         i = j + 1;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void add_edge(vector<long long> adj[], long long a, long long b) {     adj[a].push_back(b);     adj[b].push_back(a);   }   class myComparator {    public:     int operator()(int p1, int p2) { return p1 > p2; }   };   long long fun(long long x, long long n) {     long long mid, beg = 1, last = x / 2;     while (beg < last) {       mid = (beg + last) / 2;       long long t = x - mid;       if (t <= n) {         last = mid;       } else {         beg = mid + 1;       }     }     return (x / 2) - last + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n;     cin >> n;     long long t = (2 * n) - 1;     string v = to_string(t);     string s;     long long i;     for (i = 0; i < v.size(); i++) s +=  9 ;     long long num = stoll(s);     if (num > t) {       num /= 10;       s.pop_back();     }     long long ans = 0;     for (i = 0; i < 9; i++) {       string temp = to_string(i);       string ma = temp + s;       long long num = stoll(ma);       if (num > t) break;       ans += fun(num, n);     }     if (n > 4)       cout << ans << endl;     else {       long long k;       long long ans = 1;       for (k = 3; k <= n; k++) ans *= k;       if (n == 4) ans = ans / 2;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int B[1000 * 1001];   const int base = 1000 * 1000 + 3;   int main() {     int n, m;     int r = 1;     bool ok = true;     cin >> n >> m;     string A[n];     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < n; i++) {       bool empty = true;       for (int j = 0; j < m; j++) empty &= A[i][j] ==  . ;       if (empty) {         r = (r * 2) % base;         continue;       }       B[0] = 0;       B[m + 1] = 0;       for (int j = 0; j < m; j++) {         if (A[i][j] ==  . ) B[j + 1] = 0;         if (A[i][j] ==  1  || A[i][j] ==  2 ) B[j + 1] = 1;         if (A[i][j] ==  3  || A[i][j] ==  4 ) B[j + 1] = -1;       }       for (int j = 1; j < m; j++)         if (B[j] == -1 && B[j + 1] == 1) B[j] = B[j + 1] = 2;       for (int j = 1; j <= m; j++)         if (B[j] == 1 && B[j - 1] == 0) B[j] = B[j - 1] = 2;       for (int j = 1; j <= m; j++)         if (B[j] == -1 && B[j + 1] == 0) B[j] = B[j + 1] = 2;       int c = -1000 * 1000;       B[m + 1] = 2;       for (int j = 1; j <= m; j++) {         if (B[j] != 0 && B[j] != 2) ok = false;         if (B[j] == 0) c++;         if (B[j] == 2) {           if (c > 0 && c % 2) ok = false;           c = 0;         }       }     }     for (int i = 0; i < m; i++) {       bool empty = true;       for (int j = 0; j < n; j++) empty &= A[j][i] ==  . ;       if (empty) {         r = (r * 2) % base;         continue;       }       B[0] = 0;       B[n + 1] = 0;       for (int j = 0; j < n; j++) {         if (A[j][i] ==  . ) B[j + 1] = 0;         if (A[j][i] ==  1  || A[j][i] ==  4 ) B[j + 1] = 1;         if (A[j][i] ==  3  || A[j][i] ==  2 ) B[j + 1] = -1;       }       for (int j = 1; j < n; j++)         if (B[j] == -1 && B[j + 1] == 1) B[j] = B[j + 1] = 2;       for (int j = 1; j <= n; j++)         if (B[j] == 1 && B[j - 1] == 0) B[j] = B[j - 1] = 2;       for (int j = 1; j <= n; j++)         if (B[j] == -1 && B[j + 1] == 0) B[j] = B[j + 1] = 2;       int c = -1000 * 1000;       B[n + 1] = 2;       for (int j = 1; j <= n; j++) {         if (B[j] != 0 && B[j] != 2) ok = false;         if (B[j] == 0) c++;         if (B[j] == 2) {           if (c > 0 && c % 2) ok = false;           c = 0;         }       }     }     cout << (ok ? r : 0) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2010;   int n, m, k;   char a[MAXN][MAXN];   int pref[MAXN][MAXN];   int getSumLine(int i, int j) {     return pref[i][j + k - 1] - pref[i][j - 1] - pref[i - 1][j + k - 1] +            pref[i - 1][j - 1];   }   int getSumRow(int i, int j) {     return pref[i + k - 1][j] - pref[i - 1][j] - pref[i + k - 1][j - 1] +            pref[i - 1][j - 1];   }   int main() {     scanf( %d%d%d n , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %s , a[i] + 1);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  * ) {           pref[i][j]++;         }         pref[i][j] += pref[i - 1][j];         pref[i][j] += pref[i][j - 1];         pref[i][j] -= pref[i - 1][j - 1];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i + k - 1 <= n) {           if (getSumRow(i, j) == 0) ans++;         }         if (j + k - 1 <= m && k != 1) {           if (getSumLine(i, j) == 0) ans++;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   long long int a, b, n, S;   int main() {     cin >> t;     while (t--) {       cin >> a >> b >> n >> S;       if (b >= S) {         cout <<  YES  << endl;         continue;       }       if (a * n + b < S) {         cout <<  NO  << endl;         continue;       }       long long int x = S / n;       x = min(x, a);       long long int res = (S - x * n);       if (res <= b) {         cout <<  YES  << endl;         continue;       }       if (res > b) {         cout <<  NO  << endl;         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     int n, k;     cin >> n;     cin >> k;     int c[n];     for (int i = 0; i < n; ++i) cin >> c[i];     ;     map<int, int> table;     vector<long long> capitals;     long long csum = 0;     for (int i = 0; i < k; ++i) {       int id;       cin >> id;       id -= 1;       capitals.push_back(c[id]);       ;       ;       csum += c[id];       table[id] = 1;     };     long long ans = 0;     long long ncsum = 0;     for (int i = 0; i < n; ++i) {       if (table[i] != 1) ncsum += c[i];     };     long long dncsum = 0;     for (int i = 0; i < n; ++i) {       int right = (i + 1 == n ? 0 : i + 1);       if (table[i] != 1) {         if (table[right] != 1) {           ;           ;           dncsum += c[i] * c[right];         }       }     };     vector<long long> prefix(k);     for (int i = 0; i < k; ++i) {       if (i == 0)         prefix[i] = capitals[i];       else         prefix[i] = prefix[i - 1] + capitals[i];     }     long long fcsum = 0;     for (int i = 0; i < k; ++i) {       fcsum += capitals[i] * (csum - prefix[i]);       fcsum += capitals[i] * ncsum;     }     ans = fcsum + dncsum;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   struct Node {     int t[26], len, f, tf, d, s;   } a[1000500];   int tn, las;   void linkd(int u) {     int fa = a[u].f;     a[u].d = a[u].len - a[fa].len;     a[u].tf = (a[u].d == a[fa].d && a[u].d * 2 <= a[u].len) ? a[fa].tf : u;   }   void ins(int k, int c, char *str) {     int p = las;     while (str[k - a[p].len - 1] != c) p = a[p].f;     if (!a[p].t[c]) {       int np = las = ++tn, v;       for (v = a[p].f; str[k - a[v].len - 1] != c; v = a[v].f)         ;       if (!a[v].t[c])         a[np].f = 2;       else         a[np].f = a[v].t[c];       a[a[p].t[c] = np].len = a[p].len + 2;       linkd(np);     } else       las = a[p].t[c];   }   int f[1000500];   void dp(int k) {     for (int p = las; p > 2; p = a[a[p].tf].f) {       int tl = a[a[p].tf].len;       a[p].s = f[k - tl];       if (a[p].tf != p) a[p].s = (a[a[p].f].s + a[p].s) % mod;       if (!(k & 1)) f[k] = (f[k] + a[p].s) % mod;     }   }   void Init() {     a[1].f = a[2].f = 1;     a[1].len = -1;     las = tn = 2;   }   int n;   char s[1000500], s2[1000500];   int main() {     scanf( %s , s2 + 1);     n = strlen(s2 + 1);     if (n & 1) {       puts( 0 );       return 0;     }     for (int i = 1; i + i <= n; i++) {       s[i * 2 - 1] = s2[n - i + 1];       s[i * 2] = s2[i];     }     s[0] = -1;     f[0] = 1;     Init();     for (int i = 1; i <= n; i++) {       ins(i, s[i] -=  a , s);       dp(i);     }     printf( %d , f[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1003], d, u, e;   vector<int> v1, v2, v3;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < 0) v1.push_back(a[i]);       if (a[i] > 0) v2.push_back(a[i]);       if (a[i] == 0) v3.push_back(a[i]);     }     if (v2.size() == 0) {       v2.push_back(v1[0]);       v2.push_back(v1[1]);       v1[0] = -1003;       v1[1] = -1003;       d += 2;     }     if (v1.size() % 2 == 0) {       v3.push_back(v1[v1.size() - 1]);       v1[v1.size() - 1] = -1003;       d++;     }     cout << v1.size() - d <<    ;     for (int i = 0; i < v1.size(); i++)       if (v1[i] != -1003) cout << v1[i] <<    ;     cout << endl;     cout << v2.size() <<    ;     for (int i = 0; i < v2.size(); i++)       if (v2[i] != -1003) cout << v2[i] <<    ;     cout << endl;     cout << v3.size() <<    ;     for (int i = 0; i < v3.size(); i++)       if (v3[i] != -1003) cout << v3[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   void solve() {     long long n;     cin >> n;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       m[x]++;     }     long long mx = 0;     long long ans = 0;     for (auto it : m) {       ans += min(mx, it.second);       mx = max(mx, it.second);     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long int, char> p1, pair<long long int, char> p2) {     return p1.first > p2.first;   }   vector<vector<long long int> > graph;   vector<bool> vis;   vector<vector<long long int> > level;   vector<long long int> d, childp;   void dfs(long long int node, long long int prev) {     vis[node] = true;     d[node] = prev + 1;     long long int temp = 1, i;     long long int x = 0, k = 1;     for (i = 0; i < graph[node].size(); i++) {       if (vis[graph[node][i]] == false) {         dfs(graph[node][i], d[node]);         x += childp[graph[node][i]];       }     }     childp[node] = x + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, i, p;     cin >> n;     long double ans[n + 1];     graph.resize(n + 1);     level.resize(n + 1);     vis.resize(n + 1);     d.resize(n + 1);     childp.resize(n + 1);     for (i = 1; i <= n; i++) {       vis[i] = false;       d[i] = 0;       ans[i] = 0.0;       childp[i] = 0;     }     for (i = 2; i <= n; i++) {       cin >> p;       graph[p].push_back(i);       graph[i].push_back(p);     }     dfs(1, 0);     for (i = 1; i <= n; i++)       printf( %0.8lf  , ((n - childp[i] - d[i] + 1) / 2.0) + d[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   long long a[510][510], n;   int main() {     while (~scanf( %I64d , &n)) {       if (n == 1) {         scanf( %I64d , &n);         printf( 1 n );         continue;       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) scanf( %I64d , &a[i][j]);       }       int zr = 0, zc;       for (int i = 1; i <= n && !zr; ++i) {         for (int j = 1; j <= n && !zr; ++j) {           if (a[i][j] == 0) {             zr = i;             zc = j;           }         }       }       long long zv, sum = 0, zsum = 0;       for (int i = 1; i <= n; ++i) zsum += a[zr][i];       if (zr == 1) {         for (int i = 1; i <= n; ++i) sum += a[n][i];         zv = sum - zsum;       } else {         for (int i = 1; i <= n; ++i) sum += a[1][i];         zv = sum - zsum;       }       if (zv <= 0) {         printf( -1 n );         continue;       }       a[zr][zc] = zv;       bool ok = true;       for (int i = 1; i <= n; ++i) {         long long tmpsum = 0;         for (int j = 1; j <= n; ++j) tmpsum += a[i][j];         if (tmpsum != sum) {           ok = false;           break;         }         tmpsum = 0;         for (int j = 1; j <= n; ++j) tmpsum += a[j][i];         if (tmpsum != sum) {           ok = false;           break;         }       }       long long tmpsum = 0;       for (int i = 1; i <= n; ++i) tmpsum += a[i][i];       if (tmpsum != sum) ok = false;       tmpsum = 0;       for (int i = n; i >= 1; --i) tmpsum += a[i][n + 1 - i];       if (tmpsum != sum) ok = false;       if (ok) {         printf( %I64d n , zv);       } else         printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   const int N = 105;   int n, m, i, j, k, s[N], h[N], id[N], a[N], l[N], r[N];   int fr[N], fl[N];   bool cmp(int x, int y) { return s[x] < s[y]; }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; ++i) scanf( %d%d , s + i, h + i), id[i] = i;     if (m == 1) {       printf( %d n1 n , s[1]);       return 0;     }     std::sort(id + 1, id + m + 1, cmp);     for (i = 1; i <= n; ++i) scanf( %d , a + i);     for (i = 1; i <= m; ++i) {       long long ss;       ss = h[i];       for (l[i] = s[i]; l[i] && ss >= 0; ss += a[--l[i]])         ;       ++l[i];       ss = h[i];       for (r[i] = s[i]; r[i] <= n && ss >= 0; ss += a[++r[i]])         ;       --r[i];     }     fr[m] = m;     for (i = m - 1; i; --i) {       for (j = i + 1; j <= m; ++j)         if (fr[j] && l[id[j]] <= s[id[i]]) fr[i] = j;     }     fl[1] = 1;     for (i = 2; i <= m; ++i) {       for (j = 1; j < i; ++j)         if (fl[j] && r[id[j]] >= s[id[i]]) fl[i] = j;     }     if (fr[1]) {       static bool bb[N];       static int st[N];       int w = 0;       printf( %d n , s[id[1]]);       for (j = 1; j < m; j = fr[j]) st[++w] = id[j];       st[++w] = id[m];       std::reverse(st + 1, st + w + 1);       for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);       for (j = 1; j <= m; ++j)         if (!bb[j]) printf( %d  , j);       exit(0);     }     if (fl[m]) {       static bool bb[N];       static int st[N];       int w = 0;       printf( %d n , s[id[m]]);       for (j = m; j > 1; j = fl[j]) st[++w] = id[j];       st[++w] = id[1];       std::reverse(st + 1, st + w + 1);       for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);       for (j = 1; j <= m; ++j)         if (!bb[j]) printf( %d  , j);       exit(0);     }     for (i = 1; i < m; ++i)       for (k = i + 1; k <= m; ++k)         if (fl[i] && fr[k] && r[id[i]] + 1 >= l[id[k]]) {           printf( %d n , l[id[k]]);           static int st[N];           int w = 0;           static bool bb[N];           for (j = k; j < m; j = fr[j]) st[++w] = id[j];           st[++w] = id[m];           std::reverse(st + 1, st + w + 1);           for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);           w = 0;           for (j = i; j > 1; j = fl[j]) st[++w] = id[j];           st[++w] = id[1];           std::reverse(st + 1, st + w + 1);           for (; w; --w) bb[st[w]] = 1, printf( %d  , st[w]);           for (j = 1; j <= m; ++j)             if (!bb[j]) printf( %d  , j);           exit(0);         }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ar[111];   int in[111];   long long n, s, now, t;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];       s += ar[i];       in[i] = i;     }     if (s < n - 1 || ar[0] == 0) {       cout << -1;       return 0;     }     for (int ii = 1; ii < n - 1; ii++)       for (int i = 1; i < n - 1; i++)         if (ar[in[i]] < ar[in[i + 1]]) swap(in[i], in[i + 1]);     cout << n - 1;     s = 0;     now = 1;     while (now < n) {       while (ar[in[s]] > 0 && now < n) {         cout << endl << in[s] + 1 <<     << in[now++] + 1;         ar[in[s]]--;       }       s++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 6;   const long long M = 1e9 + 1;   char mat[105][105];   void solve() {     long long n;     cin >> n;     long long row[n];     vector<pair<long long, long long> > vecr;     vector<pair<long long, long long> > vecc;     long long col[n];     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         cin >> mat[i][j];         if (mat[i][j] ==  . ) {           if (row[i] != 1) vecr.push_back({i, j});           row[i] = 1;           if (col[j] != 1) vecc.push_back({i, j});           col[j] = 1;         }       }     }     bool rowok = true;     bool colok = true;     for (long long i = 0; i < n; i++) {       if (row[i] == 0) rowok = false;       if (col[i] == 0) colok = false;     }     if (!rowok && !colok)       cout << -1;     else if (rowok) {       for (long long i = 0; i < vecr.size(); i++)         cout << vecr[i].first + 1 <<     << vecr[i].second + 1 <<   n ;     } else if (colok) {       for (long long i = 0; i < vecc.size(); i++)         cout << vecc[i].first + 1 <<     << vecc[i].second + 1 <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   bool check(int i, int j, int k) {     return (i + j > k && j + k > i && j + i > j);   }   int main() {     int n, ct = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         int k = i ^ j;         if (k <= n && k >= j && check(i, j, k)) ct++;       }     }     cout << ct << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int number_of_usb;   int file_size;   int usb_required = 0;   int summing = 0;   int temp;   int main() {     cin >> number_of_usb;     cin >> file_size;     int usb_sizes[number_of_usb];     for (int i = 0; i < number_of_usb; i++) {       cin >> usb_sizes[i];     }     for (int i = 0; i < number_of_usb; i++) {       for (int j = 0; j < number_of_usb; j++) {         if (usb_sizes[i] > usb_sizes[j]) {           temp = usb_sizes[j];           usb_sizes[j] = usb_sizes[i];           usb_sizes[i] = temp;         }       }     }     for (int i = 0; i < number_of_usb; i++) {       if (summing < file_size) {         usb_required++;       }       summing += usb_sizes[i];     }     cout << usb_required;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int MOD = 1e4 + 7;   int n, m, q;   int main() {     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       int delt = abs(a - b);       int ans = delt / 10 + (delt % 10 != 0);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, tmp;   bool flag = false;   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       scanf( %d , &tmp);       if (tmp == 1) flag = true;     }     if (flag)       printf( %d , -1);     else       printf( %d , 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int p = 27;   string s;   long long int hashnum(int lw, int up) {     if ((up - lw) % 2 == 0)       return (((hashnum(lw, (lw + up) / 2) * p) % mod + 1) *               ((hashnum((lw + up) / 2, up) * p) % mod + 1)) %              mod;     long long int res = 0;     for (int i = lw; i < up; i++) {       res *= p;       res %= mod;       res += (s[i] -  a );       res %= mod;     }     return res;   }   int main() {     cin >> s;     long long int tmp = hashnum(0, s.length());     cin >> s;     long long int tmp1 = hashnum(0, s.length());     if (tmp == tmp1)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   } a[200005];   bool cmp(struct point A, struct point B) {     if (A.x != B.x) return A.x < B.x;     return A.y < B.y;   }   int m;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i].x);       a[i].y = i + 1;     }     int num = 0;     for (int i = n; i < 2 * n; i++) {       scanf( %d , &a[i].x);       a[i].y = i + 1 - n;       if (a[i].x == a[i - n].x) num++;     }     n *= 2;     a[n].x = 1e9 + 1;     n++;     sort(a, a + n, cmp);     cin >> m;     long long ans = 1;     int count = 1;     for (int i = 1; i < n; i++) {       if (a[i].x == a[i - 1].x) {         count++;         ans = (ans * count);         while (num && ans % 2 == 0) {           ans /= 2;           num--;         }         ans %= m;       } else         count = 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   int tree[N * 32][2], cnt[N * 32];   long long int curr = 1, n, ans;   vector<long long int> arr(N);   void clean() {     for (long long int i = 0; i <= N * 32 - 1; i++) tree[i][0] = tree[i][1] = -1;   }   void add(long long int x) {     long long int v = 0;     cnt[v]++;     for (long long int i = 32; i >= 0; i--) {       long long int b = (x >> i) & 1;       if (tree[v][b] == -1) tree[v][b] = curr++;       v = tree[v][b];       cnt[v]++;     }   }   long long int calc(int v) {     if (v == -1) return 0;     int s0 = 0, s1 = 0;     if (tree[v][0] != -1) s0 = cnt[tree[v][0]];     if (tree[v][1] != -1) s1 = cnt[tree[v][1]];     if (s0 == 0 && s1 == 0) return cnt[v];     if (s0 == 0) return calc(tree[v][1]);     if (s1 == 0) return calc(tree[v][0]);     return 1 + max(calc(tree[v][0]), calc(tree[v][1]));   }   int main() {     clean();     cin >> n;     for (long long int i = 0; i <= n - 1; i++) cin >> arr[i], add(arr[i]);     cout << n - calc(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, max1 = 0, n, p, sum = 0;     string a, b, c;     cin >> n;     int x[26] = {0};     cin >> a;     if (n > 26)       cout <<  -1  << endl;     else {       for (i = 0; i < n; i++) {         p = a[i] -  a ;         x[p]++;       }       for (i = 0; i < 26; i++) {         if (x[i] > 1) {           sum += (x[i] - 1);           if (x[i] > max1) max1 = x[i];         }       }       cout << sum << endl;     }     return 0;   }