malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int QuickPow(int x, int y) {     int Res = 1, Temp = x;     while (y) {       if (y & 1) Res = Res * Temp % 1000000007;       Temp = Temp * Temp % 1000000007;       y /= 2;     }     return Res;   }   inline void Swap(int &x, int &y) {     int Temp = x;     x = y;     y = Temp;   }   inline int Max(int x, int y) { return x > y ? x : y; }   inline int Min(int x, int y) { return x < y ? x : y; }   inline void read(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   struct node {     int v, Index;     node() {}     node(int V, int INDEX) {       v = V;       Index = INDEX;     }   };   stack<int> S;   vector<node> G[400005];   int Dfn[400005], Low[400005], Bel[400005], Cnt, Col, Size[400005], Maxx, Root;   bool InStack[400005];   void Tarjan(int x, int Pre) {     Dfn[x] = Low[x] = ++Cnt;     S.push(x);     InStack[x] = 1;     int l = G[x].size();     for (register int i = 0; i < l; ++i) {       int to = G[x][i].v;       if (to == Pre) continue;       if (!Dfn[to]) {         Tarjan(to, x);         Low[x] = Min(Low[x], Low[to]);       } else if (InStack[to])         Low[x] = Min(Low[x], Dfn[to]);     }     if (Dfn[x] == Low[x]) {       Col++;       int u;       do {         Size[Col]++;         u = S.top();         S.pop();         InStack[u] = 0;         Bel[u] = Col;       } while (u != x);       if (Size[Col] > Maxx) Maxx = Size[Col], Root = x;     }   }   bool Pan[400005];   int From[400005 * 2], To[400005 * 2];   void Dfs(int x) {     Pan[x] = 1;     int l = G[x].size();     for (register int i = 0; i < l; ++i) {       int to = G[x][i].v, Id = G[x][i].Index;       if (Pan[to]) {         From[Id] = x, To[Id] = to;         continue;       }       if (Low[to] != Low[x])         From[Id] = to, To[Id] = x;       else         From[Id] = x, To[Id] = to;       Dfs(to);     }   }   int main() {     int n, m;     read(n);     read(m);     for (register int i = 1; i <= m; ++i) {       int u, v;       read(u);       read(v);       G[u].push_back(node(v, i));       G[v].push_back(node(u, i));     }     for (register int i = 1; i <= n; ++i)       if (!Dfn[i]) Tarjan(i, i);     printf( %d n , Maxx);     Dfs(Root);     for (register int i = 1; i <= m; ++i) printf( %d %d n , From[i], To[i]);     return 0;   }
#include <bits/stdc++.h>   struct compare {     bool operator()(const int& l, const int& r) { return l > r; }   };   using namespace std;   priority_queue<int, vector<int>, compare> pq;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       if (k % 3 && n % 3 == 0) {         cout <<  Bob n ;       } else if (k % 3 == 0) {         n %= (k + 1);         if (n % 3 == 0 && n != k) {           cout <<  Bob n ;         } else {           cout <<  Alice n ;         }       } else {         cout <<  Alice n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long double pi = 2.0 * acos(0.0);   mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());   long long int N;   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int a, b, c, i, j, k, first, r, x, y, z;     long long int n, m, p, q, t;     long long int A[1000005];     long long int B[1000005];     first = 0;     r = 0;     cin >> n;     k = (n) / 2;     cout << k <<   n ;     for (i = 0; i < k - 1; i++) cout <<  2  ;     cout << (2 + (n % 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int sz[100005], answer[100005];   long long ans = 0;   vector<int> spis;   void clears(int v, int pr) {     sz[v] = 1;     int pos = -1;     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       if (u == pr)         pos = i;       else {         clears(u, v);         sz[v] += sz[u];       }     }     if (pos != -1) {       swap(g[v][pos], g[v].back());       g[v].pop_back();     }     return;   }   void dfs(int v, int len) {     ans += (long long)2 * len;     spis.push_back(v);     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       dfs(u, len + 1);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v), g[v].push_back(u);     }     clears(1, -1);     int cen = 1;     while (true) {       int mx = -1;       for (int i = 0; i < (int)g[cen].size(); i++) {         int u = g[cen][i];         if (2 * sz[u] > sz[cen]) mx = i;       }       if (mx == -1) break;       int newcen = g[cen][mx];       swap(g[cen][mx], g[cen].back());       g[cen].pop_back();       g[newcen].push_back(cen);       sz[cen] -= sz[newcen];       sz[newcen] += sz[cen];       cen = newcen;     }     dfs(cen, 0);     cout << ans <<   n ;     if (n % 2 == 0) {       for (int i = 0; i < n / 2; i++)         answer[spis[i]] = spis[i + n / 2], answer[spis[i + n / 2]] = spis[i];     } else {       for (int i = 1; i < n / 2; i++)         answer[spis[i]] = spis[i + n / 2], answer[spis[i + n / 2]] = spis[i];       answer[spis[0]] = spis[n / 2], answer[spis[n / 2]] = spis[n - 1],       answer[spis[n - 1]] = spis[0];     }     for (int i = 1; i <= n; i++) cout << answer[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int main() {     int mas[100000];     cin >> n;     for (int i = 0; i < (n); i++) {       scanf( %d , &mas[i]);       if (i < n / 2)         mas[i] -= i;       else         mas[i] -= n - i - 1;     }     sort(mas, mas + n);     int l = 0;     int ans = 0;     for (int i = 1; i <= n; i++)       if (mas[i] != mas[l] || i == n) {         if (mas[l] >= 1) ans = max(ans, i - l);         l = i;       }     cout << n - ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     int res = 0;     for (int i = 0; i < n; i++) {       if ((sum - arr[i]) % 2 == 0) res++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, s;     cin >> n >> s;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long l = 0, r = n, total = 0;     while (l < r) {       long long mid = (l + r) / 2;       long long cost[n];       for (int i = 0; i < n; i++) {         cost[i] = a[i] + mid * (i + 1);       }       sort(cost, cost + n);       total = 0;       for (int i = 0; i < mid; i++) {         total += cost[i];       }       if (s < total) {         r = mid;       } else {         l = mid;       }       if (r - l == 1) {         int cost[n];         mid = r;         for (int i = 0; i < n; i++) {           cost[i] = a[i] + mid * (i + 1);         }         sort(cost, cost + n);         total = 0;         for (int i = 0; i < mid; i++) {           total += cost[i];         }         if (s >= total) {           l = r;         } else {           mid = l;           for (int i = 0; i < n; i++) {             cost[i] = a[i] + mid * (i + 1);           }           sort(cost, cost + n);           total = 0;           for (int i = 0; i < mid; i++) {             total += cost[i];           }         }         break;       }     }     cout << l <<     << total <<   n ;     return 0;   }
#include <bits/stdc++.h>   #define endl   n       using namespace std;      typedef long long lld;      void solve(){       int n;       cin>>n;       vector<lld> a(n+1), b(n+1), p(n+2,0);       for(int i=1;i<=n;i++){           cin>>a[i];       }       for(int i=1;i<=n;i++){           cin>>b[i];           p[i]=a[i]*b[i]+p[i-1];       }       lld ans=p[n];       for(int i=1;i<=n;i++){           lld curr=a[i]*b[i];           for(int l=i-1, r=i+1; l>=1 && r<=n; l--, r++){               curr+=a[r]*b[l]+a[l]*b[r];               ans=max(ans,curr+p[l-1]+p[n]-p[r]);           }           curr=0;           for(int l=i, r=i+1; l>=1 && r<=n; l--, r++){               curr+=a[r]*b[l]+a[l]*b[r];               ans=max(ans,curr+p[l-1]+p[n]-p[r]);           }       }       cout<<ans<<endl;   }      int32_t main(){       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (a > (b * c)) {         cout << (-1) << endl;         continue;       }       long long k = (a / (d * b));       cout << (a * (k + 1)) - (d * b * k * (k + 1) / 2) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> V[500500];   vector<int> SV[500500];   vector<int> MAX1[500500], MAX2[500500], MIN1[500500], MIN2[500500];   vector<pair<int, int>> T;   int R[505000];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc;     cin >> tc;     for (int t = 1; t <= tc; t++) {       int n, m;       cin >> n >> m;       for (int i = 0; i < n; i++) {         V[i].clear();         SV[i].clear();       }       T.clear();       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int x;           cin >> x;           V[i].push_back(x);         }         T.push_back(make_pair(V[i][0], i));       }       sort(T.begin(), T.end());       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           SV[i].push_back(V[T[i].second][j]);         }         R[T[i].second] = i;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           MAX1[i].push_back(0);           MAX2[i].push_back(0);           MIN1[i].push_back(0);           MIN2[i].push_back(0);         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int m1 = i == 0 ? -1 : MAX1[i - 1][j];           int m2 = j == 0 ? -1 : MAX1[i][j - 1];           MAX1[i][j] = max(max(m1, m2), SV[i][j]);         }       }       for (int i = n - 1; i >= 0; i--) {         for (int j = m - 1; j >= 0; j--) {           int m1 = (i == n - 1) ? -1 : MAX2[i + 1][j];           int m2 = (j == m - 1) ? -1 : MAX2[i][j + 1];           MAX2[i][j] = max(max(m1, m2), SV[i][j]);         }       }       for (int i = 0; i < n; i++) {         for (int j = m - 1; j >= 0; j--) {           int m1 = i == 0 ? 9999999 : MIN1[i - 1][j];           int m2 = (j == m - 1) ? 9999999 : MIN1[i][j + 1];           MIN1[i][j] = min(min(m1, m2), SV[i][j]);         }       }       for (int i = n - 1; i >= 0; i--) {         for (int j = 0; j < m; j++) {           int m1 = (i == n - 1) ? 9999999 : MIN2[i + 1][j];           int m2 = (j == 0) ? 9999999 : MIN2[i][j - 1];           MIN2[i][j] = min(min(m1, m2), SV[i][j]);         }       }       int ansx = -1, ansy = -1;       for (int i = 0; i < n - 1; i++) {         for (int j = 0; j < m - 1; j++) {           if (MAX1[i][j] < MIN2[i + 1][j] &&               MAX2[i + 1][j + 1] < MIN1[i][j + 1]) {             ansx = i;             ansy = j;             break;           }         }       }       if (ansx == -1 && ansy == -1)         cout <<  NO n ;       else {         cout <<  YES n ;         for (int i = 0; i < n; i++) {           if (R[i] <= ansx)             cout <<  B ;           else             cout <<  R ;         }         cout <<    ;         cout << ansy + 1;         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const double INF = 2e50;   double sqr(double a) { return a * a; }   int get_ch(double x, double y) {     if (x <= 0 && y <= 0) return 1;     if (x <= 0 && y >= 0) return 4;     if (x >= 0 && y <= 0) return 2;     return 3;   }   struct pt {     double x, y;     pt(double x, double y) : x(x), y(y) {}     pt() {}     void read() { cin >> x >> y; }     double d() { return sqrt(sqr(x) + sqr(y)); }     pt operator-(pt ot) { return pt(x - ot.x, y - ot.y); }     bool operator==(pt ot) { return x == ot.x && y == ot.y; }     double operator*(const pt ot) const { return (x * ot.y - y * ot.x); }     bool operator<(const pt f) const {       int a = get_ch(x, y);       int b = get_ch(f.x, f.y);       return (a < b || (a == b && (*this) * f >= 0));     }   };   inline double get_an(pt f, pt s) {     return acos((f.x * s.x + f.y * s.y) / f.d() / s.d());   }   inline double vec_m(pt f, pt s) { return (f.x * s.y - f.y * s.x); }   double with_a[501][501], with_b[501][501];   int main() {     int n, m;     cin >> n >> m;     if (!m) {       cout << n * (n - 1) * (n - 2) / 6;       return 0;     }     vector<pt> f(n), s(m);     for (int i = 0; i < n; i++) {       f[i].read();     }     for (int i = 0; i < m; i++) {       s[i].read();     }     double ans = 0;     for (int i = 0; i < n; i++) {       vector<pair<pt, pair<int, int> > > ev(n + m - 1 - i);       int sz = 0;       for (int j = i + 1; j < n; j++) {         if (j == i) continue;         ev[sz++] = make_pair(f[j] - f[i], make_pair(0, j));       }       for (int j = 0; j < m; j++) {         ev[sz++] = make_pair(s[j] - f[i], make_pair(1, j));       }       sort(ev.begin(), ev.end());       for (int j = 0; j < (int)ev.size(); j++) {         pt maxi = pt(INF, INF);         int id = ev[j].second.second;         if (ev[j].second.first) continue;         for (int k = (j + 1) % (int)ev.size();; k = (k + 1) % (int)ev.size()) {           if (k == j) break;           int type = ev[k].second.first;           int to_id = ev[k].second.second;           pt temp = (type ? s[to_id] : f[to_id]);           double to_an = vec_m(f[id] - f[i], temp - f[i]);           if (to_an < 0) break;           if (type) {             if (maxi == pt(INF, INF) || vec_m(maxi - f[id], temp - f[id]) > 0) {               maxi = temp;             }           } else {             if (maxi == pt(INF, INF) || vec_m(maxi - f[id], temp - maxi) > 0) {               ans++;             }           }         }       }     }     cout << fixed << setprecision(0) << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   string st;   int l, memo[1000009][2];   int get(int pos, int carry) {     if (pos < 0) return carry;     int &ret = memo[pos][carry];     if (ret != -1) return ret;     ret = 9999999;     if (carry == 0) {       if (st[pos] ==  0 )         return ret = get(pos - 1, 0);       else {         int ra = get(pos - 1, carry) + 1;         int rb = get(pos - 1, 1 - carry) + 1;         ret = min(ra, rb);         return ret;       }     } else {       if (st[pos] ==  1 )         return ret = get(pos - 1, carry);       else {         int ra = get(pos - 1, 0) + 1;         int rb = get(pos - 1, 1) + 1;         ret = min(ra, rb);         return ret;       }     }   }   int print_path(int pos, int carry) {     if (pos < 0) {       if (carry) printf( +2^%d n , l - pos - 1);       return 0;     }     if (carry == 0) {       if (st[pos] ==  0 )         return print_path(pos - 1, 0);       else {         int ra = get(pos - 1, carry) + 1;         if (ra == memo[pos][carry]) {           printf( +2^%d n , l - pos - 1);           return print_path(pos - 1, carry);         } else {           printf( -2^%d n , l - pos - 1);           return print_path(pos - 1, 1 - carry);         }       }     } else {       if (st[pos] ==  1 )         return print_path(pos - 1, carry);       else {         int ra = get(pos - 1, 0) + 1;         if (ra == memo[pos][carry]) {           printf( +2^%d n , l - pos - 1);           return print_path(pos - 1, 0);         } else {           printf( -2^%d n , l - pos - 1);           return print_path(pos - 1, 1);         }       }     }   }   int main() {     while (cin >> st) {       memset(memo, -1, sizeof memo);       ;       l = st.size();       cout << get(l - 1, 0) << endl;       print_path(l - 1, 0);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   signed main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long x = gcd(c, d);       c /= x;       d /= x;       if (c == 0 && a != 0) {         cout << -1 <<   n ;         continue;       }       if (c == 0 && a == 0) {         cout <<  0 n ;         continue;       }       if (c == d && a != b) {         cout << -1 <<   n ;         continue;       }       if (c == d && a == b) {         cout <<  0 n ;         continue;       }       long long l = (a + c - 1) / c - 1;       long long r = (long long)2e18 / d;       while (r - l > 1) {         long long m = (r + l) / 2;         if (m * d >= b + m * c - a) {           r = m;         } else {           l = m;         }       }       cout << r * d - b <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n = 0, a = 0;     cin >> n >> a;     long long int ar[n];     long long int i = 0;     for (i = 0; i < n; i++) cin >> ar[i];     long long int pos = a - 1;     if (n == 1) {       if (ar[0] == 1)         cout <<  1  << endl;       else         cout <<  0  << endl;     } else if (n == 2) {       if ((ar[0] == 1) && (ar[1] == 1))         cout <<  2  << endl;       else if ((ar[0] == 1) || (ar[1] == 1))         cout <<  1  << endl;       else         cout <<  0  << endl;     } else {       long long int low = pos - 1;       long long int high = pos + 1;       long long int ans = 0;       if (ar[pos] == 1) ans++;       while ((low >= 0) || (high < n)) {         long long int l1 = ar[low];         long long int l2 = ar[high];         if ((low >= 0) && (high < n) && (l1 == 1) && (l2 == 1))           ans += 2;         else if ((low >= 0) && (high >= n) && (l1 == 1))           ans++;         else if ((low < 0) && (high < n) && (l2 == 1))           ans++;         else           ans = ans;         low--;         high++;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int arr[100][100];   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 0; i < n * n; i++) {       scanf( %d%d , &a, &b);       if (!arr[a][b]) {         printf( %d  , i + 1);         for (int y = 0; y <= n; y++) {           arr[a][y] = 1;           arr[y][b] = 1;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename A, typename B = A>   using pr = pair<A, B>;   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     cout << fixed << setprecision(10);     int sy, a, b;     cin >> sy >> a >> b;     sy = -sy;     int n;     cin >> n;     vector<pr<int>> segs(n);     for (auto &[x, y] : segs) cin >> y >> x;     sort((segs).begin(), (segs).end());     vector<ll> pref(n + 1);     for (int i = 0; i < n; i++)       pref[i + 1] = pref[i] + segs[i].first - segs[i].second;     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       auto get = [&](int k) { return (k - x) * double(y) / (sy + y); };       double x1 = x + get(a);       double x2 = x + get(b);       auto find = [&](double x) {         return int(upper_bound((segs).begin(), (segs).end(),                                pr<int>{ceil(x + 1e-6), -1}) -                    segs.begin());       };       int i1 = find(x1);       int i2 = find(x2);       double sum = 0;       if (i2 != i1) {         sum += pref[i2] - pref[i1 + 1];         if (i1 != -1)           sum +=               min<double>(segs[i1].first - segs[i1].second, segs[i1].first - x1);         if (i2 != n) sum += max<double>(0, x2 - segs[i2].second);       } else {         int i = i2;         if (i != -1 && i != n)           sum += max<double>(0, min<double>(segs[i].first, x2) -                                     max<double>(segs[i].second, x1));       }       cout << sum * (sy + y) / y <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int limit = 3000000;   const int tope = 100000;   int absolut(int x) {     if (x < 0) return -x;     return x;   }   void die() {     cout << -1 << endl;     exit(0);   }   int n;   int a[limit];   int b[limit];   int add[limit];   long long int nsol;   vector<pair<int, int> > vsol;   void fix(int pos) {     while (int(vsol.size()) < tope and add[pos] > 0 and a[pos] < 9 and            a[pos + 1] < 9) {       a[pos]++;       a[pos + 1]++;       add[pos]--;       vsol.push_back(pair<int, int>(pos, 1));     }     while (int(vsol.size()) < tope and add[pos] < 0 and a[pos] > 0 and            a[pos + 1] > 0) {       a[pos]--;       a[pos + 1]--;       add[pos]++;       vsol.push_back(pair<int, int>(pos, -1));     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       a[i] = c -  0 ;     }     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       b[i] = c -  0 ;     }     for (int i = 1; i < n; i++) {       add[i] = b[i] - (a[i] + add[i - 1]);       nsol += absolut(add[i]);     }     if (a[n] + add[n - 1] != b[n]) die();     while (int(vsol.size()) < nsol and int(vsol.size()) < tope) {       for (int pos = 1; pos < n and int(vsol.size()) < tope; pos++) fix(pos);       for (int pos = n - 1; pos >= 1 and int(vsol.size()) < tope; pos--) fix(pos);     }     cout << nsol << endl;     for (int i = 0; i < int(vsol.size()) and i < tope; i++)       cout << vsol[i].first <<     << vsol[i].second << endl;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > q;   int tar[100005];   int n, k, add;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> tar[i];     long long ans = 0;     cin >> add;     int tmp;     for (int i = 1; i <= n; i++) {       cin >> tmp;       q.push(tmp);       while (k < tar[i]) {         if (q.empty()) {           cout << -1 << endl;           return 0;         }         k += add;         ans += q.top();         q.pop();       }     }     cout << ans << endl;   }