malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   void sync_stdio() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int intersect(pair<int, int> a, pair<int, int> b) {     return !(b.second <= a.first || a.second <= b.first);   }   int main() {     int a, ta, b, tb;     scanf( %d%d%d%d , &a, &ta, &b, &tb);     int h, m;     scanf( %d:%d , &h, &m);     int tm = h * 60 + m;     int START = 5 * 60;     int END = 24 * 60;     int res = 0;     for (int i = START; i < END; i += b) {       if (intersect({tm, tm + ta}, {i, i + tb})) {         ++res;       }     }     printf( %d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     vector<long long> arr;     arr.push_back(0);     int sz = 1;     long long max_ele = -1;     long long pre_ind = 0;     while (q--) {       int x;       cin >> x;       if (x == 1) {         long long v;         cin >> v;         if (sz == 0)           arr.push_back(v);         else           arr.push_back(v + arr[sz - 1]);         sz++;         max_ele = v;         continue;       }       if (sz == 2) {         cout << setprecision(10) << 0.0l <<   n ;         continue;       }       long long pre_sum = arr[pre_ind];       long long pre_numer = (pre_ind)*max_ele - pre_sum;       long double val = (long double)pre_numer / (pre_ind + 1);       while (pre_ind + 1 <= sz - 2) {         if ((long double)((pre_ind + 1) * max_ele - arr[pre_ind + 1]) /                 (pre_ind + 2) >             val) {           val = (long double)((pre_ind + 1) * max_ele - arr[pre_ind + 1]) /                 (pre_ind + 2);           pre_ind++;         } else           break;       }       cout << setprecision(10) << val <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, n;     cin >> a >> n;     int tilln = (1LL * n * (n - 1) / 2) % 1000000007,         tilla = (1LL * a * (a + 1) / 2) % 1000000007;     cout << ((((((1LL * tilln) % 1000000007) * tilla) % 1000000007) * n) %                  1000000007 +              (1LL * a * tilln) % 1000000007) %                 1000000007          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> big;   vector<int> s[100010];   vector<int> pos[100010];   unsigned int h[100010], n, m, q;   int same[320][100010];   unsigned int BND;   long long a[100010], sum[100010], add[100010];   void Debug() {     unsigned int i, j;     printf( light: n );     for (i = 0; i < m; i++) {       for (j = 0; j < s[i].size(); j++) {         if (j) printf(   );         printf( %I64d , a[s[i][j]]);       }       if (s[i].size() > BND)         printf(  heavy n );       else         printf(  light n );     }     printf(  n );     for (i = 0; i < big.size(); i++)       for (j = 0; j < m; j++) printf( same:%d %d= %d n , h[i], j, same[i][j]);   }   int main() {     unsigned int i, j, k;     scanf( %d%d%d , &n, &m, &q);     BND = sqrt(n);     for (i = 0; i < n; i++) scanf( %I64d , &a[i]);     for (i = 0; i < m; i++) {       unsigned int cnt;       scanf( %d , &cnt);       for (j = 0; j < cnt; j++) {         int tmp;         scanf( %d , &tmp);         tmp--;         s[i].push_back(tmp);         pos[tmp].push_back(i);         sum[i] += a[tmp];       }     }     for (i = 0; i < m; i++)       if (s[i].size() > BND) {         big.push_back(i);         h[big.size() - 1] = i;         for (j = 0; j < s[i].size(); j++) {           int tmp = s[i][j];           for (k = 0; k < pos[tmp].size(); k++)             same[big.size() - 1][pos[tmp][k]]++;         }       }     char o[2];     long long x;     while (q--) {       scanf( %s , o);       if (o[0] ==  + ) {         scanf( %d%I64d , &k, &x);         k--;         if (s[k].size() > BND) {           add[k] += x;           for (i = 0; i < big.size(); i++)             if (h[i] != k) sum[h[i]] += x * (long long)(same[i][k]);         } else {           for (i = 0; i < s[k].size(); i++) a[s[k][i]] += x;           for (i = 0; i < big.size(); i++)             sum[h[i]] += x * (long long)(same[i][k]);         }       } else {         scanf( %d , &k);         k--;         if (s[k].size() > BND) {           long long ans = sum[k] + (long long)s[k].size() * add[k];           printf( %I64d n , ans);         } else {           long long ans = 0;           for (i = 0; i < s[k].size(); i++) ans += a[s[k][i]];           for (i = 0; i < big.size(); i++) ans += add[h[i]] * same[i][k];           printf( %I64d n , ans);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Comm {     int first;     int second;     Comm(int a, int b) {       first = a;       second = b;     }     bool operator<(const Comm& other) const {       if (this->first == other.first) return this->second < other.second;       return this->first < other.first;     }   };   vector<int> P;   vector<int> G;   vector<Comm> ans;   int n;   int main() {     int x, scoP = 0, scoG = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (x == 1)         scoP++;       else         scoG++;       P.push_back(scoP);       G.push_back(scoG);     }     int pntP = 0, pntG = 0, setP = 0, setG = 0;     int maxPoint = max(scoP, scoG);     for (int i = maxPoint; i > 0; i--) {       int tar1 = i, tar2 = i;       int pos = 0;       setP = setG = pntG = pntP = 0;       while (pos < n && !(pntG == pntP && pntG == n)) {         pntP = lower_bound(P.begin() + pos, P.end(), tar1) - P.begin();         pntG = lower_bound(G.begin() + pos, G.end(), tar2) - G.begin();         if (pntP < pntG) {           setP++;           pos = pntP + 1;           tar1 = P[pntP] + i;           tar2 = G[pntP] + i;         }         if (pntP > pntG) {           setG++;           pos = pntG + 1;           tar1 = P[pntG] + i;           tar2 = G[pntG] + i;         }       }       int tmp = max(setG, setP);       if (tmp == setG && x == 1 || tmp == setP && x == 2 || setG == setP ||           pntG == pntP && pntG == n) {         continue;       }       Comm m(tmp, i);       ans.push_back(m);     }     printf( %d n , ans.size());     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long INF = 1e7;   signed main() {     cin.tie(0), ios_base::sync_with_stdio(false);     ;     long long n, s;     cin >> n >> s;     vector<long long> arr(n);     long long su = 0, mi = 1e18;     for (long long i = 0; i < n; ++i) {       cin >> arr[i];       su += arr[i];       if (mi > arr[i]) {         mi = arr[i];       }     }     su -= s;     if (su < 0) {       cout << -1;       return 0;     }     cout << min(su / n, mi);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e5 + 10;   int per(int tot, int cur) { return (cur * 100 + tot / 2) / tot; }   int main() {     int n, k;     cin >> n >> k;     map<pair<int, int>, int> mc;     queue<int> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       q.push(x);     }     int cur = 0;     map<int, int> ans;     while (!q.empty() || !mc.empty()) {       while (mc.size() < k && !q.empty()) {         mc[make_pair(q.front(), q.size())] = 0;         q.pop();       }       vector<pair<int, int>> vp;       int key = per(n, cur);       for (auto& p : mc) {         p.second++;         if (p.second == key) ans[p.first.second] = 1;         if (p.second == p.first.first) vp.emplace_back(p.first);       }       for (auto& p : vp) mc.erase(p), cur++;     }     printf( %d n , ans.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int ara[200005], dist[200005], ans[200005];   vector<int> even, odd, ad[200005];   bool vis[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i, j;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ara[i];       if (ara[i] & 1)         odd.push_back(i);       else         even.push_back(i);       if (i - ara[i] >= 1) ad[i - ara[i]].push_back(i);       if (i + ara[i] <= n) ad[i + ara[i]].push_back(i);     }     memset(dist, -1, sizeof dist);     queue<int> q;     for (i = 0; i < (int)even.size(); i++) {       q.push(even[i]);       dist[even[i]] = 0;       vis[even[i]] = true;     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (i = 0; i < (int)ad[u].size(); i++) {         int v = ad[u][i];         if (!vis[v]) {           vis[v] = true;           q.push(v);           dist[v] = dist[u] + 1;           if (ara[v] & 1) ans[v] = dist[v];         }       }     }     memset(vis, false, sizeof vis);     memset(dist, -1, sizeof dist);     for (i = 0; i < (int)odd.size(); i++) {       q.push(odd[i]);       dist[odd[i]] = 0;       vis[odd[i]] = true;     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (i = 0; i < (int)ad[u].size(); i++) {         int v = ad[u][i];         if (!vis[v]) {           vis[v] = true;           q.push(v);           dist[v] = dist[u] + 1;           if (ara[v] % 2 == 0) ans[v] = dist[v];         }       }     }     for (i = 1; i <= n; i++) {       if (!ans[i]) ans[i] = -1;       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 50, maxm = 5e3, inf = 1e8;   int n, m, q, k, tot, ter[maxm + 3], cap[maxm + 3], wei[maxm + 3], nxt[maxm + 3],       lnk[maxn + 3], dist[maxn + 3], pre[maxn + 3], f[maxn + 3];   bool in[maxn + 3];   long long g[maxn + 3], h[maxn + 3];   void add(int u, int v, int c, int w) {     ter[++tot] = v, cap[tot] = c, wei[tot] = w, nxt[tot] = lnk[u], lnk[u] = tot;   }   void add_flow(int u, int v, int c, int w) { add(u, v, c, w), add(v, u, 0, -w); }   int rev(int x) { return x & 1 ? x + 1 : x - 1; }   bool spfa() {     fill(dist + 1, dist + n + 1, inf);     fill(pre + 1, pre + n + 1, 0);     queue<int> Q;     Q.push(1), dist[1] = 0, in[1] = true;     while (!Q.empty()) {       int u = Q.front();       Q.pop(), in[u] = false;       for (int i = lnk[u], v, c, w; i; i = nxt[i]) {         v = ter[i], c = cap[i], w = wei[i];         if (c > 0 && dist[v] > dist[u] + w) {           dist[v] = dist[u] + w, pre[v] = i;           if (!in[v]) {             in[v] = true, Q.push(v);           }         }       }     }     return pre[n];   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1, u, v, w; i <= m; i++) {       scanf( %d %d %d , &u, &v, &w);       add_flow(u, v, 1, w);     }     while (spfa()) {       int x = n, t;       while (x != 1) {         t = pre[x];         cap[t]--, cap[rev(t)]++;         x = ter[rev(t)];       }       f[++k] = dist[n];       g[k] = g[k - 1] + f[k];       h[k] = 1ll * k * f[k] - g[k];     }     scanf( %d , &q);     for (int x, t; q-- > 0;) {       scanf( %d , &x);       t = upper_bound(h + 1, h + k + 1, x) - (h + 1);       printf( %.9lf n , 1. * (g[t] + x) / t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long int;   int main() {     lint n;     cin >> n;     vector<lint> v(n);     for (lint i = 0; i < n; i++) {       cin >> v[i];     }     lint val = 2 * accumulate(v.begin(), v.end(), 0ll) / n;     vector<lint> visited(n);     for (lint i = 0; i < n; i++) {       if (visited[i]) {         continue;       }       for (lint j = i + 1; j < n; j++) {         if (visited[j]) {           continue;         }         if (v[i] + v[j] == val) {           visited[i] = 1;           visited[j] = 1;           cout << (i + 1) <<     << (j + 1) << endl;           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   int f[55][55][55][55];   string s[100];   bool dfs(int n, int a, int b, int c) {     if (n == 1) return 1;     if (f[n][a][b][c]) return 0;     if (s[c][0] == s[b][0] || s[c][1] == s[b][1])       if (dfs(n - 1, n - 3, a, c)) return 1;     if (n > 3 && (s[c][0] == s[n - 3][0] || s[c][1] == s[n - 3][1]))       if (dfs(n - 1, c, a, b)) return 1;     f[n][a][b][c] = 1;     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> s[i];     bool ans = dfs(n, n - 2, n - 1, n);     if (ans == 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = (int)1e4 + 5, N = (int)1e5 + 5;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int n, m, p;   int a[M], b[N];   vector<int> fac, dp;   int fast(int a, int b) {     int re = 1;     while (b) {       if (b & 1) re = (long long)re * a % p;       a = (long long)a * a % p, b >>= 1;     }     return re;   }   int main() {     scanf( %d %d %d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]);     for (int i = 1; i * i < p; i++)       if ((p - 1) % i == 0) {         fac.push_back(i);         if ((p - 1) / i != i) fac.push_back((p - 1) / i);       }     sort(fac.begin(), fac.end());     int gd = p - 1;     for (int i = 1; i <= m; i++) gd = gcd(gd, b[i]);     dp.resize(fac.size());     for (int i = 1, ab, t; i <= n; i++) {       ab = fast(a[i], gd);       t = fac.size() - 1;       while (fast(ab, (p - 1) / fac[t]) != 1) t--;       dp[t] = (p - 1) / fac[t];     }     long long ans = 0;     for (int i = dp.size() - 1; i >= 0; i--)       if (dp[i]) {         for (int j = dp.size() - 1; j > i; j--)           if (fac[j] % fac[i] == 0) dp[i] -= dp[j];         ans += dp[i];       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int kMaxN = 1010;   struct Cell {     int x, y, val;     bool operator<(const Cell &p) const { return val > p.val; }   } cell[kMaxN * kMaxN];   vector<int> vec[kMaxN];   int g[kMaxN][kMaxN];   int n, m;   void init() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         scanf( %d , &cell[i * m + j].val);         cell[i * m + j].x = i;         cell[i * m + j].y = j;       }     }     sort(cell, cell + n * m);   }   void solve() {     for (int i = 0; i < n * m; ++i) {       int j = cell[i].y;       int q = cell[i].x;       for (int l = 0; l < ((int)(vec[j]).size()); ++l) {         int p = vec[j][l];         if (g[p][q]) {           printf( %d n , cell[i].val);           return;         }         g[p][q] = g[q][p] = 1;       }       vec[j].push_back(q);     }   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 5;   long long a[maxn];   long long pre[maxn];   map<long long, long long> mp;   int main() {     int n, l;     scanf( %d%d , &n, &l);     for (int i = 0; i < n; i++) {       scanf( %I64d , &a[i]);       mp[a[i]]++;     }     sort(a, a + n);     long long cnt = unique(a, a + n) - a;     for (int i = 1; i <= cnt; i++) {       pre[i] = pre[i - 1] + mp[a[i - 1]];     }     l *= 8;     long long temp = log(cnt) / log(2);     if ((1 << temp) < cnt) temp++;     if (temp * n <= l) {       printf( 0 n );       return 0;     }     long long sum = l / n;     sum = (1 << sum);     long long ans = -0x3f3f3f3f;     for (int i = 1, j = i + sum; j <= cnt; i++, j++) {       ans = max(ans, pre[j] - pre[i]);     }     printf( %I64d n , n - ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char x[105];   bool g;   int main() {     scanf( %s , x);     for (int i = 0; x[i]; i++)       if (x[i] ==  a  || x[i] ==  e  || x[i] ==  i  || x[i] ==  o  || x[i] ==  u )         g = 0;       else if (g) {         puts( NO );         return 0;       } else if (x[i] !=  n )         g = 1;     puts(g ?  NO  :  YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> a[100005], b[100005], all;   void solve() {     for (int i = 1; i <= n; i++) {       a[i].resize(m + 1);       b[i].resize(m + 1);       for (int j = 1; j <= m; j++) a[i][j] = (i - 1) * m + j;     }     bool bswap = 0;     if (n > m) bswap = 1;     if (bswap == 1) {       for (int j = 1; j <= m; j++)         for (int i = 1; i <= n; i++) all.push_back(a[i][j]);       for (int j = 1; j <= m; j++) {         if (n % 2 == 0) {           for (int i = 1; i <= n / 2; i++)             b[i][j] = all[(j - 1) * n + (i - 1) * 2 + 1];           for (int i = n / 2 + 1; i <= n; i++)             b[i][j] = all[(j - 1) * n + (i - 1 - n / 2) * 2];           if (j % 2 == 1)             for (int i = 1; i <= n / 2; i++) swap(b[i][j], b[n - i + 1][j]);         } else {           if (j % 2 == 1) {             for (int i = 1; i <= n / 2; i++)               b[i][j] = all[(j - 1) * n + (i - 1) * 2 + 1];             for (int i = n / 2 + 1; i <= n; i++)               b[i][j] = all[(j - 1) * n + (i - 1 - n / 2) * 2];           } else {             for (int i = 1; i <= n / 2 + 1; i++)               b[i][j] = all[(j - 1) * n + (i - 1) * 2];             for (int i = n / 2 + 2; i <= n; i++)               b[i][j] = all[(j - 1) * n + (i - 2 - n / 2) * 2 + 1];           }         }       }     } else {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) all.push_back(a[i][j]);       for (int i = 1; i <= n; i++) {         if (m % 2 == 0) {           for (int j = 1; j <= m / 2; j++)             b[i][j] = all[(i - 1) * m + (j - 1) * 2 + 1];           for (int j = m / 2 + 1; j <= m; j++)             b[i][j] = all[(i - 1) * m + (j - 1 - m / 2) * 2];           if (i % 2 == 1)             for (int j = 1; j <= m / 2; j++) swap(b[i][j], b[i][m - j + 1]);         } else {           if (i % 2 == 1) {             for (int j = 1; j <= m / 2; j++)               b[i][j] = all[(i - 1) * m + (j - 1) * 2 + 1];             for (int j = m / 2 + 1; j <= m; j++)               b[i][j] = all[(i - 1) * m + (j - 1 - m / 2) * 2];           } else {             for (int j = 1; j <= m / 2 + 1; j++)               b[i][j] = all[(i - 1) * m + (j - 1) * 2];             for (int j = m / 2 + 2; j <= m; j++)               b[i][j] = all[(i - 1) * m + (j - 2 - m / 2) * 2 + 1];           }         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cout << b[i][j] <<    ;       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (n == 1 && m == 1) {       cout <<  YES  << endl << 1;       return 0;     }     if ((n == 1 && m == 4) || (n == 4 && m == 1)) {       cout <<  YES  << endl;       solve();       return 0;     }     if (n + m <= 5) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     if (n == 3 && m == 3) {       cout << 6 <<     << 1 <<     << 8 << endl;       cout << 7 <<     << 5 <<     << 3 << endl;       cout << 2 <<     << 9 <<     << 4;       return 0;     }     if (n > 3 || m > 3) solve();   }
#include <bits/stdc++.h>   using namespace std;   bool flag = false;   long long n;   long long mat[1000][1000];   bool vis[1000][1000];   long long ans[1000][1000];   bool isSol() {     long long s = 0;     for (int i = 0; i < n; i++) {       s += ans[i][i];     }     long long s2 = 0;     for (int i = 0; i < n; i++) {       s2 += ans[n - i - 1][i];     }     if (s2 != s) return false;     for (int i = 0; i < n; i++) {       s2 = 0;       for (int j = 0; j < n; j++) {         s2 += ans[i][j];       }       if (s2 != s) return false;     }     for (int i = 0; i < n; i++) {       s2 = 0;       for (int j = 0; j < n; j++) {         s2 += ans[j][i];       }       if (s2 != s) return false;     }     return true;   }   void find_sol(long long pos) {     if (flag) return;     if (pos == n * n) {       if (isSol()) flag = true;       return;     }     long long pos_x = pos / n;     long long pos_y = pos % n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (!vis[i][j] && !flag) {           vis[i][j] = true;           ans[pos_x][pos_y] = mat[i][j];           find_sol(pos + 1);           vis[i][j] = false;         }       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> mat[i][j];         vis[i][j] = false;       }     }     find_sol(0);     long long s = 0;     for (int i = 0; i < n; i++) s += ans[i][0];     cout << s << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }     return 0;   }
#include <cstdio>   #include <algorithm>   using namespace std;   #define ADD(x) ((x>=mod)?x-mod:x)   const int mod=1e9+7;   int n,c[110],b[110],sum[110],sum1[110],sumc[110],dp[110][10010],ans,Min,T,x;   int main()   {    scanf( %d ,&n);    for (int i=1;i<=n;i++) scanf( %d ,&c[i]),sumc[i]=sumc[i-1]+c[i];    for (int i=1;i<n;i++) scanf( %d ,&b[i]),sum[i]=sum[i-1]+b[i];    for (int i=1;i<=n;i++) sum1[i]=sum1[i-1]+sum[i-1];    scanf( %d%d ,&T,&x);    dp[0][0]=1;    for (int i=1;i<=n;i++)     for (int j=x*i+sum1[i];j<=sumc[i];j++)      for (int k=min(j,c[i]);k>=0;k--)       dp[i][j]=ADD(dp[i][j]+dp[i-1][j-k]);    for (int i=0;i<=sumc[n];i++) ans=ADD(ans+dp[n][i]);    printf( %d n ,ans);    return 0;   }