malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int maxSubArraySum(long long int a[], long long int size) {     long long int max_so_far = INT_MIN, max_ending_here = 0;     for (long long int i = 0; i < size; i++) {       max_ending_here = max_ending_here + a[i];       if (max_so_far < max_ending_here) max_so_far = max_ending_here;       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   int32_t main() {     long long int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       long long int sum = 0;       long long int a[n];       string s;       vector<long long int> v;       long long int k;       cin >> k;       long long int b[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];       }       sort(b, b + n);       long long int p = 0;       for (long long int i = 0; i < n; i++) {         if (a[i] != b[i]) {           p = 1;           break;         }       }       if (p == 0) {         cout << maxSubArraySum(a, n);       } else {         long long int ansfinal = -1e9;         for (long long int i = 0; i < n; i++) {           for (long long int j = i; j < n; j++) {             long long int u = k;             long long int ans = 0;             priority_queue<long long int> pq;             priority_queue<long long int, vector<long long int>,                            greater<long long int>>                 pqmin;             for (long long int k = 0; k < n; k++) {               if (k >= i && k <= j) {                 ans += a[k];                 pqmin.push(a[k]);               } else {                 pq.push(a[k]);               }             }             while (u && pq.size() && pqmin.size()) {               if (pqmin.top() >= pq.top()) {                 break;               } else {                 ans -= pqmin.top();                 pqmin.pop();                 ans += pq.top();                 pq.pop();               }               u--;             }             ansfinal = max(ans, ansfinal);           }         }         cout << ansfinal;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   long long a[N], f[N];   int main() {     long long o, t, n = 1;     long long s = 0;     scanf( %I64d , &o);     while (o--) {       scanf( %I64d , &t);       if (t == 2) {         n++;         scanf( %I64d , &a[n]);         f[n] = 0;         s += a[n];       } else if (t == 1) {         long long cnt, x;         scanf( %I64d%I64d , &cnt, &x);         f[cnt] += x;         s += cnt * x;       } else if (t == 3) {         s -= (f[n] + a[n]);         f[n - 1] += f[n];         f[n] = 0;         n--;       }       printf( %.9lf n , s * 1.0 / n);     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, d[500][500], dist[500][500];   long long t, a, c, b;   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         cin >> d[i][j];         dist[i][j] = d[i][j];       }     }     long long tong;     cin >> t;     while (t--) {       cin >> a >> b >> c;       tong = 0;       dist[a][b] = dist[b][a] = min(dist[a][b], min(dist[b][a], c));       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= n; j++) {           dist[i][j] = min(dist[i][j], min(dist[i][a] + c + dist[b][j],                                            dist[i][b] + c + dist[a][j]));         }       }       for (long long i = 1; i <= n; i++) {         for (long long j = i + 1; j <= n; j++) {           tong += dist[i][j];         }       }       cout << tong <<    ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAX = 2e5 + 5;   const long long MAX2 = 11;   const int MOD = 1000000000 + 7;   const long long INF = 20000;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};   const double pi = acos(-1);   long long n, h, ans;   bool st, ada;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> h >> n;     n--;     for (int i = (int)h - 1; i >= (int)0; i--) {       ada = (1ll << i) & n;       if (ada ^ st)         ans += (1ll << (i + 1));       else         ans++, st ^= 1;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a % b != 0) {       long long aux = a % b;       a = b;       b = aux;     }     return b;   }   int main() {     ios::sync_with_stdio(0);     cin.tie();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       long long a, b, d;       cin >> a >> b >> d;       long long div = gcd(a, b);       a /= div;       b /= div;       while (true) {         div = gcd(b, d);         if (1 == div)           break;         else {           while (b % div == 0) b /= div;           d = div;         }       }       if (b == 1)         cout <<  Finite n ;       else         cout <<  Infinite n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     double exp, ans, pi;     exp = ans = 0.0;     for (int i = 0; i < n; i++) {       scanf( %lf , &pi);       exp = exp * pi + pi;       ans = ans + 2 * exp - pi;     }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-10;   const int INF = 0x3fffffff;   const long long LINF = INF * 1ll * INF;   const double PI = acos(-1.0);   using namespace std;   int sign(double x) { return x > 0 ? 1 : -1; }   int main(void) {     int x1, y1, x2, y2;     scanf( %d %d %d %d , &x1, &y1, &x2, &y2);     int vmax, t;     scanf( %d %d , &vmax, &t);     double low = 0, high = t;     double windX, windY;     scanf( %lf %lf , &windX, &windY);     double newX, newY;     scanf( %lf %lf , &newX, &newY);     bool find = false;     while (low + EPS <= high) {       double mid = (low + high) / 2.0;       double deltaX = x2 - x1;       double deltaY = y2 - y1;       double vx = deltaX / mid - windX;       if (abs(vx) - abs(vmax) > 0) {         low = mid;         continue;       }       double vy = sqrt(vmax * vmax - vx * vx) + windY;       double mx = vy * mid;       vy = -sqrt(vmax * vmax - vx * vx) + windY;       double mi = vy * mid;       if (mx < mi) swap(mx, mi);       if (mi - EPS <= deltaY && deltaY <= mx + EPS) {         high = mid;         find = true;       } else         low = mid;     }     if (!find) {       low = t, high = 1e9;       while (low + EPS <= high) {         double mid = (low + high) / 2.0;         double deltaX = x2 - x1;         double deltaY = y2 - y1;         double vx = deltaX - t * windX - newX * (mid - t);         vx /= mid;         if (abs(vx) - abs(vmax) > 0) {           low = mid;           continue;         }         double vy = sqrt(vmax * vmax - vx * vx);         double mx = vy * mid + t * windY + (mid - t) * newY;         vy = -sqrt(vmax * vmax - vx * vx);         double mi = vy * mid + t * windY + (mid - t) * newY;         if (mx < mi) swap(mx, mi);         if (mi - EPS <= deltaY && deltaY <= mx + EPS) {           high = mid;         } else           low = mid;       }     }     printf( %.10lf n , low);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, rt, i, j;     char a[] = { a ,  e ,  i ,  o ,  u };     cin >> k;     rt = (int)sqrt(k);     for (; k % rt != 0; rt--)       ;     if (rt > 4) {       for (i = 0; i != k / rt; i++) {         for (j = 0; j != rt; j++) {           cout << a[(i + j) % 5];         }       }     } else       cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int dp[N][N];   int a[N];   int calc(int l, int r) {     if (dp[l][r] != -1) return dp[l][r];     if (l > r) {       return dp[l][r] = 1;     }     if (l == r) {       return dp[l][r] = 1;     }     dp[l][r] = N;     if (a[l] == a[r]) {       dp[l][r] = min(dp[l][r], calc(l + 1, r - 1));     }     for (int j = l; j < r; j++) {       dp[l][r] = min(dp[l][r], calc(l, j) + calc(j + 1, r));     }     return dp[l][r];   }   int main() {     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) dp[i][j] = -1;     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cout << calc(0, n - 1) << endl;   }
#include <bits/stdc++.h>   const long long int M = 2000000005;   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     while (t--) {       long long int n, i, c, j;       string s;       cin >> s;       n = s.size();       vector<long long int> v[26];       for (i = 0; i < 26; i++) {         v[i].push_back(-1);       }       for (i = 0; i < n; i++) {         c = (long long int)s[i] - 97;         v[c].push_back(i);       }       for (i = 0; i < 26; i++) {         v[i].push_back(n);       }       long long int ans = 1e18, ans1;       for (i = 0; i < 26; i++) {         if (v[i].size() == 2) {           continue;         }         ans1 = -1e18;         for (j = 1; j < v[i].size(); j++) {           ans1 = max(ans1, v[i][j] - v[i][j - 1]);         }         ans = min(ans, ans1);       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long an1 = 1, an2 = 1;     for (int i = 0; i < n; ++i) {       an1 = (an1 * 7) % 1000000007;     }     for (int i = 0; i < 3 * n; ++i) {       an2 = (an2 * 3) % 1000000007;     }     long long ot = an2 - an1;     while (ot < 0) ot += 1000000007;     cout << ot;     return 0;   }
#include <bits/stdc++.h>   int p, prime[100005], count[100005][20];   void Prime() {     int i, j;     for (i = 2, p = 0; i < 100005; i++) {       for (j = 2; j <= sqrt(i); j++)         if (i % j == 0) break;       if (j > sqrt(i)) prime[p++] = i;     }   }   void Count() {     int i, j;     memset(count, 0, sizeof(count));     for (i = 0; i < p; i++)       for (j = prime[i]; j < 100005; j += prime[i])         count[j][++count[j][0]] = prime[i];   }   int main() {     Prime();     Count();     char sym;     int n, m, i, j, ind, flag[100005], num[100005];     while (scanf( %d%d , &n, &m) != EOF) {       memset(flag, 0, sizeof(flag));       memset(num, 0, sizeof(num));       for (i = 0; i < m; i++) {         getchar();         scanf( %c %d , &sym, &ind);         if (sym ==  + ) {           if (flag[ind])             printf( Already on n );           else {             for (j = 1; j <= count[ind][0]; j++)               if (num[count[ind][j]]) break;             if (j > count[ind][0]) {               printf( Success n );               flag[ind] = 1;               for (j = 1; j <= count[ind][0]; j++) num[count[ind][j]] = ind;             } else               printf( Conflict with %d n , num[count[ind][j]]);           }         } else {           if (!flag[ind])             printf( Already off n );           else {             printf( Success n );             flag[ind] = 0;             for (j = 1; j <= count[ind][0]; j++) num[count[ind][j]] = 0;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % ((long long)1e9 + 7);       }       y /= 2;       x = (x * x) % ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % w;       }       y /= 2;       x = (x * x) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   void solve() {     long long n;     cin >> n;     long long ans = 1;     for (long long i = 1; i <= n - 1; i++) {       if (i != n / 2) ans *= i;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, id;     friend bool operator<(node a, node b) {       if (a.x == b.x) return a.id < b.id;       return a.x < b.x;     }   } a[200005];   priority_queue<node> Q;   struct edge {     int s, e;   } ans[2000005];   int id;   int main() {     int n, s;     while (scanf( %d %d , &n, &s) != EOF) {       int i, j, k;       for (i = 1; i <= n; ++i) {         scanf( %d , &a[i].x);         a[i].id = i;         Q.push(a[i]);       }       node x;       id = 0;       while (!Q.empty()) {         x = Q.top();         Q.pop();         j = 0;         for (i = 0; i < x.x && (!Q.empty()); ++i) {           a[j] = Q.top();           Q.pop();           ans[id].s = x.id;           ans[id].e = a[j].id;           a[j].x--;           j++;           id++;         }         if (i == x.x) {           --j;           while (j >= 0) {             if (a[j].x) {               Q.push(a[j]);             }             j--;           }         } else {           s = 0;           break;         }       }       if (s == 0) {         puts( No );       } else {         puts( Yes );         printf( %d n , id);         for (i = 0; i < id; ++i) {           printf( %d %d n , ans[i].s, ans[i].e);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a, b;     cin >> a >> b;     int pa = 0;     while (pa + 1 < a.size() && a[pa + 1] < b[0]) pa++;     for (int i = 0; i <= pa; i++) cout << a[i];     cout << b[0];   }
#include <bits/stdc++.h>   using namespace std;   void SieveOfErat() {     bool prime[1000001];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= 1000000; p++) {       if (prime[p] == true) {         for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false;       }     }   }   long long gcd(long long x, long long y) {     if (x == 0) {       return y;     } else       return gcd(x % y, y);   }   long long n, m;   vector<vector<long long> > v;   vector<long long> res;   signed main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     v.assign(n, vector<long long>(m, 0));     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < m; ++j) cin >> v[i][j];     }     if (n < m) {       for (long long i = 0; i < n; ++i) {         long long mi = 600;         for (long long j = 0; j < m; ++j) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long j = 0; j < mi; ++j) res.push_back(i + 1);         for (long long j = 0; j < m; ++j) v[i][j] -= mi;       }       for (long long j = 0; j < m; ++j) {         long long mi = 600;         for (long long i = 0; i < n; ++i) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long i = 0; i < mi; ++i) res.push_back(-(j + 1));         for (long long i = 0; i < n; ++i) v[i][j] -= mi;       }     } else {       for (long long j = 0; j < m; ++j) {         long long mi = 600;         for (long long i = 0; i < n; ++i) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long i = 0; i < mi; ++i) res.push_back(-(j + 1));         for (long long i = 0; i < n; ++i) v[i][j] -= mi;       }       for (long long i = 0; i < n; ++i) {         long long mi = 600;         for (long long j = 0; j < m; ++j) mi = min(mi, v[i][j]);         if (mi == 0) continue;         for (long long j = 0; j < mi; ++j) res.push_back(i + 1);         for (long long j = 0; j < m; ++j) v[i][j] -= mi;       }     }     long long sum = 0;     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < m; ++j) sum += v[i][j];     if (sum > 0) {       cout << -1 << endl;       return 0;     }     cout << res.size() <<   n ;     for (long long i = 0; i < res.size(); ++i) {       if (res[i] > 0)         cout <<  row   << res[i] <<   n ;       else         cout <<  col   << -res[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, dx, dy, ans = 0, a, b;     map<long long, int> num;     double k;     scanf( %lld%lld%lld%lld , &n, &m, &dx, &dy);     long long x, y;     for (int i = 0; i < m; i++) {       scanf( %lld%lld , &x, &y);       k = ((dy * x - dx * y) % n + n) % n;       num[k]++;       if (ans < num[k]) {         a = x;         b = y;         ans = num[k];       }     }     printf( %lld %lld n , a, b);     return 0;   }
#include <bits/stdc++.h>   int get() {     int x = 0;     char s = getchar();     while (s <  0  || s >  9 ) s = getchar();     while (s >=  0  && s <=  9 )       x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();     return x;   }   const int M = 1e5 + 5;   int n, m, head[M], cntedge, ans, s, a[M << 2];   bool c[M], vis[M];   struct edge {     int to, nxt;     edge() {}     edge(const int T, const int NX) { to = T, nxt = NX; }   } e[M << 1];   void add(const int u, const int v) {     e[++cntedge] = edge(v, head[u]), head[u] = cntedge;   }   void dfs(int u, int fa) {     vis[u] = 1;     a[++ans] = u;     c[u] ^= 1;     for (int i = head[u]; i; i = e[i].nxt)       if (!vis[e[i].to]) {         dfs(e[i].to, u);         a[++ans] = u;         c[u] ^= 1;       }     if (c[u]) {       a[++ans] = fa;       c[fa] ^= 1;       a[++ans] = u;       c[u] ^= 1;     }   }   int main() {     n = get(), m = get();     for (int u, v; m--;) {       u = get(), v = get();       add(u, v), add(v, u);     }     for (int i = 1; i <= n; ++i) {       c[i] = get();       if (c[i]) s = i;     }     if (s) {       dfs(s, -1);       for (int i = 1; i <= n; ++i)         if (!vis[i] && c[i]) return !printf( -1 );     }     if (ans > 1 && a[ans - 1] == -1) ans -= 3;     printf( %d n , ans);     for (int i = 1; i <= ans; ++i) printf( %d  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %d %d %d %d , &a, &b, &c, &d);     int M, M1, M2, V, V1, V2;     M1 = (3 * a) / 10;     M2 = (a - (a / 250) * c);     if (M1 > M2) {       M = M1;     } else {       M = M2;     }     V1 = (3 * b) / 10;     V2 = (b - (b / 250) * d);     if (V1 > V2) {       V = V1;     } else {       V = V2;     }     if (M > V) {       printf( Misha n );     } else {       if (V > M) {         printf( Vasya );       } else {         printf( Tie );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long LINF = 1e18;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const int MAXN = 200050;   int a[MAXN], cnt[105];   unordered_map<int, int> mp;   void solve(int T) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     int maxx = 0, idx;     for (int i = 1; i <= 100; i++) {       if (cnt[i] > maxx) {         maxx = cnt[i];         idx = i;       }     }     int tmp = 0;     for (int i = 1; i <= 100; i++) {       if (cnt[i] == maxx) tmp++;     }     if (tmp >= 2) {       printf( %d n , n);       return;     }     int ans = 0;     for (int i = 1; i <= 100; i++) {       if (i == idx) continue;       mp.clear();       mp[idx] = 0;       int sum = 0;       for (int j = 1; j <= n; j++) {         if (a[j] == idx)           sum++;         else if (a[j] == i)           sum--;         if (sum == 0)           ans = max(ans, j);         else if (mp[sum]) {           ans = max(ans, j - mp[sum]);         } else           mp[sum] = j;       }     }     printf( %d , ans);   }   signed main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve(i);     }   }
#include <bits/stdc++.h>   using namespace std;   long long int mod1 = 1000000007;   long long int mod2 = 67280421310721;   long long int mod3 = 998244353;   long long int INF = 1e18;   long long int binpow1(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int binpow2(long long int a, long long int b, long long int m) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   map<long long int, long long int> fact(long long int n) {     map<long long int, long long int> factorization;     long long int c = 0;     while (n % 2 == 0) {       c++;       n /= 2;     }     if (c > 0) {       factorization.insert({2, c});     }     c = 0;     for (long long int d = 3; d * d <= n; d += 2) {       while (n % d == 0) {         c++;         n /= d;       }       if (c > 0) {         factorization.insert({d, c});       }       c = 0;     }     if (n > 1) {       factorization.insert({n, 1});     }     return factorization;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long int n = s.length();       long long int ans = 0;       long long int c = 0, d = 0;       long long int k = 0;       long long int f = 0;       long long int p = n;       for (int i = (0); i < (n); i++) {         if (s[i] ==  A ) {           p = i;           break;         }       }       for (int i = (0); i < (n); i++) {         if (s[i] ==  A ) {           c++;           f++;         } else {           d++;           k++;         }         if (d >= c) {           ans = ans + c;           c = 0;           d = 0;         }       }       ans = ans + min(c, d);       cout << n - 2 * ans - (k - ans - (k - ans) % 2) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int freq[3];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       freq[s[i] -  0 ]++;     }     for (int i = n - 1; i >= 0; i--) {       if (freq[0] <= n / 3) {         break;       }       if (s[i] ==  0 ) {         if (freq[2] < n / 3) {           freq[2]++;           s[i] =  2 ;           freq[0]--;         } else {           freq[1]++;           s[i] =  1 ;           freq[0]--;         }       }     }     for (int i = 0; i < n; i++) {       if (freq[1] <= n / 3) break;       if (s[i] ==  1 ) {         if (freq[0] < n / 3) {           freq[0]++;           freq[1]--;           s[i] =  0 ;         }       }     }     for (int i = n - 1; i >= 0; i--) {       if (freq[1] <= n / 3) break;       if (s[i] ==  1 ) {         if (freq[2] < n / 3) {           freq[2]++;           freq[1]--;           s[i] =  2 ;         }       }     }     for (int i = 0; i < n; i++) {       if (freq[2] <= n / 3) break;       if (s[i] ==  2 ) {         if (freq[0] < n / 3) {           freq[0]++;           freq[2]--;           s[i] =  0 ;         } else {           freq[1]++;           freq[2]--;           s[i] =  1 ;         }       }     }     cout << s;     return 0;   }