malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int TAM = 100000 + 15;   const long long MOD = 1000000007LL;   const double PI = 3.14159265359;   long long add(long long x, long long y) { return (x + y + 2 * MOD) % MOD; }   long long mult(long long x, long long y) {     return (add(x, 0) * add(y, 0)) % MOD;   }   long long fast_expo(long long x, long long y) {     if (x == 0) return 0;     if (y == 0) return 1;     long long res = 1;     long long mid = fast_expo(x, y / 2);     if (y % 2 != 0) res = x;     return mult(mult(mid, mid), res);   }   long long inver(long long x) { return fast_expo(x, MOD - 2); }   long long gcd(long long e1, long long e2) {     if (e2 == 0) return e1;     return gcd(e2, e1 % e2);   }   int n;   map<int, int> mapa[TAM];   int color[TAM];   vector<int> G[TAM];   long long dom[TAM];   int tam[TAM];   int cant[TAM];   void dfs_tam(int u, int pd = -1) {     tam[u] = 1;     for (int v : G[u]) {       if (v != pd) {         dfs_tam(v, u);         tam[u] += tam[v];       }     }   }   void dfs(int u, int pd = -1) {     int m = -1, val = -1;     for (int v : G[u]) {       if (v != pd) {         if (tam[v] > val) {           m = v;           val = tam[v];         }       }     }     if (m == -1) {       mapa[u][color[u]]++;       dom[u] = color[u];       cant[u] = 1;       return;     }     for (int v : G[u]) {       if (v != pd) {         dfs(v, u);       }     }     swap(mapa[u], mapa[m]);     dom[u] = dom[m];     cant[u] = cant[m];     mapa[u][color[u]]++;     if (mapa[u][color[u]] > cant[u]) {       cant[u] = mapa[u][color[u]];       dom[u] = 1LL * color[u];     } else if (mapa[u][color[u]] == cant[u]) {       dom[u] += 1LL * color[u];     }     for (int v : G[u]) {       if (v != pd && v != m) {         int k, t;         for (map<int, int>::iterator it = mapa[v].begin(); it != mapa[v].end();              it++) {           k = it->first;           t = it->second;           mapa[u][k] += t;           if (mapa[u][k] > cant[u]) {             cant[u] = mapa[u][k];             dom[u] = 1LL * k;           } else if (mapa[u][k] == cant[u]) {             dom[u] += 1LL * k;           }         }       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &color[i]);     int u, v;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       G[u - 1].push_back(v - 1);       G[v - 1].push_back(u - 1);     }     dfs_tam(0);     dfs(0);     for (int i = 0; i < n; i++) cout << 1LL * dom[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool compare(pair<int, int> p1, pair<int, int> p2) {     return p1.first > p2.first;   }   long long int power(int a, int b) {     if (b == 0) return 1;     return a * power(a, b - 1);   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n, m;     cin >> n >> m;     int a[n + 1], b[m + 1];     for (int i = 0; i < n + 1; i++) {       cin >> a[i];     }     for (int i = 0; i < m + 1; i++) {       cin >> b[i];     }     if (n > m) {       if (a[0] * b[0] > 0)         cout <<  Infinity ;       else         cout <<  -Infinity ;     } else if (n < m) {       cout <<  0/1 ;     } else {       if (a[0] * b[0] < 0) {         cout <<  - ;       }       cout << abs(a[0]) / gcd(abs(a[0]), abs(b[0])) <<  /             << abs(b[0]) / gcd(abs(a[0]), abs(b[0]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans, i, N, H, alive, last1, last2, last3, a, b, c;   long long A[2][32][32][32], B[2][32][32][32];   int main() {     cin >> N >> H;     A[1][0][0][0] = 4;     for (i = 1; i < N; i++) {       for (alive = 0; alive < 2; alive++)         for (last1 = 0; i - last1 > 0 && last1 < H; last1++)           for (last2 = 0; i - last2 > 0 && last2 < H; last2++)             for (last3 = 0; i - last3 > 0 && last3 < H; last3++) {               if (last1 == 0 || last1 == H - 1)                 a = 0;               else                 a = last1 + 1;               if (last2 == 0 || last2 == H - 1)                 b = 0;               else                 b = last2 + 1;               if (last3 == 0 || last3 == H - 1)                 c = 0;               else                 c = last3 + 1;               B[alive][a][b][c] += A[alive][last1][last2][last3];               B[alive][a][b][c] %= 1000000009;               B[last1 > 0 || i < H][alive][b][c] += A[alive][last1][last2][last3];               B[last1 > 0 || i < H][alive][b][c] %= 1000000009;               B[last2 > 0 || i < H][a][alive][c] += A[alive][last1][last2][last3];               B[last2 > 0 || i < H][a][alive][c] %= 1000000009;               B[last3 > 0 || i < H][a][b][alive] += A[alive][last1][last2][last3];               B[last3 > 0 || i < H][a][b][alive] %= 1000000009;             }       for (alive = 0; alive < 2; alive++)         for (last1 = 0; last1 < H; last1++)           for (last2 = 0; last2 < H; last2++)             for (last3 = 0; last3 < H; last3++) {               A[alive][last1][last2][last3] = B[alive][last1][last2][last3];               B[alive][last1][last2][last3] = 0;             }     }     for (a = 0; a < H; a++)       for (b = 0; b < H; b++)         for (c = 0; c < H; c++) ans = (ans + A[1][a][b][c]) % 1000000009;     for (a = 0; a < H; a++)       for (b = 0; b < H; b++)         for (c = 0; c < H; c++)           if (a > 0 || b > 0 || c > 0) ans = (ans + A[0][a][b][c]) % 1000000009;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e5 + 10;   long long t[2][4 * N], a, b;   void update(int l, int r, int j, int pos, int val) {     if (r < pos || pos < l) return;     if (pos <= l && r <= pos) {       t[0][j] = min(a, t[0][j] + val);       t[1][j] = min(b, t[1][j] + val);       return;     }     int mid = (l + r) >> 1;     update(l, mid, 2 * j, pos, val);     update(mid + 1, r, 2 * j + 1, pos, val);     if (l != r) {       t[0][j] = t[0][2 * j] + t[0][2 * j + 1];       t[1][j] = t[1][2 * j] + t[1][2 * j + 1];     }   }   long long getSum(int l, int r, int j, int x, int y, int wh) {     if (r < x || y < l) return 0LL;     if (x <= l && r <= y) {       return t[wh][j];     }     int mid = (l + r) >> 1;     long long X = getSum(l, mid, (j << 1), x, y, wh);     long long Y = getSum(mid + 1, r, ((j << 1) | 1), x, y, wh);     return X + Y;   }   int n, k, q;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k >> a >> b >> q;     for (int i = 0; i < q; i++) {       int type;       cin >> type;       if (type == 1) {         int di, ai;         cin >> di >> ai;         update(1, n, 1, di, ai);       } else {         int p;         cin >> p;         long long res = getSum(1, n, 1, 1, p - 1, 1);         res += getSum(1, n, 1, p + k, n, 0);         cout << res <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int a[N], b[N];   bool p[N];   vector<int> P;   pair<bool, int> c[N];   int num(string s) {     int x = 0;     for (int i = 1; i < s.size(); i++) x = x * 10 + (s[i] -  0 );     return x;   }   int main() {     int n, m, t = 0, T = 0;     string s;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s;       if (s[0] ==  + ) {         a[num(s)]++;         c[i + 1] = {0, num(s)};       } else {         b[num(s)]++;         t++;         c[i + 1] = {1, num(s)};       }     }     for (int i = 1; i <= n; i++) {       if (a[i] + t - b[i] == m) {         p[i] = 1;         P.push_back(i);         T++;       }     }     if (T == 1) {       for (int i = 1; i <= n; i++) {         if (c[i].first == 0) {           if (c[i].second == P[0]) {             cout <<  Truth n ;           } else {             cout <<  Lie n ;           }         } else {           if (c[i].second == P[0]) {             cout <<  Lie n ;           } else {             cout <<  Truth n ;           }         }       }       return 0;     }     for (int i = 1; i <= n; i++) {       if (c[i].first == 0) {         if (p[c[i].second]) {           cout <<  Not defined n ;         } else {           cout <<  Lie n ;         }       } else {         if (p[c[i].second]) {           cout <<  Not defined n ;         } else {           cout <<  Truth n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, w, m;   double a[100];   int kol[100];   vector<pair<int, double> > v[100];   int main() {     cin >> n >> w >> m;     double q = n * w * 1.0 / m;     memset(kol, 0, sizeof(kol));     for (int i = 0; i < 100; ++i) a[i] = w;     for (int i = 0; i < m; ++i) {       double p = q;       int z = 0;       for (int j = 0; j < n; ++j) {         if (a[j] > 1e-9) {           double temp = min(p, a[j]);           v[i].push_back(make_pair(j + 1, temp));           p -= temp;           a[j] -= temp;           ++z;           ++kol[j];           if (kol[j] > 2) {             cout <<  NO n ;             return 0;           }           if (p < 1e-9) break;         }       }       if (z == 0 || p > 1e-9) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     for (int i = 0; i < m; ++i) {       for (int j = 0; j < v[i].size(); ++j) {         if (j) cout <<    ;         cout << v[i][j].first <<     << fixed << setprecision(10)              << v[i][j].second;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Antenna {     int iniLeft, iniRight;   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int nbAntennas, totLen;     cin >> nbAntennas >> totLen;     vector<Antenna> ants(nbAntennas);     for (int iAnt = 0; iAnt < nbAntennas; ++iAnt) {       int center, iniScope;       cin >> center >> iniScope;       ants[iAnt].iniLeft = max(0, center - iniScope);       ants[iAnt].iniRight = min(totLen, center + iniScope);     }     vector<int> minCost(totLen + 1);     minCost[totLen] = 0;     for (int pos = totLen - 1; pos >= 0; --pos) {       minCost[pos] = (totLen - pos);       for (int iAnt = 0; iAnt < nbAntennas; ++iAnt) {         int left = ants[iAnt].iniLeft, right = ants[iAnt].iniRight;         if (left <= pos + 1 && pos + 1 <= right) {           minCost[pos] = minCost[pos + 1];           break;         }         if (pos < left) {           int accessCost = (left - pos - 1);           int nextPos = min(totLen, right + accessCost);           minCost[pos] = min(minCost[pos], accessCost + minCost[nextPos]);         }       }     }     cout << minCost[0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ll n, m, k;     cin >> n >> m >> k;     vector<ll> vec(m);     for (ll &v : vec) cin >> v;     ll ans = 0, i = 0;     while (i < m) {       ll t = (vec[i] - i - 1) / k, j = i + 1;       while (j < m && (vec[j] - i - 1) / k == t) j++;       ans++, i = j;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[2222], n;   int D[2222];   int Find(int x) {     if (D[x] != 0) return D[x];     if (p[x] == -1)       return D[x] = 1;     else       return D[x] = Find(p[x]) + 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     int ans = 0, tmp;     for (int i = 1; i <= n; i++) {       tmp = Find(i);       if (tmp > ans) ans = tmp;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   #define f(i,q,n) for(int i=(int)q;i<n;i++)   #define pb push_back   #define debug(x) cout<<#x<<   <<x<<endl;   int main()   {       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);       int t=1;       cin>>t;       while(t--){           int n,m;           cin>>n>>m;           string s;           cin>>s;           while(m--){           string ans=s;           f(i,0,n){               if(i==0 and ans[i]== 0  and ans[i+1]== 1 ){s[i]= 1 ;}               else if(i==n-1 and ans[i]== 0  and ans[i-1]== 1 ){s[i]= 1 ;}               else{                   if(i<n-1 and i>0 and ans[i]== 0  and ans[i+1]!=ans[i-1]){                       s[i]= 1 ;                   }               }           }           if(s==ans){               break;           }                 }                  cout<<s<<endl;          }       return 0;   }   //check constraints, testcases, ll vs int
#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long a[200005];   struct poi {     long long val;     int pos;   } tp;   bool operator<(const poi &a, const poi &b) {     return (a.val > b.val) || (a.val == b.val and a.pos > b.pos);   }   priority_queue<poi> q;   int main() {     int n;     int cnt = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       tp.val = a[i];       tp.pos = i;       q.push(tp);     }     while (!q.empty()) {       poi a1 = q.top();       q.pop();       poi b1 = q.top();       q.pop();       while (!q.empty() && a1.val != b1.val) {         a1 = b1;         b1 = q.top();         q.pop();       }       if (a1.val == b1.val and a1.pos != b1.pos) {         a[b1.pos] = b1.val * 2;         b1.val = b1.val * 2;         a[a1.pos] = -1;         cnt++;         if (q.empty()) break;         q.push(b1);       }     }     printf( %d n , n - cnt);     for (int i = 0; i < n; i++) {       if (a[i] != -1) printf( %lld  , a[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   string str;   const long long MOD = 1e9 + 7;   template <class T>   inline void amin(T &x, const T &y) {     if (y < x) x = y;   }   template <class T>   inline void amax(T &x, const T &y) {     if (x < y) x = y;   }   int read() {     long long s = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = s * 10 + c -  0 ;       c = getchar();     }     return s * f;   }   long long Pow(long long a, long long b) {     if (a == 1 || b == 1) return a;     if (b % 2 == 1) return (a * Pow(a, b - 1)) % MOD;     return (Pow(a, b / 2) * Pow(a, b / 2)) % MOD;   }   long long factorial(long long n) {     long long ans = 1;     while (--n) ans = (ans * (n + 1)) % MOD;     return ans;   }   vector<bool> b(12, 0);   bool binod(int k) {     bool arr[13][13];     memset(arr, 0, sizeof(arr));     int a = 0;     for (int i = 0; i < k; i++)       for (int j = 0; j < 12 / k; j++) {         arr[i][j] = b[a];         a++;       }     a = 0;     bool d;     for (int j = 0; j < 12 / k; j++) {       d = 1;       for (int i = 0; i < k; i++) {         if (!arr[i][j]) d = 0;       }       if (d) return 1;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       for (int i = 0; i < 12; i++) {         char sign;         cin >> sign;         if (sign ==  X )           b[i] = 1;         else           b[i] = 0;       }       vector<int> v;       if (binod(1)) v.push_back(1);       if (binod(2)) v.push_back(2);       if (binod(3)) v.push_back(3);       if (binod(4)) v.push_back(4);       if (binod(6)) v.push_back(6);       if (binod(12)) v.push_back(12);       cout << v.size() <<    ;       for (int i = 0; i < v.size(); i++) {         cout << v[i] <<  x  << 12 / v[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str;   int make(int star, int en) {     if (en - star >= 7) return -1e7;     if (en - star >= 1 && str[star] ==  0 ) return -1e7;     if (str[star] ==  0  && str[en] !=  0 ) return -1e7;     int sum = 0;     for (int i = star; i <= en; i++) {       sum = sum * 10 + (str[i] -  0 );     }     if (sum > 1e6) return -1e7;     return sum;   }   int main() {     int m = -1, i, j, len, a, b, c;     cin >> str;     len = str.length();     for (i = 0; i < len - 2; i++) {       for (j = i + 1; j < len - 1; j++) {         a = make(0, i);         b = make(i + 1, j);         c = make(j + 1, len - 1);         m = max(m, a + b + c);       }     }     if (m < 0)       printf( -1 );     else       printf( %d , m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-9;   static const double PI = acos(-1.0);   char ans[4][110];   int main() {     int n;     while (scanf( %d , &n) > 0) {       if (n == 1) {         printf( a na nb nb n );         continue;       }       ans[0][0] =  a ;       ans[1][0] =  a ;       ans[2][0] =  b ;       ans[3][0] =  c ;       int ud = 2;       char p =  b ;       for (int i = 1; i < n; i++) {         ans[ud][i] = p;         ans[ud + 1][i] = p + 1;         p += 2;         if (p >=  x ) {           p =  a ;         }         ud ^= 2;         if (i == n - 1) {           ans[ud][i] = p;           ans[ud + 1][i] = p;         } else {           ans[ud][i] = p;           ans[ud + 1][i] = p + 1;         }       }       for (int y = 0; y < (int)(4); y++) {         for (int x = 0; x < (int)(n); x++) {           putchar(ans[y][x]);         }         puts(  );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a;     vector<pair<int, int> > v;     cin >> n;     for (i = 0; i < n; ++i) {       cin >> a;       v.push_back(make_pair(a, i + 1));     }     for (i = 0; i < n; ++i) {       cin >> a;       v.push_back(make_pair(a, i + 1));     }     long long m;     cin >> m;     m *= 2;     sort(v.begin(), v.end());     long long r = 1;     int c = 0, c1 = 0;     for (i = 1; i < n + n; ++i) {       if (v[i].first == v[i - 1].first) {         ++c;         if (v[i].second == v[i - 1].second) {           ++c1;         } else           c1 = 0;       } else {         c1 = c = 0;       }       r = (r * (c + 1) / (c1 + 1)) % m;       c1 = 0;     }     cout << r % (m / 2);     return 0;   }   int cpp4cf_main() {     freopen( B.cpp ,  r , stdin);     char s[99];     bool f;     while (true) {       cin >> s;       if (cin.eof()) break;       if (strstr(s,  /* )) {         cin >> s;         if (strstr(s,  Test )) {           cin >> s;           if (strstr(s,  on )) {             cout <<  Output:  ;             cpp4cf_main();             cout <<   nAnswer:  ;             f = false;             while (true) {               cin >> s;               if (strstr(s,  */ )) break;               if (strstr(s,  // )) {                 if (f)                   cout << endl;                 else                   f = true;               } else                 cout << s <<    ;             }             cout <<   n n ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     map<long long, long long> mp;     long long ans = 0;     long long prev = 0;     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += a[i];       if (sum == 0)         prev = max(prev, mp[0] + 1);       else if (mp.find(sum) != mp.end())         prev = max(prev, mp[sum] + 1);       ans += i + 1 - prev;       mp[sum] = i + 1;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const bool debug = 0;   struct mout {     int i, j;     long long first;     mout(){};     mout(int i, int j, long long first) : i(i), j(j), first(first) {}   };   int main() {     if (!debug) {       cin.tie(0);       cout.tie(0);       ios::sync_with_stdio(0);     }     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long> a(n);       vector<mout> out;       for (int i = 0; i < n; i++) cin >> a[i];       long long s = 0;       for (int i = 0; i < n; i++) s += a[i];       if (s != (s / n) * n) {         cout <<  -1 n ;         continue;       }       s /= n;       for (int i = 1; i < n; i++) {         if (a[i] % (i + 1) != 0) {           out.push_back({1, i + 1, i + 1 - a[i] % (i + 1)});           a[1] -= i + 1 - a[i] % (i + 1);           a[i] += i + 1 - a[i] % (i + 1);         }         out.push_back({i + 1, 1, a[i] / (i + 1)});         a[1] += a[i];         a[i] = 0;       }       for (int i = 1; i < n; i++) {         out.push_back({1, i + 1, s});       }       cout << out.size() <<   n ;       for (int i = 0; i < out.size(); i++)         cout << out[i].i <<     << out[i].j <<     << out[i].first <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e14;   const long long TE3 = 1005;   const long long TE5 = 300005;   const string YN[2] = { NO ,  YES };   using namespace std;   long long f(long long n, vector<long long>& q1, vector<long long>& q2) {     unordered_map<long long, long long> e;     long long c = 0;     e[0] = -1;     long long i = 0, j = 0;     long long ans = 0;     while (i < q1.size() || j < q2.size()) {       long long g;       long long q1t = (i >= q1.size()) ? INF : q1[i];       long long q2t = (j >= q2.size()) ? INF : q2[j];       if (q1t < q2t) {         g = q1t;         ++c;         ++i;       } else {         g = q2t;         --c;         ++j;       }       if (e.find(c) == e.end()) {         e[c] = g;       } else {         q2t = (j >= q2.size()) ? INF : q2[j];         q1t = (i >= q1.size()) ? INF : q1[i];         long long tmp = min(q1t, q2t);         long long cur = (tmp == INF ? n : tmp) - e[c] - 1;         ans = max(ans, cur);       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     long long x;     unordered_map<long long, vector<long long> > mpq;     for (long long i = (0); i < (n); ++i) {       cin >> x;       mpq[x].push_back(i);     }     if (mpq.size() == 1) {       cout << 0 << endl;       return 0;     }     unordered_map<long long, long long> rev;     long long ma = -INF, mo = 0;     for (auto it : mpq) {       rev[it.second.size()]++;       if (it.second.size() > mo) {         ma = it.first;         mo = it.second.size();       }     }     if (rev[mo] >= 2) {       cout << n << endl;       return 0;     }     long long ans = 0;     for (auto it : mpq) {       if (it.first == ma) continue;       ans = max(ans, f(n, mpq[ma], it.second));     }     cout << ans << endl;     return 0;   }