malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   int n, m, cnt, k;   struct node {     int l, r, sum = 1999999999;   } g[maxn * 20];   inline int read() {     register int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   struct value {     int x, y, id;   } x[maxn];   bool cmp(value v1, value v2) { return v1.x > v2.x; }   int root[maxn];   void update(int num, int wht, int &rt, int l, int r) {     g[++cnt] = g[rt];     if (l == r) {       g[cnt].sum = min(g[rt].sum, wht);       rt = cnt;       return;     }     rt = cnt;     int mid = l + r >> 1;     if (num <= mid)       update(num, wht, g[rt].l, l, mid);     else       update(num, wht, g[rt].r, mid + 1, r);     g[rt].sum = max(g[g[rt].l].sum, g[g[rt].r].sum);   }   int query(int rt, int l, int r, int lb, int rb) {     if (lb >= l && rb <= r) return g[rt].sum;     if (lb > r || l > rb) return -1999999999;     int mid = lb + rb >> 1;     return max(query(g[rt].l, l, r, lb, mid), query(g[rt].r, l, r, mid + 1, rb));   }   int main() {     cnt = 1;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       x[i].x = read(), x[i].y = read(), x[i].id = read();     }     sort(x + 1, x + 1 + k, cmp);     for (int i = 1; i <= k; i++) {       root[i] = root[i - 1];       update(x[i].id, x[i].y, root[i], 1, n);     }     while (m--) {       int A = read(), B = read(), X = read(), Y = read();       int lb = 1, asn = -1, rb = k;       while (lb <= rb) {         int mid = lb + rb >> 1;         if (x[mid].x >= X) {           lb = mid + 1;           asn = mid;         } else {           rb = mid - 1;         }       }       int ans = query(root[asn], A, B, 1, n);       if (ans <= Y)         printf( yes n );       else         printf( no n );       fflush(stdout);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     cin >> n;     vector<int> adj[n];     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);       k = max(k, max((int)adj[u].size(), (int)adj[v].size()) + 1);     }     cout << k << endl;     int nd_clr[n], prnt[n];     queue<int> Q;     Q.push(0);     nd_clr[0] = 0;     prnt[0] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       int clr = nd_clr[u];       for (int i = 0; i < adj[u].size(); i++) {         int v = adj[u][i];         if (v != prnt[u]) {           int c = (clr + 1) % k;           if (c == nd_clr[prnt[u]]) c = (c + 1) % k;           nd_clr[v] = c;           clr = c;           prnt[v] = u;           Q.push(v);         }       }     }     for (int i = 0; i < n; i++) cout << nd_clr[i] + 1 <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       long long n;       cin >> n;       long long s = sqrt(n);       long long c = cbrt(n);       long long p = sqrt(cbrt(n));       cout << s + c - p <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0, f = 1;     char ch;     while (ch = getchar(), ch <  0  || ch >  9 )       if (ch ==  - ) f = -1;     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * f;   }   const int N = 14, M = 4782969, P = 1e9 + 7;   inline int qpow(int a, int b) {     int ans = 1, base = a;     while (b) {       if (b & 1) ans = 1ll * ans * base % P;       base = 1ll * base * base % P;       b >>= 1;     }     return ans;   }   int rev[1 << N], cnt[1 << N], n, A, a[N];   int F[1 << N], G[1 << N], v[N][1 << N];   inline int get(int S, int T) {     if (!S) return 1;     if (G[S]) return G[S];     return G[S] = 1ll * get(S & (S - 1), T) * v[rev[S & -S]][T] % P;   }   int main() {     n = read(), A = (1 << n) - 1;     for (int i = 0; i < n; ++i) a[i] = read(), rev[1 << i] = i;     for (int i = 0; i < n; ++i) {       v[i][0] = 1;       for (int S = 1; S < (1 << n); ++S)         v[i][S] = 1ll * v[i][S & (S - 1)] * a[i] % P *                   qpow((a[rev[S & -S]] + a[i]) % P, P - 2) % P;     }     for (int S = 1; S < (1 << n); ++S) {       int tmp = 0;       cnt[S] = cnt[S >> 1] + (S & 1);       for (int T = (S - 1) & S; T; T = (T - 1) & S)         (tmp += 1ll * F[T] * get(S ^ T, A ^ S) % P) %= P;       F[S] = (get(S, A ^ S) - tmp + P) % P;       for (int T = S; T; T = (T - 1) & S) G[T] = 0;     }     int res = 0;     for (int S = 1; S < (1 << n); ++S) (res += 1ll * F[S] * cnt[S] % P) %= P;     printf( %d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) f = ch ==  -  ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar();     return x * f;   }   const int maxn = 205;   int tot;   int R, G, B;   int r[maxn];   int g[maxn];   int b[maxn];   int f[maxn][maxn][maxn];   struct Stick {     int v, c;   } a[maxn << 3];   inline bool cmp(int u, int v) { return u > v; }   int main() {     R = read(), G = read(), B = read();     for (int i = (1); i <= (R); i++) r[i] = read();     for (int i = (1); i <= (G); i++) g[i] = read();     for (int i = (1); i <= (B); i++) b[i] = read();     sort(r + 1, r + R + 1, cmp), sort(g + 1, g + G + 1, cmp),         sort(b + 1, b + B + 1, cmp);     f[1][1][0] = r[1] * g[1];     f[1][0][1] = r[1] * b[1];     f[0][1][1] = g[1] * b[1];     int ans = 0;     for (int i = (0); i <= (R); i++)       for (int j = (0); j <= (G); j++)         for (int k = (0); k <= (B); k++) {           if (i && j)             f[i][j][k] = max(f[i][j][k], f[i - 1][j - 1][k] + r[i] * g[j]);           if (i && k)             f[i][j][k] = max(f[i][j][k], f[i - 1][j][k - 1] + r[i] * b[k]);           if (j && k)             f[i][j][k] = max(f[i][j][k], f[i][j - 1][k - 1] + g[j] * b[k]);           ans = max(ans, f[i][j][k]);         }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first == b.first) return a.second < b.second;     return a.first < b.first;   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second) return b.first > a.first;     return (a.second < b.second);   }   bool compmx(int a, int b) { return (a < b); }   long long int bin(long long int n) {     long long int B_Number = 0;     long long int cnt = 0;     while (n != 0) {       long long int rem = n % 2;       long long int c = pow(10, cnt);       B_Number += rem * c;       n /= 2;       cnt++;     }     return B_Number;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   bool is_prime(long long int x) {     if (x == 1) return false;     if (x == 2 || x == 3) return true;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int d, n;     cin >> d >> n;     ;     long long int a[n];     for (long long int i = 0; i < n; i++) {       cin >> a[i];     };     long long int ans = 0;     long long int x;     for (long long int i = 1; i < n; i++) {       x = a[i - 1] + 1;       if (x > d) x = 1;       if (x == 1)         continue;       else         ans += (d - x + 1);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1073741824;   const int N = 100005;   const double PI = 4 * atan(1);   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }   bool isprime(long long u) {     for (long long i = 2; i <= (int)sqrt(u); i++) {       if (u % i == 0) return 0;     }     return 1;   }   long long mod(long long to_mod) {     to_mod %= MOD;     while (to_mod < 0) to_mod += MOD;     return to_mod % MOD;   }   long long moduloMultiplication(long long a, long long b, long long mod) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1) res = (res + a) % mod;       a = (2 * a) % mod;       b >>= 1;     }     return res;   }   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long _sieve_size;   bitset<1000010> bs;   vector<long long> primes;   void sieve(long long upperbound) {     _sieve_size = upperbound + 1;     bs.set();     bs[0] = bs[1] = 0;     for (long long i = 2; i <= _sieve_size; i++)       if (bs[i]) {         for (long long j = i * i; j <= _sieve_size; j += i) bs[j] = 0;         primes.push_back(i);       }   }   long long numDiv(long long N) {     long long PF_idx = 0, PF = primes[PF_idx], ans = 1;     while (PF * PF <= N) {       long long power = 0;       while (N % PF == 0) {         N /= PF;         power++;       }       ans *= (power + 1);       PF = primes[++PF_idx];     }     if (N != 1) ans *= 2;     return ans;   }   int main() {     sieve(1000000);     long long t[1000005];     for (int i = 1; i <= 1000000; i++) {       t[i] = numDiv(i);     }     long long a, b, c, ans = 0;     cin >> a >> b >> c;     for (int i = 1; i <= a; i++) {       for (int j = 1; j <= b; j++) {         for (int k = 1; k <= c; k++) {           ans = mod(ans + t[i * j * k]);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(false);     while (cin >> n) {       vector<int> inside(1000006, 0), ans;       int stack = 0, length = 0, x, valid = 1, j = 1;       unordered_map<int, int> used;       for (int i = 0; i < n; ++i) {         cin >> x;         if ((x > 0 && inside[x]) || (x < 0 && !inside[-x]) ||             (x > 0 && used[x])) {           valid = 0;         } else if (x > 0) {           ++inside[x];           ++stack;           ++length;           used[x] = j++;         } else if (x < 0) {           --inside[-x];           --stack;           ++length;         }         if (!stack && valid) {           ans.emplace_back(length);           length = 0;           used.clear();         }       }       if (stack) valid = 0;       if (valid) {         cout << ans.size() << endl;         for (int i : ans) cout << i <<    ;         cout << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, H, M;   int main() {     scanf( %d%d:%d , &N, &H, &M);     if (N == 24) {       if (H / 10 >= 3) H %= 10;       if (H / 10 == 2 && H % 10 >= 4) H %= 10;     } else {       if (H / 10 >= 2) {         if (H % 10 == 0)           H = H % 10 + 10;         else           H %= 10;       }       if (H / 10 == 1 && H % 10 >= 3) H = 10;       if (H == 0) H = 1;     }     if (M / 10 >= 6) M %= 10;     printf( %02d:%02d n , H, M);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   uint64_t ans, fact[21];   long long t, n, cont, val;   bool us[30];   vector<uint64_t> v;   uint64_t calc() {     uint64_t tmp = 1;     uint64_t freq[30];     uint64_t ind = 0;     for (int i = 0; i < 30; i++) freq[i] = 0;     for (int i = 0; i < v.size(); i++) {       while (ind < v.size() && v[ind] < (i + 2)) {         ind++;       }       freq[v[i]]++;       tmp *= max((uint64_t)0, ind - i);     }     for (int i = 0; i < 30; i++) {       tmp /= fact[freq[i]];     }     return tmp;   }   int main() {     fact[0] = 1;     for (int i = 1; i < 21; i++) fact[i] = fact[i - 1] * uint64_t(i);     cin >> t;     while (t--) {       cin >> n;       v.clear();       ans = 0;       memset(us, false, sizeof(us));       cont = 2;       while (n) {         v.push_back(n % cont);         n /= cont;         cont++;       }       sort(v.begin(), v.end());       for (int i = 0; i < v.size(); i++) {         if (v[i] != 0 && us[v[i]] == false) {           val = v[i];           v.erase(v.begin() + i);           ans += calc();           v.insert(v.begin() + i, val);           us[val] = true;         }       }       cout << ans - 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, cn, nw, res, ans;   int used[533];   int x[1020], y[1020];   int a[1020][1020];   int asjkjas[1020];   bool kuhn(int x) {     if (used[x] == nw) return false;     used[x] = nw;     for (int i = (0); i < (n); ++i)       if (a[x][i] && i != cn && (asjkjas[i] == -1 || kuhn(asjkjas[i]))) {         asjkjas[i] = x;         return true;       }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = (0); i < (m); ++i) {       cin >> x[i] >> y[i];       x[i]--;       y[i]--;       a[x[i]][y[i]] = 1;     }     int res = 1000000000;     for (int c = (0); c < (n); ++c) {       cn = c;       int ans = 0;       for (int i = (0); i < (n); ++i) {         if (i != c)           ans += 2 - a[i][c] - a[c][i];         else           ans += 1 - a[i][i];       }       for (int i = (0); i < (n); ++i) used[i] = -1, asjkjas[i] = -1;       int ep = 0;       for (int i = (0); i < (n); ++i) {         if (i != c) {           nw = i;           if (kuhn(i)) ++ep;         }       }       ans += (n - 1) - ep;       for (int i = (0); i < (m); ++i)         if (x[i] != c && y[i] != c) ans += 1;       ans -= ep;       res = min(res, ans);     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int odd, even;   int miny[400001], maxy[400001], min2y[400001], max2y[400001];   vector<int> p[400001];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= 2e5; i++) {       maxy[i] = -1, miny[i] = 2e5 + 1;     }     for (int i = 1; i <= n; i++) {       int u, v, x, y;       cin >> u >> v;       x = v - u;       y = u + v;       x += 2e5;       y += 2e5;       p[x].push_back(y);     }     for (int i = 0; i <= 4e5; i++) {       sort(p[i].begin(), p[i].end());       miny[i] = min2y[i] = 4e5 + 1;       maxy[i] = max2y[i] = -1;     }     for (int i = 1; i <= 4e5; i++) {       if (i > 1) maxy[i] = maxy[i - 2];       if (i > 1) miny[i] = miny[i - 2];       if (!p[i - 1].empty()) maxy[i] = max(maxy[i], p[i - 1].back() - 1);       if (!p[i - 1].empty()) miny[i] = min(miny[i], p[i - 1][0] + 1);     }     long long ans = 0;     for (int i = 4e5 - 1; i >= 0; i--) {       if (i < 4e5 - 1) max2y[i] = max2y[i + 2];       if (i < 4e5 - 1) min2y[i] = min2y[i + 2];       if (!p[i + 1].empty()) max2y[i] = max(max2y[i], p[i + 1].back() - 1);       if (!p[i + 1].empty()) min2y[i] = min(min2y[i], p[i + 1][0] + 1);       maxy[i] = min(maxy[i], max2y[i]);       miny[i] = max(miny[i], min2y[i]);       if (maxy[i] >= miny[i]) {         ans += (maxy[i] - miny[i]) / 2 + 1;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> pair) {     return out <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <class A, class B, class C>   struct Triple {     A first;     B second;     C third;   };   template <class T>   void ResizeVec(T&, vector<long long>) {}   template <class T>   void ResizeVec(vector<T>& vec, vector<long long> sz) {     vec.resize(sz[0]);     sz.erase(sz.begin());     if (sz.empty()) {       return;     }     for (T& v : vec) {       ResizeVec(v, sz);     }   }   void Pol() {     cout <<  Polycarp n ;     exit(0);   }   void Vas() {     cout <<  Vasiliy n ;     exit(0);   }   int main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;     long long xp, yp, xv, yv;     cin >> xp >> yp >> xv >> yv;     ;     if (xv < yv) {       swap(xp, yp);       swap(xv, yv);     }     if (xp <= xv && yp <= yv) {       Pol();     }     if (xp + yp <= max(xv, yv)) {       Pol();     }     if (xv < xp) {       Vas();     }     long long tv = max(yv, xv - xp);     long long tp = yp;     if (tp <= tv) {       Pol();     } else {       Vas();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   set<int> g[maxn];   set<int> vis;   int u[maxn];   void dfs(int x) {     u[x] = 1;     vis.erase(x);     vector<int> ret;     for (int p : vis) {       if (!g[x].count(p)) {         ret.push_back(p);       }     }     for (int t : ret) {       vis.erase(t);     }     for (int t : ret) {       u[t] = 1;       dfs(t);     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].insert(y);       g[y].insert(x);     }     for (int i = 0; i < n; i++) {       vis.insert(i);     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (!u[i]) {         ans++;         dfs(i);       }     }     cout << ans - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[6];     for (int i = 0; i < 6; i++) cin >> a[i];     a[5]++;     int mn = 100000;     for (int i = 0; i < 6; i++) {       if (i == 4) continue;       if (mn > a[i]) mn = a[i];     }     cout << (mn > a[4] ? mn - a[4] : 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s[100005];   char t[100005];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &s[i]);     scanf( %s , t);     int tot = 0, ans = 0;     for (int i = 0; i < n; i++) {       if (t[i] ==  1 ) ans = max(tot, ans + s[i]);       tot += s[i];     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 2007;   int n, m;   vector<int> es[MAXN];   bitset<MAXN> bs[MAXN];   bool hv[MAXN];   int dp[MAXN];   void init();   void input();   void work();   int main() {     init();     int T;     scanf( %d , &T);     while (T--) {       input();       work();     }   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d%d , &n, &m);     int u, v;     for (int i = 1; i <= n; ++i) es[i].clear();     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &u, &v);       es[u].push_back(v);       es[v].push_back(u);     }   }   void work() {     bool flag = true;     for (int i = 1; i <= n; ++i) {       if (es[i].size() & 1) {         flag = false;         break;       }     }     if (flag) {       printf( 1 n );       for (int i = 1; i <= n; ++i) printf( 1  );       putchar(  n );       return;     }     bitset<MAXN> nb;     memset(hv, false, sizeof(hv));     for (int i = 1; i <= n; ++i) bs[i] = 0;     for (int i = 1; i <= n; ++i) {       nb = 0;       for (auto x : es[i]) nb[x] = 1;       nb[i] = es[i].size() & 1;       nb[n + 1] = es[i].size() & 1;       for (int j = 1; j <= n; ++j) {         if (nb[j]) {           if (hv[j])             nb ^= bs[j];           else {             hv[j] = true;             bs[j] = nb;             break;           }         }       }     }     memset(dp, 0, sizeof(dp));     for (int i = n; i > 0; --i) {       if (hv[i]) {         dp[i] = bs[i][n + 1];         for (int j = i + 1; j <= n; ++j) {           if (bs[i][j] && hv[j]) dp[i] ^= dp[j];         }       }     }     printf( 2 n );     for (int i = 1; i <= n; ++i) printf( %d  , dp[i] + 1);     putchar(  n );   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-10;   const long long MOD = 1000000007ll;   const long long mod1 = 1000000009ll;   const long long mod2 = 1100000009ll;   int INF = (int)1e9 + 5;   long long INFINF = (long long)1e18;   int main() {     int n;     scanf( %d , &n);     int a, b, diff;     diff = INF;     a = -1;     b = -1;     for (int i = 1; i <= n; i++) {       if (n % i == 0) {         int a_t, b_t;         a_t = i;         b_t = n / i;         if (abs(a_t - b_t) < diff) {           diff = abs(a_t - b_t);           a = min(a_t, b_t);           b = max(a_t, b_t);         }       }     }     printf( %d  , a);     printf( %d n , b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t[50] = {1,                      2,                      4,                      8,                      16,                      32,                      64,                      128,                      256,                      512,                      1024,                      2048,                      4096,                      8092,                      16184,                      32368,                      64736,                      129472,                      258944,                      517888,                      1035776,                      2071552,                      4143104,                      8286208,                      16572416,                      33144832,                      66289664,                      132579328,                      265158656,                      530317312,                      1060634624LL,                      2121269248LL,                      4242538496LL,                      8485076992LL,                      16970153984LL,                      33940307968LL};   int main() {     int n;     cin >> n;     cout << t[n];     return 0;   }