malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct Compteur {     int nbs[4];     Compteur() {       for (int iCoeff = 0; iCoeff < 4; iCoeff++) {         nbs[iCoeff] = 0;       }     }   };   Compteur operator+(const Compteur &a, const Compteur &b) {     Compteur nouv;     for (int iCoeff = 0; iCoeff < 4; iCoeff++) {       nouv.nbs[iCoeff] = a.nbs[iCoeff] + b.nbs[iCoeff];     }     return nouv;   }   int getP2(int a) {     int s = 1;     while (s < a) {       s *= 2;     }     return s;   }   vector<Compteur> arbres[10][10];   void modif(vector<Compteur> &a, int pos, Compteur val) {     pos += (int)a.size() / 2;     while (pos != 0) {       a[pos] = a[pos] + val;       pos /= 2;     }   }   Compteur getSomme(vector<Compteur> &a, int deb, int fin) {     deb += (int)a.size() / 2;     fin += (int)a.size() / 2;     Compteur somme;     while (deb < fin) {       if (deb % 2 == 1) {         somme = somme + a[deb];         deb++;       }       if (fin % 2 == 1) {         fin--;         somme = somme + a[fin];       }       deb /= 2;       fin /= 2;     }     return somme;   }   int conv[256];   int main() {     string chaine;     cin >> chaine;     conv[ A ] = 0;     conv[ T ] = 1;     conv[ G ] = 2;     conv[ C ] = 3;     for (int iTaille = 1; iTaille <= 10; iTaille++) {       for (int iMod = 0; iMod < iTaille; iMod++) {         arbres[iTaille - 1][iMod] = vector<Compteur>(             2 * getP2((chaine.size() + iTaille) / iTaille), Compteur());       }     }     for (int iCar = 0; iCar < chaine.size(); iCar++) {       Compteur nouv;       nouv.nbs[conv[chaine[iCar]]]++;       for (int iTaille = 1; iTaille <= 10; iTaille++) {         int mod = iCar % iTaille;         int pos = iCar / iTaille;         modif(arbres[iTaille - 1][mod], pos, nouv);       }     }     int nbReqs;     cin >> nbReqs;     for (int iReq = 0; iReq < nbReqs; iReq++) {       int type;       cin >> type;       if (type == 1) {         int iCar;         char val;         cin >> iCar >> val;         iCar--;         Compteur nouv;         nouv.nbs[conv[val]]++;         nouv.nbs[conv[chaine[iCar]]]--;         for (int iTaille = 1; iTaille <= 10; iTaille++) {           int mod = iCar % iTaille;           int pos = iCar / iTaille;           modif(arbres[iTaille - 1][mod], pos, nouv);         }         chaine[iCar] = val;       } else {         int deb, fin;         string comp;         cin >> deb >> fin >> comp;         deb--;         int iTaille = comp.size();         int somme = 0;         for (int iMod = 0; iMod < iTaille; iMod++) {           int mod = (deb + iMod) % iTaille;           int debPos = (deb + iMod) / iTaille;           int finPos = (fin - iTaille) / iTaille;           while (finPos * iTaille + mod < fin) {             finPos++;           }           Compteur vals = getSomme(arbres[iTaille - 1][mod], debPos, finPos);           somme += vals.nbs[conv[comp[iMod]]];         }         cout << somme << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, d, b;     char a, ch[3];     cin >> s;     long long i, j, ans, n, flag = 0;     a = s[0];     for (i = 1; i < s.size(); i++) {       if (s[i] ==  . ) continue;       if (s[i] ==  e ) {         flag = 1;       }       if (s[i] !=  e ) {         if (flag)           b.push_back(s[i]);         else           d.push_back(s[i]);       }     }     if (d.size() == 1 && d[0] ==  0 ) d.clear();     if (a ==  0 ) {       cout << a;       if (d.size()) cout <<  .  << d;       return 0;     }     for (i = 0; i < b.size(); i++) ch[i] = b[i];     long long pr = atoi(ch);     if (d.size() == pr) cout << a << d;     if (d.size() > pr) {       cout << a;       for (i = 0; i < d.size(); i++) {         if (i == pr) cout <<  . ;         cout << d[i];       }     }     if (pr > d.size()) {       if (a !=  0 ) cout << a;       for (i = 0; i < pr; i++) {         if (i < d.size())           cout << d[i];         else {           cout <<  0 ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 15000001;   int n;   int sieve[sz];   int v[300001];   int cnt[sz];   inline void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);     }     for (int i = 2; i < sz; i++)       if (sieve[i] == 0) {         for (int j = i; j < sz; j += i) sieve[j] = i;       }     for (int i = 0; i < n; i++) {       int x = v[i];       if (x == 1) continue;       vector<int> f;       while (x != 1) {         f.push_back(sieve[x]);         x /= sieve[x];       }       int cur = f[f.size() - 1];       cnt[cur]++;       for (int j = f.size() - 2; j >= 0; j--) {         if (f[j] == f[j + 1])           cur *= f[j];         else           cur = f[j];         cnt[cur]++;       }     }     int otv = n;     for (int i = 0; i < sz; i++) {       if (n != cnt[i]) otv = min(n - cnt[i], otv);     }     if (otv == n)       printf( %d , -1);     else       printf( %d , otv);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     for (; q > 0; q--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <typename T>   inline void rit(T &x) {     char c;     for (x = 0, c = getchar(); c <  - ; c = getchar())       ;     for (; c >=  0 ; x = x * 10 + c -  0 , c = getchar())       ;   }   int Q, op, x, c, p = 1;   long long int s[500001];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     rit(Q);     while (Q--) {       rit(op);       if (op == 1) {         s[c + 1] = s[c] + x, ++c, rit(x);       } else {         while (p < c && s[p] + x >= (s[p + 1] - s[p]) * p) ++p;         double ans = (double)x - (double)(s[p] + x) / p;         int a = ans;         cout << a <<  .  << setw(7) << setfill( 0 ) << (int)((ans - a) * 1e7)              <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   long long n;   int Q;   void ReadInput() {     cin >> n >> Q;     n *= 2LL;   }   long long Get(long long first) {     if (first % 2 == 1) return (first + 1) / 2;     return Get(first + (n - first) / 2);   }   void Solve() {     while (Q-- > 0) {       long long first;       cin >> first;       cout << Get(first) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ReadInput();     Solve();   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   string a[2005];   int common[2005][2005];   int main() {     std::ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         for (int k = 0; k < a[i].size() && k < a[j].size(); k++)           if (a[i][k] == a[j][k])             common[i][j] = k + 1;           else             break;     int ans = 0;     for (int i = 0; i < (1 << n); i++)       if (__builtin_popcount(i) == k) {         int cur = 0;         for (int j = 0; j < n; j++)           if (i & (1 << j))             for (int k = j + 1; k < n; k++)               if (i & (1 << k)) cur += common[j][k];         if (cur > ans) ans = cur;       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void bfs(int v, vector<vector<int> > &graf, vector<vector<int> > &dist) {     queue<int> q;     q.push(v);     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = 0; i < graf[p].size(); i++) {         int to = graf[p][i];         if (dist[v][to] != 1e9) continue;         dist[v][to] = dist[v][p] + 1;         q.push(to);       }     }   }   struct ship {     int pos, attack, fuel;   };   struct base {     int pos, def;   };   vector<bool> used;   vector<int> lnk;   bool dfs(int v, vector<vector<int> > &vv) {     used[v] = 1;     for (int i = 0; i < vv[v].size(); i++) {       int u = vv[v][i];       if (lnk[u] == -1 || !used[lnk[u]] && dfs(lnk[u], vv)) {         lnk[u] = v;         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m;     cin >> n >> m;     vector<vector<int> > dist(n + 1, vector<int>(n + 1, 1e9));     vector<vector<int> > graf(n + 1);     for (int i = 0; i < m; i++) {       int first, t;       cin >> first >> t;       graf[first].push_back(t);       graf[t].push_back(first);     }     for (int i = 1; i <= n; i++) dist[i][i] = 0;     for (int i = 1; i <= n; i++) bfs(i, graf, dist);     int second, b, k, h;     cin >> second >> b >> k >> h;     vector<ship> ships(second);     for (int i = 0; i < second; i++) {       cin >> ships[i].pos >> ships[i].attack >> ships[i].fuel;     }     vector<base> bases(b);     for (int i = 0; i < b; i++) {       cin >> bases[i].pos >> bases[i].def;     }     vector<vector<int> > vv(second);     for (int i = 0; i < second; i++) {       for (int j = 0; j < b; j++) {         int d = dist[ships[i].pos][bases[j].pos];         if (d <= ships[i].fuel && bases[j].def <= ships[i].attack)           vv[i].push_back(j);       }     }     int ans = 0;     used.resize(second);     lnk.resize(b, -1);     for (int i = 0; i < second; i++) {       used.assign(n, 0);       if (dfs(i, vv)) ans++;     }     cout << min(1LL * ans * k, 1LL * second * h);   }
#include <bits/stdc++.h>   using namespace std;   bool chk(int a, int b, int c, int sum) { return a + b + c == sum; }   int main() {     int sum = 0;     vector<int> u(6);     for (int i = 0; i < 6; i++) {       cin >> u[i];       sum += u[i];     }     if (sum % 2) {       cout <<  NO ;       return 0;     }     sum /= 2;     for (int a = 0; a < 6; a++)       for (int b = 0; b < 6; b++)         for (int c = 0; c < 6; c++)           if (a != b && b != c && a != c && u[a] + u[b] + u[c] == sum) {             cout <<  YES ;             return 0;           }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100000], lim, n, flag;   void DFS(long long x, long long y) {     if (x > n) {       if (y == a[lim]) flag = 1;       return;     }     if (flag) return;     DFS(x + 1, y);     if (x != lim) {       DFS(x + 1, y + a[x]);       DFS(x + 1, y - a[x]);     }   }   inline void work() {     lim = flag = n = 0;     memset(a, 0, sizeof(a));     scanf( %lld , &n);     for (register long long i = 1; i <= n; ++i) scanf( %lld , &a[i]);     for (lim = 1; lim <= n; ++lim) {       DFS(1, 0);       if (flag) {         puts( YES );         return;       }     }     puts( NO );   }   signed main() {     long long T;     scanf( %lld , &T);     while (T--) work();   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   vector<long long> prnum;   void sieve() {     bool prime[1000001];     memset(prime, true, sizeof(prime));     for (int i = 2; i * i <= 1000000; i++) {       if (prime[i] == true) {         for (int j = 2 * i; j <= 1000000; j += i) {           prime[j] = false;         }       }     }     for (int i = 2; i <= 1000000; i++) {       if (prime[i]) prnum.push_back(i);     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k >= n) {         cout << 1 <<   n ;       } else {         long long ans = 1000000000;         for (long long i = 1; i * i <= n; i++) {           if (i > k) break;           if (n % i == 0) {             if ((n / i) <= k) {               ans = min(ans, i);             } else {               ans = min(ans, n / i);             }           }         }         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   signed main() {     long long n, sum = 0, temp;     multiset<long long> a;     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> temp;       a.insert(temp);     }     while (a.size() > 1) {       long long temp_sum = 0, sz = a.size();       for (long long j = 0; j < ((sz % 2 == 0) ? 2 : min(3ll, sz)); ++j) {         temp_sum += *a.begin();         a.erase(a.begin());       }       sum += temp_sum;       a.insert(temp_sum);     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ht[300][300], tt[300][300][8], n, m, t, tp, tu, td;   void print(const char *s, int k) {     cout << s << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cout << setw(2) << tt[i][j][k] <<    ;       cout << endl;     }   }   int main() {     int i1, j1, i2, j2, bestDt = 2e9;     cin >> n >> m >> t >> tp >> tu >> td;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> ht[i][j];     for (int i = 0; i < n; ++i) {       tt[i][0][0] = 0;       tt[i][m - 1][2] = 0;       for (int j = 1; j < m; ++j) {         tt[i][j][0] =             tt[i][j - 1][0] + ((ht[i][j - 1]) == (ht[i][j])                                    ? tp                                    : ((ht[i][j - 1]) < (ht[i][j]) ? tu : td));         tt[i][m - 1 - j][2] =             tt[i][m - j][2] +             ((ht[i][m - j]) == (ht[i][m - 1 - j])                  ? tp                  : ((ht[i][m - j]) < (ht[i][m - 1 - j]) ? tu : td));       }     }     for (int j = 0; j < m; ++j) {       tt[0][j][1] = 0;       tt[n - 1][j][3] = 0;       for (int i = 1; i < n; ++i) {         tt[i][j][1] =             tt[i - 1][j][1] + ((ht[i - 1][j]) == (ht[i][j])                                    ? tp                                    : ((ht[i - 1][j]) < (ht[i][j]) ? tu : td));         tt[n - 1 - i][j][3] =             tt[n - i][j][3] +             ((ht[n - i][j]) == (ht[n - 1 - i][j])                  ? tp                  : ((ht[n - i][j]) < (ht[n - 1 - i][j]) ? tu : td));       }     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         tt[i][j][4] = tt[i][j][3] - tt[i][j][0];         tt[i][j][5] = tt[i][j][0] - tt[i][j][1];         tt[i][j][6] = tt[i][j][2] - tt[i][j][3];         tt[i][j][7] = tt[i][j][1] - tt[i][j][2];       }     for (int imin = 0; imin < n; ++imin)       for (int jmin = 0; jmin < m; ++jmin) {         int d1 = tt[imin][jmin][4] - t;         for (int imax = imin + 2; imax < n; ++imax) {           int d2 = d1 + tt[imax][jmin][6];           for (int jmax = jmin + 2; jmax < m; ++jmax) {             int dt = d2 + tt[imin][jmax][5] + tt[imax][jmax][7];             if (abs(dt) < bestDt)               i1 = imin, j1 = jmin, i2 = imax, j2 = jmax, bestDt = abs(dt);           }         }       }     cout << i1 + 1 <<     << j1 + 1 <<     << i2 + 1 <<     << j2 + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void print(T x, char let) {     print(x), putchar(let);   }   const int maxn = 2e5 + 5;   const int mn = (1 << 18) - 1;   int n, a[maxn], b[mn], f[mn], sz[mn];   int find(int k) {     if (f[k] == k) return k;     return f[k] = find(f[k]);   }   void merge(int a, int b) {     int fa = find(a);     int fb = find(b);     if (sz[fa] <= sz[fb]) {       f[fa] = fb;       sz[fb] += sz[fa];     } else {       f[fb] = fa;       sz[fa] += sz[fb];     }   }   int main() {     n = read();     long long sum1 = 0;     for (int i = 1; i <= n; i++) {       a[i] = read();       sum1 += a[i];       b[a[i]]++;     }     b[0]++;     for (int i = 0; i <= mn; i++) f[i] = i;     long long sum = 0;     for (int i = mn; i >= 1; i--) {       if (b[0] > 0 && b[i] > 0 && find(0) != find(i)) {         merge(0, i);         sum += (long long)(b[0] + b[i] - 1) * i;         b[0] = b[i] = 1;       }       for (int j = i; j; j = (j - 1) & i) {         int k = i ^ j;         if (b[j] > 0 && b[k] > 0 && find(j) != find(k)) {           merge(j, k);           sum += (long long)(b[j] + b[k] - 1) * i;           b[j] = b[k] = 1;         }       }     }     cout << sum - sum1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x, y;     cin >> x >> y;     int u = 0, v = 0, turns = 0, flag = 1, c = 1;     while (1) {       if (u == x and v == y) break;       if (flag == 1) {         int d = 0;         while (d != c) {           u++;           if (u == x and v == y) break;           d++;         }         flag = 2;         if (u != x or v != y) turns++;       } else if (flag == 2) {         int d = 0;         while (d != c) {           v++;           if (u == x and v == y) break;           d++;         }         if (u != x or v != y) turns++;         flag = 3;         c++;       } else if (flag == 3) {         int d = 0;         while (d != c) {           u--;           if (u == x and v == y) break;           d++;         }         flag = 4;         if (u != x or v != y) turns++;       } else if (flag == 4) {         int d = 0;         while (d != c) {           v--;           if (u == x and v == y) break;           d++;         }         c++;         flag = 1;         if (u != x or v != y) turns++;       }     }     cout << turns;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string line;     int persons = 0;     int data = 0;     while (getline(cin, line)) {       if (line[0] ==  + )         ++persons;       else if (line[0] ==  - )         --persons;       else         data += (line.size() - line.find( : ) - 1) * persons;     }     cout << data << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int l = 0, u = 0, d = 0;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int l = -1, u = -1, d = -1;       cin >> s;       for (int j = 0; j < s.length(); j++) {         if (isdigit(s[j])) d = j;         if (islower(s[j])) l = j;         if (isupper(s[j])) u = j;       }       if (d == -1)         for (int j = 0; j < s.length(); j++)           if (j != l && j != u) {             s[j] =  4 ;             d = j;             break;           }       if (l == -1)         for (int j = 0; j < s.length(); j++)           if (j != d && j != u) {             s[j] =  a ;             l = j;             break;           }       if (u == -1)         for (int j = 0; j < s.length(); j++)           if (j != l && j != d) {             s[j] =  A ;             u = j;             break;           }       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int count = 0;     cin >> n;     for (int i = 0; i < n; i++) {       string a;       cin >> a;       if (a ==  ABSINTH  || a ==  BEER  || a ==  BRANDY  || a ==  CHAMPAGNE  ||           a ==  GIN  || a ==  RUM  || a ==  SAKE  || a ==  TEQUILA  ||           a ==  VODKA  || a ==  WHISKEY  || a ==  WINE  || a ==  0  || a ==  1  ||           a ==  2  || a ==  3  || a ==  4  || a ==  5  || a ==  6  || a ==  7  ||           a ==  8  || a ==  9  || a ==  10  || a ==  11  || a ==  12  ||           a ==  13  || a ==  14  || a ==  15  || a ==  16  || a ==  17 )         count++;     }     cout << count;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b;     cin >> a >> b;     int c = min(a, b);     a = max(a, b) - c;     cout << c <<     << a / 2;     ;   }   int main() {     int count = 1;     while (count--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modpower(long long n, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = (res * n) % 1000000009;       k >>= 1;       n = (n * n) % 1000000009;     }     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     bool f = 0;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] != 1) f = 1;     }     sort(a, a + n);     if (!f) {       for (long long i = 0; i < n - 1; ++i) {         cout << a[i] <<    ;       }       cout << 2;       return 0;     }     cout << 1 <<    ;     for (long long i = 0; i < n - 1; ++i) {       cout << a[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<vector<int> > g;   vector<int> depth;   void dfs(int v, int d = 0) {     depth[v] = d;     for (int to : g[v]) {       if (depth[to] == -1) {         dfs(to, d + 1);       }     }   }   int main() {     int n, m;     cin >> n >> m;     g.resize(n);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       --u, --v;       g[u].push_back(v);       g[v].push_back(u);     }     depth.assign(n, -1);     dfs(0);     int v = 0;     for (int i = 1; i < n; ++i) {       if (depth[i] > depth[v]) {         v = i;       }     }     depth.assign(n, -1);     dfs(v);     int ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, depth[i]);     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   class strocks {    public:     string strocksguy() {}   };   int main() {     strocks strocks;     iostream::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     string s, d;     unordered_map<string, string> master;     for (long long i = 0; i < m; i++) {       cin >> s >> d;       if (s.size() > d.size()) {         master.insert(make_pair(s, d));       } else         master.insert(make_pair(d, s));     }     for (long long i = 0; i < n; i++) {       cin >> s;       if (master.find(s) != master.end())         cout << master.at(s) <<    ;       else         cout << s <<    ;     }     return 0;   }