malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     char c;     char prev;     vector<int> A;     int i = 0, count = 1;     scanf( %c , &prev);     A.push_back(1);     while (scanf( %c , &c) != EOF) {       if (c !=  +  && c !=  - ) continue;       if (c == prev) {         A[i]++;       } else {         if (!(A[i] & 1)) {           if (i != 0) {             A[i - 1] += A[i];             A.erase(A.begin() + i);             i--;           }           A[i]++;           prev = c;         } else {           A.push_back(1);           i++;           prev = c;         }       }     }     int flag = 0;     while (flag == 0 && A.size() != 1) {       flag = 1;       for (vector<int>::iterator it = A.begin(); it != A.end(); it++) {         if (!((*it) & 1)) {           flag = 0;           if (it != A.begin()) {             *it += *(it - 1);           }           if ((it + 1) != A.end()) {             *it += *(it + 1);           }           if ((it + 1) != A.end()) A.erase(it + 1);           if (it != A.begin()) A.erase(it - 1);           break;         }       }     }     if (A.size() == 1 && !(A[0] & 1))       cout <<  Yes n ;     else       cout <<  No n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   vector<int> g[N];   int used[N], cant, pep[N][N];   void dfs(int u, int col) {     if (g[u].size() == 0) return;     used[u] = col;     int ncol = ((col == 1) ? 2 : 1);     for (int v : g[u])       if (!used[v]) {         dfs(v, ncol);       } else if (used[v] == col) {         cant = 1;       }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       pep[u][v] = pep[v][u] = 1;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (!pep[i][j] && i != j) {           g[i].push_back(j);         }       }     }     for (int i = 1; i <= n; ++i) {       if (!used[i]) dfs(i, 1);     }     if (cant) {       printf( No n );       return 0;     }     char s[N];     for (int i = 1; i <= n; ++i) {       if (used[i] == 1) {         s[i - 1] =  a ;       } else if (used[i] == 2) {         s[i - 1] =  c ;       } else {         s[i - 1] =  b ;       }     }     s[n] =   0 ;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (pep[i][j]) {           if (abs(s[i - 1] - s[j - 1]) > 1) {             printf( No n );             return 0;           }         }       }     }     printf( Yes n%s n , s);     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   bool vis[N];   int trie[N * 20][2], sz;   void inser(int n) {     int curr = 0;     for (int i = 19; i >= 0; i--) {       int dir = (n >> i) & 1;       if (trie[curr][dir] == -1) trie[curr][dir] = ++sz;       curr = trie[curr][dir];     }   }   int query(int n) {     int curr = 0, ans = 0;     for (int i = 19; i >= 0; i--) {       int dir = (n >> i) & 1;       if (trie[curr][dir] != -1) {         curr = trie[curr][dir];       } else {         ans += (1 << i);         curr = trie[curr][1 ^ dir];       }     }     return ans;   }   int main() {     memset(trie, -1, sizeof(trie));     int n, q;     scanf( %d%d , &n, &q);     while (n--) {       int a;       scanf( %d , &a);       vis[a] = true;     }     for (int i = 0; i < N; i++)       if (!vis[i]) inser(i);     int xorval = 0;     while (q--) {       int x;       scanf( %d , &x);       xorval ^= x;       printf( %d n , query(xorval));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const long long M = 1000003;   struct ban {     long long x;     ban() { x = 0; }     ban(long long x) { this->x = x % M; }   };   bool operator<(const ban& a, const ban& b) { return a.x < b.x; }   bool operator>(const ban& a, const ban& b) { return a.x > b.x; }   bool operator==(const ban& a, const ban& b) { return a.x == b.x; }   ban operator+(const ban& a, const ban& b) { return ban(a.x + b.x); }   ban operator*(const ban& a, const ban& b) { return ban(a.x * b.x); }   ban ast(ban x, int n) {     if (n == 0) return ban(1);     if (n % 2 == 0) {       ban y = ast(x, n / 2);       return y * y;     } else {       ban y = ast(x, n - 1);       return x * y;     }   }   ban operator/(const ban& a, const ban& b) { return a * ast(b, M - 2); }   ban operator-(const ban& a, const ban& b) { return ban(a.x - b.x + M); }   const int n = 50;   const int m = 10;   ban a[N][N];   ban b[N];   int w[N];   ban g[N];   int solv() {     for (int ii = 1; ii <= n; ++ii) {       cout <<  ?   << ii << endl;       cin >> b[ii].x;       for (int j = 0; j <= m; ++j) a[ii][j] = ast(ban(ii), j);     }     for (int jj = 0, ii = 1; jj <= m && ii <= n; ++jj) {       ban maxu;       int maxi;       for (int i = ii; i <= n; ++i) {         if (a[i][jj] > maxu) {           maxu = a[i][jj];           maxi = i;         }       }       w[jj] = ii;       for (int j = 0; j <= m; ++j) {         swap(a[ii][j], a[maxi][j]);       }       swap(b[ii], b[maxi]);       for (int i = 1; i <= n; ++i) {         if (i == ii) continue;         ban t = a[i][jj] / a[ii][jj];         for (int j = jj; j <= m; ++j) {           a[i][j] = a[i][j] - a[ii][j] * t;         }         b[i] = b[i] - b[ii] * t;       }       ++ii;     }     for (int jj = 0; jj <= m; ++jj) {       int ii = w[jj];       if (ii == 0) continue;       g[jj] = b[ii] / a[ii][jj];     }     for (int x = 0; x < M; ++x) {       ban u;       for (int j = 0; j <= m; ++j) {         u = u + g[j] * ast(ban(x), j);       }       if (u.x == 0) return x;     }     return -1;   }   int main() {     int x = solv();     cout <<  !   << x << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   const int maxn = 1e6 + 50;   int seg[2 * maxn], ans[maxn], last_pos[maxn], next_pos[maxn];   int n, m;   vector<int> v, get_val, partial_xor;   vector<pair<pair<int, int>, int> > ques;   void update(int val, int l, int r = n) {     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) seg[l++] ^= val;       if (r & 1) seg[--r] ^= val;     }   }   int get_xor(int idx) {     int res = 0;     for (idx += n; idx; idx >>= 1) res ^= seg[idx];     return res;   }   void sweep(int pos) {     int val = get_val[v[pos]];     int nxt = next_pos[pos];     update(val, pos, nxt);   }   void input() {     cin >> n;     for (int i = 0; i < n; i++) {       int b;       cin >> b;       if (i == 0)         partial_xor.push_back(b);       else         partial_xor.push_back(partial_xor[i - 1] ^ b);       get_val.push_back(b);       v.push_back(b);       last_pos[i] = n;     }     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--, r--;       ques.push_back({{l, r}, i});     }   }   void map_it() {     sort(get_val.begin(), get_val.end());     get_val.resize(unique((get_val).begin(), (get_val).end()) - get_val.begin());     for (int i = v.size() - 1; i > -1; i--) {       v[i] =           lower_bound((get_val).begin(), (get_val).end(), v[i]) - get_val.begin();       next_pos[i] = last_pos[v[i]];       last_pos[v[i]] = i;     }     for (int i = 0; i < get_val.size(); i++) update(get_val[i], last_pos[i]);   }   void answer_ques(int i) {     pair<int, int> p = ques[i].first;     ans[ques[i].second] = get_xor(p.second) ^ partial_xor[p.first] ^                           partial_xor[p.second] ^ get_val[v[p.first]];   }   void calc() {     int go_pos = 0;     int i = 0;     sort(ques.begin(), ques.end());     while (go_pos < ques.size()) {       while (go_pos < ques.size() and i == ques[go_pos].first.first)         answer_ques(go_pos++);       if (go_pos == ques.size()) break;       while (i < ques[go_pos].first.first) sweep(i++);     }   }   void ansing() {     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     input();     map_it();     calc();     ansing();   }
#include <bits/stdc++.h>   const long long mod = 1e9 + 7;   const int N = 1e5 + 20;   using namespace std;   int main() {     int n, s[N], m;     s[0] = 0;     cin >> n;     for (int i = (1); i <= (n); i++) {       cin >> m;       s[i] = s[i - 1] + m;     }     cin >> m;     for (int i = (1); i <= (m); i++) {       int x, y;       cin >> x >> y;       cout << (s[y] - s[x - 1]) / 10 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     int out;     cin >> m >> n;     if (m >= n && m >= 2) {       out = (m / 2) * n;       if (m % 2 && n / 2) {         out += (n / 2);       }     } else if (n > m && n >= 2) {       out = (n / 2) * m;       if (n % 2 && m / 2) {         out += (m / 2);       }     } else {       out = 0;     }     cout << out;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 7;   const int MOD = (int)1e9 + 7;   const long long INF = (long long)1e18 + 7;   vector<vector<long long>> a;   long long col[N], row[N], trow[N], tcol[N];   long long res;   int m, n;   long long getrow() {     long long ma = trow[1];     long long pos = 1;     for (int i = 2; i <= m; i++)       if (trow[i] > ma) {         ma = trow[i];         pos = i;       }     trow[pos] = 0;     for (int i = 1; i <= n; i++) tcol[i] -= a[pos][i];     return max(0ll, ma);   }   long long getcol() {     long long ma = tcol[1];     long long pos = 1;     for (int i = 2; i <= n; i++)       if (tcol[i] > ma) {         ma = tcol[i];         pos = i;       }     tcol[pos] = 0;     for (int i = 1; i <= m; i++) trow[i] -= a[i][pos];     return max(0ll, ma);   }   void sett() {     for (int i = 1; i <= m; i++) trow[i] = row[i];     for (int i = 1; i <= n; i++) tcol[i] = col[i];   }   void proces(int st, int nd, int rd, int th) {     long long ma = 0;     sett();     if (st)       ma += getcol();     else       ma += getrow();     if (nd)       ma += getcol();     else       ma += getrow();     if (rd)       ma += getcol();     else       ma += getrow();     if (th)       ma += getcol();     else       ma += getrow();     res = max(res, ma);   }   int main() {     cin >> m >> n;     a.resize(m + 1);     for (int i = 1; i <= m; i++) {       a[i].push_back(0);       long long t;       for (int j = 1; j <= n; j++) {         cin >> t;         a[i].push_back(t);       }     }     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) row[i] += a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) col[i] += a[j][i];     for (int a1 = 0; a1 <= 1; a1++)       for (int a2 = 0; a2 <= 1; a2++)         for (int a3 = 0; a3 <= 1; a3++)           for (int a4 = 0; a4 <= 1; a4++) proces(a1, a2, a3, a4);     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[10001];   const long long INF = 1e60 + 7;   long long binpow(long long a, long long b) {     if (a == 0) {       return 0;     }     if (b == 0) return 1;     long long temp = binpow(a, b / 2);     if (b & 1) {       return temp * temp * a;     } else       return temp * temp;   }   long long poweroftwo(long long n) {     if ((n && n & (n - 1)) == 0)       cout <<  y ;     else       cout <<  n ;   }   long long binarysearch(long long a[], long long l, long long r, long long x) {     while (l <= r) {       long long mid = l + (r - l) / 2;       if (a[mid] == x)         return 1;       else if (a[mid] > x) {         r = mid - 1;       } else {         l = mid + 1;       }     }     return 0;   }   long long findSplitPoint(long long arr[], long long n) {     long long leftSum = 0;     for (long long i = 0; i < n; i++) {       leftSum += arr[i];       long long rightSum = 0;       for (long long j = i + 1; j < n; j++) rightSum += arr[j];       if (leftSum == rightSum) return i + 1;     }     return -1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     {       long long n, m;       cin >> n >> m;       long long ans = 0;       for (long long i = 0; i < n; i++) {         long long x;         cin >> x;         ans = ans + x;         cout << ans / m <<    ;         ans = ans % m;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int fx[] = {+1, -1, +0, +0, +1, +1, -1, -1, +0};   int fy[] = {+0, +0, +1, -1, +1, -1, +1, -1, +0};   template <typename T>   inline T GCD(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <typename T>   inline T LCM(T x, T y) {     T tp = GCD(x, y);     if ((x / tp) * 1. * y > 9e18) return 9e18;     return (x / tp) * y;   }   template <typename T>   inline T BigMod(T A, T B, T M) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   template <typename T>   inline T ModInv(T A, T M) {     return BigMod(A, M - 2, M);   }   template <typename T>   bool scani(T &n) {     n = 0;     bool got = false;     bool negative = false;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) negative = true;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       got = true;       n = n * 10 + c - 48;       c = getchar();     }     if (negative) n = ~(n - 1);     return got;   }   template <typename T>   void write(T n, bool line = true) {     if (n < 0) {       putchar( - );       n = -n;     }     if (!n) {       putchar( 0 );       if (line) putchar(  n );       return;     }     char buff[22];     int len = 0;     while (n) buff[len++] = n % 10 + 48, n /= 10;     for (int i = len - 1; i >= 0; i--) putchar(buff[i]);     if (line) putchar(  n );   }   int scans(char *a) {     int i = 0;     char c = 0;     while (c < 33) c = getchar();     while (c > 33) {       a[i++] = c;       c = getchar();     }     a[i] = 0;     return i;   }   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e;     write(min(min(min(a / 1, b / 1), min(c / 2, d / 7)), e / 4));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   bool vis[MAXN];   char str[MAXN];   int main() {     gets(str);     int len = strlen(str);     char maxch = 0;     memset(vis, false, sizeof(vis));     for (int i = len - 1; i >= 0; i--) {       if (str[i] >= maxch) vis[i] = true;       maxch = max(maxch, str[i]);     }     for (int i = 0; i < len; i++) {       if (vis[i]) putchar(str[i]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   template <class T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <class T>   inline void umin(T &x, T y) {     x = x < y ? x : y;   }   template <class T>   inline void umax(T &x, T y) {     x = x > y ? x : y;   }   inline unsigned int R() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   const int N = 505000;   int n;   map<int, int> Map;   pair<int, int> s[N];   int len;   long long res;   priority_queue<long long, vector<long long>, greater<long long> > heap;   int main() {     read(n);     for (register int i = (1); i <= (n); i++) {       int x;       read(x);       Map[x]++;       res += x;     }     for (auto i : Map) s[++len] = pair<int, int>(i.first, i.second);     int sum = 0;     for (register int j = (len); j >= (1); j--) {       int c = min(s[j].second, sum - 2 * ((int)heap.size()));       vector<long long> cur(c, s[j].first);       c = s[j].second - c;       for (int i = 1; i <= c; i += 2)         if (!heap.empty()) {           long long t = heap.top();           heap.pop();           if (t < s[j].first) {             cur.push_back(s[j].first);             if (i < c) cur.push_back(s[j].first);           } else {             cur.push_back(t);             if (t < 2 * s[j].first && i < c) cur.push_back(2 * s[j].first - t);           }         }       for (auto i : cur) heap.push(i);       sum += s[j].second;     }     while (!heap.empty()) res -= heap.top(), heap.pop();     cout << res;     return 0;   }
#include <bits/stdc++.h>   unsigned long long int factorial(unsigned long long int n) {     unsigned long long int facto;     if (n == 0) return 1;     return facto = n * factorial(n - 1);   }   int main() {     long long int a, b, GCD;     unsigned long long int fa, fb;     scanf( %I64d %I64d , &a, &b);     if (a > b) {       fb = factorial(b);       printf( %I64d n , fb);     } else {       fa = factorial(a);       printf( %I64d n , fa);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[101010], v[101010], t[101010];   int n, s;   int l[1010101], r[1010101];   bool check(double m) {     memset(l, 0, sizeof(l));     memset(r, 0, sizeof(r));     for (int i = 1; i <= n; i++) {       if (t[i] == 1) {         if (1.0 * x[i] / v[i] < m)           l[0]++;         else {           l[x[i]]++;           l[max((long long)x[i],                 min(1000001LL,                     (long long)floor((m * (v[i] + s) - x[i]) * (s - v[i]) / s +                                      x[i])) +                     1)]--;         }       } else {         if (1.0 * (1000000 - x[i]) / v[i] < m)           r[0]++;         else {           r[min(               x[i] + 1LL,               max(0LL, (long long)ceil(x[i] - (m * (v[i] + s) + x[i] - 1000000) *                                                   (s - v[i]) / s)))]++;           r[x[i] + 1]--;         }       }     }     for (int i = 1; i <= 1000000; i++) {       l[i] += l[i - 1];       r[i] += r[i - 1];       if (l[i] && r[i]) return true;     }     return false;   }   int main() {     scanf( %d %d , &n, &s);     for (int i = 1; i <= n; i++) scanf( %d %d %d , &x[i], &v[i], &t[i]);     double l1 = 1e-8, r1 = 1e6;     while (r1 - l1 > 1e-7) {       double mid = (l1 + r1) / 2;       if (check(mid))         r1 = mid;       else         l1 = mid;     }     printf( %.12lf n , (l1 + r1) / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, ans;   int main() {     scanf( %d %d %d , &n, &a, &b);     if (b < 0) {       for (int i = b; i < 0; i++) {         a--;         if (a == 0) {           a = n;         }       }       ans = a;     } else {       for (int i = 0; i < b; i++) {         a++;         if (a > n) {           a = 1;         }       }       ans = a;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 40;   const int MAXM = 210;   int n, m, A[MAXN];   double p[MAXM][MAXN][MAXN];   void lucky() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);   }   int main() {     lucky();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) p[0][i][j] = (A[i] > A[j]);     double rat = 1.0 / (0.5 * n * (n + 1));     for (int R = 1; R <= m; R++)       for (int l = 1; l <= n; l++)         for (int r = l; r <= n; r++) {           for (int i = 1; i <= n; i++)             for (int j = 1; j <= n; j++) {               int x = (l <= i && i <= r) ? l + r - i : i;               int y = (l <= j && j <= r) ? l + r - j : j;               p[R][i][j] += rat * p[R - 1][x][y];             }         }     double ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ans += p[m][i][j];     printf( %.10lf n , ans);     return 0;   }
#include<bits/stdc++.h>       using namespace std;       typedef unsigned long long int ull;   typedef long long int ll;   typedef long double ld;       #define PB push_back   #define MP make_pair   #define F first   #define S second   #define Pair vector<pair<ll,ll>>   #define vec vector <ll>    #define all(a) a.begin(),a.end()   #define mo 1000000007   #define decimal(i,n) fixed << setprecision(i) << n   #define show(a) for(auto xyz:a)cout<<xyz<<   ;cout<<endl;   #define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;   #define MAX (ll)(pow(2,63)-1)   #define fill(a,b) memset(a, b, sizeof(a))   #define yes cout<< YES <<endl;   #define no cout<< NO <<endl;       //modular inverse   void eea(ll a,ll b,ll &x,ll &y)   {       if (a == 1)       {           x = 1; y = 0;           return;       }       ll x1, y1;       eea(b%a,a,x1,y1);       x=y1-(b/a)*x1;       y=x1;   }   ll mi(ll a,ll m)   {       ll x,y;       eea(a,m,x,y);       x= (x%m+m)%m;       return x;   }   //complete       void Sieve(int n)    {        int prime[n+1];       fill(prime,-1);       for (int p=2; p*p<=n; p++)        {            if (prime[p] == -1)            {                for (int i=p*p; i<=n; i += p)                    prime[i] = 0;            }        }        for (int p=2; p<=n; p++)        {                  }          }               int main()   {       ios::sync_with_stdio(0);       cin.tie(0); cout.tie(0);             // freopen( ladder.in ,  r , stdin);   // name of input file    // freopen( ladder.out ,  w , stdout); // name of output file           // ifstream fin( art.in );       // ofstream fout( art.out );              // fstream file, output;    // file.open(R () , ios::in);        // add the address of local input file    // output.open(R () , ios::out);  // add the address of local output file                ll t=1,t1=1;       cin>>t;       while(t--)       {           ll n;           cin>>n;           string s;           cin>>s;           ll t=0,m=0,x=0;           for(ll i=0;i<n;i++)           {               if(s[i]== M )               {                   m++;               }               else if(s[i]== T )               {                   t++;               }               if(m>t)               x=1;           }           t=0,m=0;           for(ll i=n-1;i>=0;i--)           {               if(s[i]== M )               {                   m++;               }               else if(s[i]== T )               {                   t++;               }               if(m>t)               x=1;           }           if(2*m!=t)           x=1;           if(x==1)           cout<< NO n ;           else           cout<< YES n ;           }     }       /*   Some helpful points   1.) Calm yourself   2.) check for semicolon or data type mismatch   3.) It can be solved   */