malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int Count(int ar[], int m, int n) {     int count = 0, i;     for (i = 0; i < n; i++) {       if (ar[i] == m) {         count++;       }     }     return count;   }   void change(int br[], int ar[], int n, int clr, int d, int m) {     int count = 0, i;     for (i = 0; i < n; i++) {       if (ar[i] == m) {         count++;         br[i] = ceil(float(count) / d) + clr;         ar[i] = -1;       }     }   }   int main() {     int n, i, cnt = 0;     cin >> n;     int ar[n], br[n];     for (i = 0; i < n; i++) {       br[i] = 0;     }     for (i = 0; i < n; i++) {       cin >> ar[i];       if (ar[i] == 0) {         cnt++;       }     }     if (cnt == n) {       cout <<  Possible n ;       for (i = 0; i < n; i++) {         cout << 1 <<    ;       }       return 0;     }     if (cnt != 0) {       cout <<  Impossible ;       return 0;     }     int m, count, clr = 0;     m = *max_element(ar, ar + n);     while (m != -1) {       m = *max_element(ar, ar + n);       count = Count(ar, m, n);       if ((n - count) > m) {         cout <<  Impossible ;         return 0;       }       if (m == n - count) {         change(br, ar, n, clr, count, m);         clr++;       } else {         int bp = m - (n - count);         if (bp % (count - bp) == 0) {           change(br, ar, n, clr, count - bp, m);           clr += count / (count - bp);         } else {           cout <<  Impossible ;           return 0;         }       }       m = *max_element(ar, ar + n);     }     cout <<  Possible n ;     for (i = 0; i < n; i++) {       cout << br[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct hash_pair {     template <class T1, class T2>     size_t operator()(const pair<T1, T2>& p) const {       auto hash1 = hash<T1>{}(p.first);       auto hash2 = hash<T2>{}(p.second);       return hash1 ^ hash2;     }   };   string ans =   ;   int flag = 0;   int res = 0;   void permut(string n, int s, int l) {     if (flag == 1) return;     if (s == l) {       if ((res * 10000 + stoi(n)) % 7 == 0) {         flag = 1;         ans += n;       }       return;     }     for (int i = s; i <= l; i++) {       swap(n[s], n[i]);       permut(n, s + 1, l);       swap(n[s], n[i]);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string n;     cin >> n;     int one = 0;     int six = 0;     int eight = 0;     int nine = 0;     string zero =   ;     for (int i = 0; i < n.length(); i++) {       if (n[i] ==  1  && one == 0) {         one = 1;       } else if (n[i] ==  6  && six == 0) {         six = 1;       } else if (n[i] ==  8  && eight == 0) {         eight = 1;       } else if (n[i] ==  9  && nine == 0) {         nine = 1;       } else {         if (n[i] ==  0  && ans.length() == 0) {           zero +=  0 ;         } else {           ans += n[i];           res *= 10;           res += n[i] -  0 ;           res %= 7;         }       }     }     permut( 1689 , 0, 3);     if (ans.length() != 0)       cout << ans + zero;     else       cout <<  0 ;   }
#include <bits/stdc++.h>   using namespace std;   const int NUM = 2e5 + 10;   struct node {     int index, q;     bool operator<(const node &a) const { return index + q < a.index + a.q; }   } no[NUM];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &no[i].index, &no[i].q);     sort(no, no + n);     int ans = 1, last = 0;     for (int i = 1; i < n; i++) {       if (no[i].index - no[i].q >= no[last].index + no[last].q) {         last = i;         ans++;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[105], k;   int n;   bool check(long long x) {     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += (arr[i] + x - 1LL) / x;     }     return x * sum <= k;   }   int main(int argc, char const *argv[]) {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> arr[i], k += arr[i];     long long ans = 0;     for (long long i = 1; i <= sqrt(k) + 1; i++) {       if (check(i)) ans = max(ans, i);       if (check(k / i)) ans = max(ans, k / i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int cnt, n;     cin >> n;     cnt = 0;     cnt += n / 100;     n %= 100;     cnt += n / 20;     n %= 20;     cnt += n / 10;     n %= 10;     cnt += n / 5;     n %= 5;     cnt += n;     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   int Cmp(const void *a, const void *b);   int main(void) {     int i, n, x, w, gpos = -2 * 1000000000, ans = 0, grange[200000][2];     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &x, &w);       grange[i][0] = x - w;       grange[i][1] = x + w;     }     qsort(grange, n, sizeof(int) * 2, Cmp);     for (i = 0; i < n; i++) {       if (gpos <= grange[i][0]) {         ans++;         gpos = grange[i][1];       }     }     printf( %d n , ans);   }   int Cmp(const void *a, const void *b) {     int ta = *(*(int(*)[2])a + 1), tb = *(*(int(*)[2])b + 1);     if (ta > tb)       return 1;     else if (tb > ta)       return -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       map<int, int> cur;       set<pair<int, int>> st;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (!cur.count(a[i])) {           st.insert(make_pair(a[i], i));         }         cur[a[i]] = i;       }       if (st.size() == 1) {         cout <<  NO  << endl;         continue;       } else {         cout <<  YES  << endl;         vector<pair<int, int>> res;         auto e = st.begin(), g = prev(st.end());         for (int i = 0; i < n; i++) {           if (a[i] != e->first) {             res.emplace_back(i + 1, e->second + 1);           } else if (i != g->second && i != e->second)             res.emplace_back(i + 1, g->second + 1);         }         for (auto j : res) cout << j.first <<     << j.second << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool a[1000010];   int main() {     memset(a, 0, sizeof(a));     int n, ans = 0;     cin >> n;     int f = 2;     for (;;) {       if (a[f] == 0) {         for (int i = 2 * f; i <= 1000000; i = i + f) a[i] = 1;       }       f++;       if (f == 1000000) break;     }     for (int i = 10;; i++) {       int i1 = i, i2 = 0;       while (i1 > 0) {         i2 = i2 * 10 + i1 % 10;         i1 = i1 / 10;       }       if (a[i2] == 0 && a[i] == 0 && i2 != i) ans++;       if (ans == n) {         cout << i << endl;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Max = INT_MIN, Min = INT_MAX;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m, mx = 0;     cin >> n >> m;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       if ((a[i] - a[i + 1] - m) > mx) {         mx = (a[i] - a[i + 1] - m);       }     }     cout << ((mx > 0) ? mx : 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, n, i, j, z, mx;   string s, s2;   int main() {     cin >> a >> b >> c;     mx = max(max(a, b), c);     for (i = 1; i <= mx; i++) {       for (j = 1; j <= mx; j++) {         z = c / j;         if (i * j == a && i * z == b && j * z == c) {           cout << i * 4 + j * 4 + z * 4;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ways[5050][5050], last[27], fat[5050], ifat[5050];   char s[5050];   int expo(int b, int e) {     if (!e) return 1;     if (e & 1)       return 1LL * b * expo(1LL * b * b % 1000000007, e >> 1) % 1000000007;     return expo(1LL * b * b % 1000000007, e >> 1);   }   int invmod(int x) { return expo(x, 1000000007 - 2); }   void prep() {     fat[0] = 1;     for (int i = 1; i < 5050; i++) fat[i] = 1LL * fat[i - 1] * i % 1000000007;     ifat[5050 - 1] = invmod(fat[5050 - 1]);     for (int i = 5050 - 1; i > 0; i--)       ifat[i - 1] = 1LL * ifat[i] * i % 1000000007;     assert(ifat[0] == 1);   }   long long nCr(int n, int k) {     return 1LL * fat[n] * ifat[k] % 1000000007 * ifat[n - k] % 1000000007;   }   int main() {     scanf( %d %s , &n, s + 1);     prep();     s[0] = char( a  + 26);     last[26] = n + 1;     ways[n + 1][0] = 1;     for (int i = n; i >= 0; i--) {       for (int c = 0; c < 27; c++) {         if (c == (s[i] -  a ) || (last[c] == 0)) continue;         for (int j = 0; j < (n - i + 1); j++) {           ways[i][j + 1] += ways[last[c]][j];           if (ways[i][j + 1] >= 1000000007) ways[i][j + 1] -= 1000000007;         }       }       last[s[i] -  a ] = i;     }     long long ans = 0;     for (int i = 2; i <= n + 1; i++) {       ans = (ans + nCr(n - 1, i - 2) * ways[0][i]) % 1000000007;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6;   long long seg_t[MAXN * 4];   long long n, k, cur, ans = 1;   void add(long long u, long long curl, long long curr, long long l, long long r,            long long delta) {     long long curm = (curl + curr) / 2;     if (l == curl && r == curr) {       seg_t[u] += delta;       return;     }     if (l <= curm) {       if (r >= curm) {         add(u * 2, curl, curm, l, curm, delta);       } else {         add(u * 2, curl, curm, l, r, delta);       }     }     if (r >= curm + 1) {       if (l <= curm + 1) {         add(u * 2 + 1, curm + 1, curr, curm + 1, r, delta);       } else {         add(u * 2 + 1, curm + 1, curr, l, r, delta);       }     }   }   long long get(long long u, long long curl, long long curr, long long x) {     long long ret = 0;     long long curm = (curl + curr) / 2;     ret += seg_t[u];     if (curl == curr) return ret;     if (x <= curm) {       ret += get(u * 2, curl, curm, x);     } else if (x >= curm + 1) {       ret += get(u * 2 + 1, curm + 1, curr, x);     }     return ret;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     k = min(k, n - k);     long long r, l = 1;     for (long long i = 0; i < n; ++i) {       r = l + k;       if (r > n) {         add(1, 1, n + 1, l + 1, n + 1, 1);         r -= n;         if (r > 1) add(1, 1, n + 1, 1, r - 1, 1);       } else {         add(1, 1, n + 1, l + 1, r - 1, 1);       }       ans += 1 + get(1, 1, n + 1, l) + get(1, 1, n + 1, r);       cout << ans <<    ;       l = r;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100;   int ara[N];   int main() {     int n = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , ara + i);     }     if (n == 1)       puts( -1 );     else if (n == 2 && ara[0] == ara[1])       puts( -1 );     else {       int mn = 10000;       int nm = 0;       for (int i = 0; i < n; ++i) {         if (ara[i] < mn) {           mn = ara[i];           nm = i;         }       }       ++nm;       printf( 1 n%d n , nm);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define int long long   struct node{    int x, y, id;    bool operator <(const node& W) const{     if (W.x != x) return x < W.x;     else return y < W.y;    }   };      void work() {    int n;    cin >> n;    vector<node> v(n);    for (int i = 0; i < n; i++) {     int x, y;     cin >> x >> y;     if (x > y) swap(x, y);     v[i] = {x, y, i + 1};    }    sort(v.begin(), v.end());    vector<int> res(n + 1);    int pos = -1;        for (int i = 0; i < v.size(); i++) {     int j = i;     while (j < v.size() && v[i].x == v[j].x) j++;     j--;     if (pos == -1) for (int k = i; k <= j; k++) res[v[k].id] = -1;     else {      for (int k = i; k <= j; k++)        if (v[k].y > v[pos].y) res[v[k].id] = v[pos].id;       else res[v[k].id] = -1;     }     if (pos == -1) pos = 0;     else if (v[i].y < v[pos].y) pos = i;     i = j;    }        for (int i = 1; i < res.size(); i++) cout << res[i] <<    ;    cout << endl;   }   int32_t main() {    ios::sync_with_stdio(false);    cin.tie(0);    int cas;    cin >> cas;    while (cas--) work();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> sieve;   vector<long long int> *Sieve(int N) {     const long long int maxn = N;     sieve.resize(maxn);     for (long long int(i) = 0; (i) < (maxn); ++(i)) sieve[i] = 1;     sieve[1] = 0;     sieve[0] = 0;     for (long long int(i) = 2; (i) <= (maxn); (i) += (1))       if (1 == sieve[i])         for (long long int j = i * i; j < maxn; j += i) sieve[j] = 0;     vector<long long int> *primes = new vector<long long int>();     primes->push_back(2);     for (int i = 3; i < maxn; i += 2)       if (sieve[i]) {         primes->push_back(i);       }     return primes;   }   long long int extended_GCD(long long int a, long long int b, long long int &x,                              long long int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long int x1, y1;     long long int gcd = extended_GCD(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   }   long long int ncr(long long int n, long long int k) {     long long int r = 1;     if (k > n - k) k = n - k;     for (long long int i = 0; i < k; i++) {       r *= (n - i);       r /= (i + 1);     }     return r;   }   long long int power(long long int a, long long int b,                       long long int m = 1000000007) {     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 modinv(long long int a, long long int mod = 1000000007) {     long long int x, y;     extended_GCD(a, mod, x, y);     if (x < 0) x += mod;     return x;   }   bool prime(int n) {     int c = 0;     for (int i = 2; (i * i) <= n; i++) {       if (n % i == 0) {         c++;         return false;       }     }     if (c == 0) return true;   }   vector<int> v[200006];   int vis[200006];   int c;   void dfs(int n) {     vis[n] = 1;     c++;     for (int i : v[n]) {       if (!vis[i]) dfs(i);     }   }   int a[100001];   void solve() {     int n, k;     cin >> n >> k;     int a[n];     for (long long int(i) = 0; (i) < (n); ++(i)) cin >> a[i];     int sa = 1, sb = 1;     double ca = 0, cb = k;     int i = 0, j = n - 1;     double ans = 0;     while (i <= j) {       double t1, t2, d1, d2;       d1 = a[i] - ca;       d2 = cb - a[j];       t1 = (double)d1 / sa;       t2 = (double)d2 / sb;       if (t1 <= t2) {         ans += t1;         ca += d1;         i++;         sa++;         cb -= (double)t1 * sb;       } else {         ans += t2;         cb -= d2;         j--;         sb++;         ca += (double)t2 * sa;       }     }     ans += double(cb - ca) / (sa + sb);     cout << fixed << setprecision(10) << ans;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long int    int main()   {       int t;       cin>>t;       while(t--)       {           ll n;           cin>>n;           vector<ll>a(n);           for(ll i=0;i<n;i++)           {               cin>>a[i];           }           ll maxi=INT_MIN;           for(ll i=n-1;i>-1;i--)           {               ll total=0;               total+=a[i];               if(i+a[i]<n)               {                   total+=a[i+a[i]];               }               a[i]=total;               maxi=max<ll>(maxi,total);           }           //cout<<  t ;           cout<<maxi<<  n ;       }   }
#include <bits/stdc++.h>   using namespace std;   class subtractions {    private:     int _a, _b;     int _operations;     bool even_divide(int& a, int& b) {       if (b > a && !(b % a)) {         _operations += (b / a);         return true;       } else if (a >= b && !(a % b)) {         _operations += (a / b);         return true;       }       return false;     }     bool quick_divide(int& a, int& b) {       if (b > a) {         int factor = b / a;         b -= a * factor;         _operations += factor;         return true;       } else if (a >= b) {         int factor = a / b;         a -= b * factor;         _operations += factor;         return true;       }       return false;     }       public:     subtractions(int a = 0, int b = 0) : _a(a), _b(b) { _operations = 0; }     int operate() {       while (_a > 0 && _b > 0) {         if (even_divide(_a, _b)) break;         if (quick_divide(_a, _b)) continue;         ++_operations;       }       return _operations;     }   };   int main() {     int tests = 0;     cin >> tests;     while (tests > 0) {       int a, b;       cin >> a >> b;       subtractions s(a, b);       cout << s.operate() << endl;       --tests;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long w[3][300500];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0, qwerty = n; i < qwerty; i++) {       cin >> s;       stack<char> st;       st.push(s[0]);       for (int j = 1, qwerty = s.size(); j < qwerty; j++) {         char c = s[j];         if (!st.empty() && c ==  )  && st.top() ==  ( )           st.pop();         else           st.push(c);       }       int r1 = 0, r2 = 0;       while (!st.empty()) {         if (st.top() ==  ( )           r1++;         else           r2++;         st.pop();       }       if (r1 && r2) continue;       if (r1 + r2 == 0)         w[2][0]++;       else if (r1)         w[0][r1]++;       else if (r2)         w[1][r2]++;     }     long long ans = w[2][0] * w[2][0];     if (w[2][0] == 1) ans = 1;     for (int i = 0, qwerty = 300200; i < qwerty; i++) ans += w[0][i] * w[1][i];     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, t;     cin >> t;     while (t--) {       cin >> a >> b;       int num = abs(a - b);       if (a > b && num % 2 != 0)         cout << 2 << endl;       else if (a < b && num % 2 != 0)         cout << 1 << endl;       else if (a > b && num % 2 == 0)         cout << 1 << endl;       else if (a < b && num % 2 == 0)         cout << 2 << endl;       else if (a == b)         cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct DSU {     struct Node {       int pr;       long long max_sum;       long long max_pref;       long long sum;       long long max_suff;     };     vector<Node> t;     multiset<long long> mx;     DSU(int n, vector<int>& c) {       t.resize(n);       for (int i = 0; i < n; ++i) {         t[i].pr = i;         t[i].sum = c[i];         t[i].max_sum = max(0, c[i]);         t[i].max_pref = max(0, c[i]);         t[i].max_suff = max(0, c[i]);         mx.insert(t[i].max_sum);       }     }     int f(int v) {       if (t[v].pr != v) {         t[v].pr = f(t[v].pr);       }       return t[v].pr;     }     void merge(int x, int y) {       x = f(x);       y = f(y);       if (x == y) {         return;       }       t[x].pr = y;       mx.erase(mx.lower_bound(t[x].max_sum));       mx.erase(mx.lower_bound(t[y].max_sum));       Node new_node;       new_node.sum = t[x].sum + t[y].sum;       new_node.pr = y;       new_node.max_sum = max(t[y].max_sum, t[x].max_sum);       new_node.max_sum = max(new_node.max_sum, t[x].max_suff + t[y].max_pref);       new_node.max_pref = max(t[x].max_pref, t[x].sum + t[y].max_pref);       new_node.max_suff = max(t[y].max_suff, t[y].sum + t[x].max_suff);       new_node.max_sum = max(new_node.max_sum, 0LL);       new_node.max_pref = max(new_node.max_pref, 0LL);       new_node.max_suff = max(new_node.max_suff, 0LL);       t[y] = new_node;       mx.insert(t[y].max_sum);     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long long m;     cin >> n >> m;     vector<int> d(n), c(n);     for (int i = 0; i < n; ++i) {       cin >> d[i] >> c[i];       c[i] = m - c[i];     }     set<pair<int, int> > q;     for (int i = 0; i + 1 < n; ++i) {       q.insert({d[i + 1] - d[i], i});     }     q.insert({-1, -1});     DSU t(n, c);     long long ans = 0;     while (q.size()) {       auto i = *q.begin();       q.erase(q.begin());       if (i.second != -1) {         t.merge(i.second, i.second + 1);         ans = max(ans, *--t.mx.end() - i.first * 1LL * i.first);       } else {         ans = max(ans, *--t.mx.end());       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     int n;     scanf( %d , &n);     int i;     if (n % 2 != 0) {       printf( -1 n );     } else {       if (n > 2) {         for (i = 1; i <= n - 2; i++) {           printf( %d  , i + 1);           printf( %d  , i);           i++;         }       }       printf( %d  , n);       printf( %d n , n - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, a[200005], b[200005];   int main() {     cin >> n;     for (int i = 1; i <= n / 2; i++) cin >> b[i];     a[1] = 0;     a[n] = b[1];     for (int i = 2; i <= n / 2; i++) {       a[i] = a[i - 1];       a[n - i + 1] = b[i] - a[i];       if (a[n - i + 1] > a[n - i + 2]) {         a[n - i + 1] = a[n - i + 2];         a[i] = b[i] - a[n - i + 1];       }     }     for (int i = 1; i <= n; i++) {       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int i, j, ft;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n;     cin >> n;     vector<long long int> v[n];     for (i = 0; i < (n - 1); i++) {       long long int b, c;       cin >> b >> c;       v[b - 1].push_back(c - 1);       v[c - 1].push_back(b - 1);     }     vector<long long int> l(n, 0);     queue<long long int> s;     s.push(0);     l[0] = 1;     while (!s.empty()) {       long long int front = s.front();       s.pop();       for (i = 0; i < (v[front].size()); i++) {         if (!l[v[front][i]]) {           s.push(v[front][i]);           l[v[front][i]] = l[front] + 1;         }       }     }     long long int odd = 0, even = 0;     for (i = 0; i < (n); i++) {       if (l[i] % 2)         odd++;       else         even++;     }     cout << odd * even - n + 1 <<   n ;     return 0;   }