malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const double eps = 1e-9;   const int N = 1 << 19;   const int P = (int)1e9 + 7;   const int Z = 239;   inline int add(int a, int b) {     a += b;     if (a >= P) a -= P;     return a;   }   int powP[2 * N];   inline int shift(int a, int n) { return (a * (long long)powP[n]) % P; }   int hash1[2 * N];   int hash2[2 * N];   int len[2 * N];   inline void upd(int x, int dx) {     x += N;     hash1[x] = dx;     hash2[x] = dx;     while (x > 1) {       x >>= 1;       hash1[x] = add(hash1[2 * x], shift(hash1[2 * x + 1], len[2 * x]));       hash2[x] = add(hash2[2 * x + 1], shift(hash2[2 * x], len[2 * x]));     }   }   int vleft[2 * N], vleftc = 0;   int vright[2 * N], vrightc = 0;   inline int get1(int l, int r) {     if (l > r) return 0;     l += N;     r += N;     vleftc = 0;     vrightc = 0;     while (l <= r) {       if ((l & 1) == 1) vleft[vleftc++] = l;       if ((r & 1) == 0) vright[vrightc++] = r;       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     int res = 0;     int toshift = 0;     for (int i = 0; i < vleftc; ++i) {       int v = vleft[i];       res = add(res, shift(hash1[v], toshift));       toshift += len[v];     }     for (int i = vrightc - 1; i >= 0; --i) {       int v = vright[i];       res = add(res, shift(hash1[v], toshift));       toshift += len[v];     }     return res;   }   inline int get2(int l, int r) {     if (l > r) return 0;     l += N;     r += N;     vleftc = 0;     vrightc = 0;     while (l <= r) {       if ((l & 1) == 1) vleft[vleftc++] = l;       if ((r & 1) == 0) vright[vrightc++] = r;       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     int res = 0;     int toshift = 0;     for (int i = 0; i < vrightc; ++i) {       int v = vright[i];       res = add(res, shift(hash2[v], toshift));       toshift += len[v];     }     for (int i = vleftc - 1; i >= 0; --i) {       int v = vleft[i];       res = add(res, shift(hash2[v], toshift));       toshift += len[v];     }     return res;   }   int a[N];   int main() {     powP[0] = 1;     for (int i = 1; i <= N; ++i) powP[i] = (powP[i - 1] * (long long)Z) % P;     for (int i = 2 * N - 1; i >= 1; --i) {       if (i >= N)         len[i] = 1;       else         len[i] = 2 * len[2 * i];     }     int n;     scanf( %d , &n);     for (int i = 0; (i) < (n); ++i) scanf( %d , &a[i]);     for (int i = 0; (i) < (n); ++i) a[i] -= 1;     bool res = false;     for (int i = 0; (i) < (n); ++i) {       int val = a[i];       if (val <= n - val - 1) {         int left = get1(0, val - 1);         int right = get2(val + 1, 2 * val);         if (left != right) {           res = true;         }       } else {         int left = get1(val - (n - 1 - val), val - 1);         int right = get2(val + 1, n - 1);         if (left != right) {           res = true;         }       }       upd(val, 1);     }     if (res)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int a[n], sum = 0;     vector<int> v;     vector<int> u;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];       if (a[i] > 0)         u.push_back(a[i]);       else         v.push_back(0 - a[i]);     }     if (sum > 0)       cout <<  first ;     else if (sum < 0)       cout <<  second ;     else {       int f = 0, m = u.size();       if (m > v.size()) m = v.size();       for (int i = 0; i < m; i++) {         if (v[i] < u[i]) {           f = 1;           break;         } else if (v[i] > u[i]) {           f = 2;           break;         }       }       if (!f) {         if (u.size() > v.size())           f = 1;         else if (u.size() < v.size())           f = 2;         else {           if (a[n - 1] > 0)             f = 1;           else             f = 2;         }       }       if (f == 1)         cout <<  first ;       else         cout <<  second ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a1, a2, b1, b2, c1, c2;     while (scanf( %d%d%d%d%d%d , &a1, &b1, &c1, &a2, &b2, &c2) != EOF) {       if (a1 == 0 && b1 == 0 && c1 != 0) {         printf( 0 n );         continue;       }       if (a2 == 0 && b2 == 0 && c2 != 0) {         printf( 0 n );         continue;       }       if ((a1 == 0 && b1 == 0 && c1 == 0) || (a2 == 0 && b2 == 0 && c2 == 0)) {         printf( -1 n );         continue;       }       if (a1 == 0 && a2 == 0) {         if (c1 * b2 == c2 * b1) {           printf( -1 n );         } else {           printf( 0 n );         }         continue;       }       if (b1 == 0 && b2 == 0) {         if (c1 * a2 == c2 * a1) {           printf( -1 n );         } else {           printf( 0 n );         }         continue;       }       if (a1 == 0 && b1 != 0) {         printf( 1 n );         continue;       }       if (a1 != 0 && b1 == 0) {         printf( 1 n );         continue;       }       if (a2 == 0 && b2 != 0) {         printf( 1 n );         continue;       }       if (a2 != 0 && b2 == 0) {         printf( 1 n );         continue;       }       if (a1 * b2 == a2 * b1) {         if (fabs(c1 * 1.0 / b1 - c2 * 1.0 / b2) < 1e-8) {           printf( -1 n );         } else {           printf( 0 n );         }       } else {         printf( 1 n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string sub;     for (int i = 0; i < k; i++) {       sub.push_back( k );     }     long long int count = 0;     set<string> arra;     for (int i = 0; i < n; i++) {       string a;       cin >> a;       arra.insert(a);     }     set<string>::iterator it1, it2;     for (it1 = arra.begin(); it1 != arra.end(); it1++) {       for (it2 = arra.begin(); it2 != arra.end(); it2++) {         string a = *it1;         string b = *it2;         if (a != b) {           for (int i = 0; i < k; i++) {             if (a[i] == b[i]) {               sub[i] = a[i];             } else if ((a[i] ==  S  && b[i] ==  T ) ||                        (a[i] ==  T  && b[i] ==  S )) {               sub[i] =  E ;             } else if ((a[i] ==  S  && b[i] ==  E ) ||                        (a[i] ==  E  && b[i] ==  S )) {               sub[i] =  T ;             } else if ((a[i] ==  E  && b[i] ==  T ) ||                        (a[i] ==  T  && b[i] ==  E )) {               sub[i] =  S ;             }           }           if (arra.find(sub) != arra.end()) {             count++;           }         }       }     }     cout << count / 6 << endl;   }
#include <bits/stdc++.h>   int a[100], i, j, maxim, h, l, n, b;   int main() {     scanf( %d , &n);     scanf( %d , &l);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     i = 0;     j = 0;     b = 0;     h = l;     maxim = l;     while (i < n) {       if (l % a[i] == 0) {         h = l / a[i];       }       if (h < maxim) maxim = h;       i++;     }     printf( %d , maxim);   }
#include <bits/stdc++.h>   using namespace std;   int b[255];   int main() {     string a;     cin >> a;     for (int i = 0; i < a.size(); i++) {       b[a[i]]++;     }     int u = b[ a ] - 1 + b[ a ];     int u2 = a.size();     cout << min(u, u2);     return 0;   }
#include <bits/stdc++.h>   #define ll long long   #define real long double   #define fr(i,l,n) for(ll i=l;i<n;i++)   #define br cout<<  n    #define al(fu) (fu).begin(), (fu).end()   #define prl(c) cout<<(c)<<  n    #define prv(v) {fr(qz,0,v.size()) cout<<(v)[qz]<<   ; br;}   #define alr(fu) (fu).rbegin(), (fu).rend()   #define mod 1000000007LL   #define mod1 998244353LL   #define nfi 1000000000000000013LL   #define skoree ios::sync_with_stdio(0); cin.tie(0)   #define danet(b) cout<<(b? YES : NO )   #define Danet(b) cout<<(b? Yes : No )   using namespace std;      char aq(char a){       if(a== 0 ) return  1 ;       else return  0 ;   }      int main(){       skoree;       ll o0o;       cin>>o0o;       while(o0o--){           ll n;           cin>>n;           vector<string> a(n),b(n);           fr(i,0,n) cin>>a[i];           fr(i,0,n) cin>>b[i];           fr(i,0,n) if(a[0][i]!=b[0][i]){               fr(j,0,n) a[j][i]=aq(a[j][i]);           }           bool bb=1;           fr(i,1,n) if(a[i]!=b[i]){               fr(j,0,n) a[i][j]=aq(a[i][j]);               if(a[i]!=b[i]) bb=0;           }           danet(bb);br;       }       return 0;   }   /*   */
#include <bits/stdc++.h>   using namespace std;   void fastIO() {     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   template <typename T, typename U>   inline void mnze(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   inline void mxze(T &x, U y) {     if (x < y) x = y;   }   void _scan(int &x) { scanf( %d , &x); }   void _scan(long long &x) { scanf( %lld , &x); }   void _scan(double &x) { scanf( %lf , &x); }   void _scan(char &x) { scanf(  %c , &x); }   void _scan(char *x) { scanf( %s , x); }   template <typename T>   void _scan(vector<T> &v) {     for (int i = 0; i < (int)v.size(); i++) _scan(v[i]);   }   void scan() {}   template <typename T, typename... U>   void scan(T &head, U &...tail) {     _scan(head);     scan(tail...);   }   template <typename T>   void _dbg(const char *sdbg, T h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <typename T, typename... U>   void _dbg(const char *sdbg, T h, U... t) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, t...);   }   long long MOD = 1e9 + 7;   inline long long Msum(long long x) { return x; }   template <typename... Rest>   inline long long Msum(long long x, Rest... rest) {     return (x + Msum(rest...)) % MOD;   }   inline long long Mprod(long long x) { return x; }   template <typename... Rest>   inline long long Mprod(long long x, Rest... rest) {     return x * Mprod(rest...) % MOD;   }   inline long long Mnorm(long long x) { return (x % MOD + MOD) % MOD; }   inline long long Msq(long long x) { return (x * x) % MOD; }   inline long long Mpot(long long x, long long e) {     if (!e) return 1;     return Msq(Mpot(x, e >> 1)) * (e & 1 ? x : 1) % MOD;   }   const int MAXN = 2e3 + 3;   char g[MAXN][MAXN];   int x[MAXN][MAXN];   int R, C;   int main() {     scan(R, C);     for (int r = 0; r < R; r++) scan(g[r]);     for (int r = R - 1; r > -1; r--) {       for (int c = 0; c < C; c++) {         x[r][c] = 1;         char cc = g[r][c];         if (r + 2 >= R) continue;         if (g[r + 1][c] != cc) continue;         if (g[r + 2][c] != cc) continue;         if (c - 1 < 0) continue;         if (g[r + 1][c - 1] != cc) continue;         if (c + 1 >= C) continue;         if (g[r + 1][c + 1] != cc) continue;         x[r][c] = min(x[r + 2][c], min(x[r + 1][c - 1], x[r + 1][c + 1])) + 1;       }     }     long long ans = 0;     for (int r = R - 1; r > -1; r--)       for (int c = 0; c < C; c++) {         ans += x[r][c];       }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int inf = (1e9) + 7;   int mod = 998244353;   int c(int num, int div) { return (num + div - 1) / div; }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int nr = 2 * n;     int ng = 5 * n;     int nb = 8 * n;     printf( %d n , c(nr, k) + c(ng, k) + c(nb, k));   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   const double eps = 1e-10;   const int max_index = 62;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   inline int read() {     char c = getchar();     while (!isdigit(c)) c = getchar();     int x = 0;     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   int N, n, m, K;   long long dp[55][55][1110];   long long C[55][55];   int main() {     scanf( %d%d , &N, &K);     n = m = 0;     for (int i = 0; i < N; i++) {       int x = read();       if (x == 50)         n++;       else         m++;     }     for (int i = 0; i <= 50; i++) C[i][0] = 1, C[i][i] = 1;     for (int i = 0; i <= 50; i++) {       for (int j = 1; j < i; j++) {         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;       }     }     dp[n][m][0] = 1;     for (int k = 1; k < 200 && dp[0][0][k - 1] == 0; k++) {       bool flag = 0;       for (int i = 0; i <= n; i++) {         for (int j = 0; j <= m; j++) {           if (k & 1) {             for (int a = 0; a * 50 <= K && a + i <= n; a++) {               for (int b = 0; b * 100 + a * 50 <= K && b + j <= m; b++) {                 if (a == 0 && b == 0) continue;                 long long tmp = dp[i + a][j + b][k - 1] * C[i + a][a] % MOD *                                 C[j + b][b] % MOD;                 dp[i][j][k] = (dp[i][j][k] + tmp) % MOD;               }             }           } else {             for (int a = 0; a * 50 <= K && a <= i; a++) {               for (int b = 0; b * 100 + a * 50 <= K && b <= j; b++) {                 if (a == 0 && b == 0) continue;                 long long tmp = dp[i - a][j - b][k - 1] * C[n - i + a][a] % MOD *                                 C[m - j + b][b] % MOD;                 dp[i][j][k] = (dp[i][j][k] + tmp) % MOD;               }             }           }         }       }     }     int k = 0;     while (dp[0][0][k] == 0 && k < 200) k++;     if (k >= 200)       puts( -1 n0 );     else       cout << k <<   n  << dp[0][0][k] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1100000000000000000;   void solve() {     long long n, k;     cin >> n >> k;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long dp[k + 5][k + 5];     memset(dp, 0, sizeof(dp));     long long x = n % k, c = (n + k - 1) / k, s = n / k;     ;     long long y = k - x;     for (long long i = 0; i <= x; i++)       for (long long j = 0; j <= y; j++) dp[i][j] = inf;     dp[0][0] = 0;     for (long long i = 0; i <= x; i++) {       if (i)         for (long long j = 0; j <= y; j++) {           long long idx = (i - 1) * c + s * j;           dp[i][j] = min(dp[i][j], abs(a[idx + c - 1] - a[idx]) + dp[i - 1][j]);         }       for (long long j = 1; j <= y; j++) {         long long idx = i * c + s * (j - 1);         dp[i][j] = min(dp[i][j], abs(a[idx + s - 1] - a[idx]) + dp[i][j - 1]);       }     }     cout << dp[x][y];   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     long long T = 1;     while (T--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 3005;   int n, D, h[N], nxt[N], adj[N], fa[N], t, f[N][N], inv[N], ifac[N], C[N][N],       g[N], s[N][N];   inline void dfs(const int x) {     for (register int i = 1; i <= n; ++i) f[x][i] = 1;     for (register int i = h[x], j, v; i; i = nxt[i])       for (dfs(v = adj[i]), j = 1; j <= n; ++j)         f[x][j] = (0ll + f[x][j]) * s[v][j] % 1000000007;     for (register int i = 1; i <= n; ++i)       s[x][i] = s[x][i - 1] + f[x][i],       s[x][i] >= 1000000007 ? s[x][i] -= 1000000007 : 0;   }   int main() {     scanf( %d%d , &n, &D);     register int i, j;     auto add = [&](const int u, const int v) {       nxt[++t] = h[u], h[u] = t, adj[t] = v;     };     for (i = 2; i <= n; ++i) scanf( %d , &fa[i]), add(fa[i], i);     for (i = 2, inv[0] = inv[1] = ifac[0] = ifac[1] = 1; i <= n; ++i)       inv[i] = (0ll + inv[1000000007 % i]) * (1000000007 - 1000000007 / i) %                1000000007,       ifac[i] = (0ll + ifac[i - 1]) * inv[i] % 1000000007;     for (i = C[0][0] = 1; i <= n; ++i)       for (j = C[i][0] = C[i][i] = 1; j < i; ++j)         C[i][j] = C[i - 1][j] + C[i - 1][j - 1],         C[i][j] >= 1000000007 ? C[i][j] -= 1000000007 : 0;     dfs(1);     register int ans = 0, o;     for (i = 1; i <= n; ++i)       for (j = 1, g[i] = f[1][i]; j < i; ++j)         g[i] = (g[i] - (0ll + C[i - 1][j - 1]) * g[j]) % 1000000007,         g[i] < 0 ? g[i] += 1000000007 : 0;     for (i = 1; i <= n; ans = (ans + (0ll + o) * g[i]) % 1000000007, ++i)       for (j = D - i + 1, o = ifac[i]; j <= D; ++j)         o = (0ll + o) * j % 1000000007;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], ans[100005];   int main() {     int n, a1, a2, num = 0, gg = 0, t = 0;     cin >> n;     bool ty = true, zz = true;     for (int i = 1; i <= n - 1; ++i) {       cin >> a1 >> a2;       a[a1]++;       a[a2]++;     }     for (int i = 1; i <= n; ++i) {       if (a[i] > 2) {         num++;         gg = i;       }       if (num > 1) {         ty = false;         break;       } else if (a[i] == 1) {         ans[i] = i;         t++;       }     }     if (!ty) {       cout <<  No  << endl;     } else {       cout <<  Yes  << endl;       if (num == 1) {         cout << t << endl;         for (int i = 1; i <= n; ++i) {           if (ans[i] != 0) {             cout << gg <<     << ans[i] << endl;           }         }       } else {         cout << 1 << endl;         for (int i = 1; i <= n; ++i) {           if (ans[i] != 0 && zz) {             cout << ans[i] <<    ;             zz = false;           } else if (ans[i] != 0 && !zz) {             cout << ans[i] << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 10, mod = 2147493647;   string a[5];   char str[5][100010];   map<string, int> ans;   int main() {     for (int i = 0; i < 3; i++) scanf( %s , &str[i]);     for (int i = 0; i < 3; i++) {       int len = strlen(str[i]);       for (int j = 0; j < len; j++) {         if (str[i][j] >=  a  && str[i][j] <=  z ) a[i] += str[i][j];         if (str[i][j] >=  A  && str[i][j] <=  Z ) a[i] += str[i][j] -  A  +  a ;       }     }     ans[a[0]] = 1;     ans[a[1]] = 1;     ans[a[2]] = 1;     ans[a[0] + a[1]] = 1;     ans[a[1] + a[0]] = 1;     ans[a[0] + a[2]] = 1;     ans[a[2] + a[0]] = 1;     ans[a[1] + a[2]] = 1;     ans[a[2] + a[1]] = 1;     ans[a[0] + a[1] + a[2]] = 1;     ans[a[0] + a[2] + a[1]] = 1;     ans[a[1] + a[0] + a[2]] = 1;     ans[a[1] + a[2] + a[0]] = 1;     ans[a[2] + a[0] + a[1]] = 1;     ans[a[2] + a[1] + a[0]] = 1;     int q;     scanf( %d , &q);     while (q--) {       string k =   ;       scanf( %s , str[4]);       int len = strlen(str[4]);       for (int i = 0; i < len; i++) {         if (str[4][i] >=  a  && str[4][i] <=  z ) k += str[4][i];         if (str[4][i] >=  A  && str[4][i] <=  Z ) k += str[4][i] -  A  +  a ;       }       if (ans[k])         printf( ACC n );       else         printf( WA n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<long long, int> > v;   vector<int> lef, rig;   long long pitaj(int t, int a, int b, int c) {     long long res;     cout << 3 - t <<     << a <<     << b <<     << c << endl;     cin >> res;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int ind = 2;     for (int i = 3; i <= n; i++) {       if (pitaj(1, 1, i, ind) == 1) ind = i;     }     for (int i = 2; i <= n; i++) {       if (i == ind) continue;       v.push_back({pitaj(2, 1, ind, i), i});     }     sort(v.begin(), v.end());     for (int i = 1; i < v.size(); i++) {       if (pitaj(1, 1, v[i - 1].second, v[i].second) == 1) {         lef.push_back(v[i - 1].second);       } else {         rig.push_back(v[i - 1].second);       }     }     lef.push_back(v.back().second);     cout << 0 <<     << 1 <<     << ind <<    ;     for (int i = 0; i < lef.size(); i++) cout << lef[i] <<    ;     for (int i = (int)rig.size() - 1; i >= 0; i--) cout << rig[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-06;   int main() {     double t, s, q;     scanf( %lf%lf%lf , &t, &s, &q);     double v = (q - 1.0) / q;     int cnt = 1;     while (true) {       s = s / (1 - v);       if (s > t - eps) break;       cnt++;     }     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x, a, b, mx = 2500, Mx = -2500, my = 2500, My = -2500, ans;   int main() {     cin >> x;     for (int i = 1; i <= x; i++) {       cin >> a >> b;       mx = min(mx, a);       Mx = max(Mx, a);       my = min(my, b);       My = max(My, b);     }     if (x == 1 || mx == Mx || my == My) {       cout << -1 << endl;     } else {       ans = (Mx - mx) * (My - my);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;   int main() {     int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       a++;       if (a > n) a = 1;       b--;       if (b < 1) b = n;       if (a == b) {         printf( YES );         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   int a, b, c, d, e, f, g;   int main() {     scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f);     if (e > f) ans += min(a, d);     a -= ans, d -= ans;     ans *= e;     g = min(min(b, c), d);     ans += f * g;     b -= g, c -= g, d -= g;     ans += e * min(a, d);     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int M = 1e7 + 1;   ;   const long long INF = 2e9 + 10;   const long long MOD = 1000 * 1000 * 1000 + 7;   const long double EPS = 1e-9;   int a[N];   bool prime(int x) {     for (int i = 2; i < (int)sqrt(x) + 1; ++i)       if (x % i == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     if (prime(n))       cout << 1;     else if (prime(n - 2))       cout << 2;     else if (n % 2 == 0)       cout << 2;     else       cout << 3;   }