malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     vector<pair<int, int> > v, r;     cin >> n >> m;     for (int a = 0, b; a < n; a++) {       cin >> b;       v.push_back(make_pair(b, a));     }     sort(v.begin(), v.end());     for (int a = 0; a < n; a++) r.push_back(make_pair(v[a].second, a % 2));     sort(r.begin(), r.end());     for (int a = 0; a < n - 1; a++) cout << r[a].second <<    ;     cout << r[n - 1].second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t) {       t--;       long long int n, k;       cin >> n >> k;       long long int a[k];       map<long long int, long long int> m;       for (int i = 0; i < k; ++i) {         cin >> a[i];         m[a[i]]++;       }       long long int pow = 1, f = 0, ans = 0;       while (n) {         if (n % 2 == 1) {           if (m[pow] == 0) {             long long int x = 0;             for (long long int i = pow; i < 1000000000; i *= 2) {               if (m[i] != 0) {                 x = i;                 break;               }             }             m[x]--;             while (x != pow && x != 0) {               x /= 2;               m[x] += 1;               ans += 1;             }             if (x == 0) {               f = 1;               break;             }           } else {             m[pow]--;           }         }         m[2 * pow] += m[pow] / (2);         m[pow] = 0;         n /= 2;         pow *= 2;       }       if (f) {         cout << -1 <<   n ;       } else {         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int test = 0;   const int MAXN = 300009;   const long long MOD = 119 << 23 | 1;   class {    public:     vector<int> V[MAXN];     int fa[MAXN * 2], cnt[MAXN * 2];     int n, m;     int curset[MAXN * 2], ans;     int findfa(int x) {       if (fa[x] == x) return x;       return fa[x] = findfa(fa[x]);     }     void merge(int x, int y) {       x = findfa(x);       y = findfa(y);       if (x == y) return;       if (x > y) swap(x, y);       fa[y] = x;       cnt[x] += cnt[y];     }     void solve() {       cin >> n >> m;       string s;       cin >> s;       for (int i = 1; i <= m; ++i) {         int c;         cin >> c;         for (int j = 0; j < c; ++j) {           int v;           cin >> v;           V[v].push_back(i);         }         fa[i] = i;         fa[i + m] = i + m;         cnt[i + m] = 1;       }       ans = 0;       for (int i = 1; i <= n; ++i) {         bool on = s[i - 1] ==  1 ;         if (V[i].size() == 1) {           int p = V[i][0];           if (on) {             del(p);             del(p + m);             merge(p + m, 0);             add(p);           } else {             del(p);             del(p + m);             merge(p, 0);             add(p);           }         } else if (V[i].size() == 2) {           int p0 = V[i][0], p1 = V[i][1];           if (on) {             del(p0);             del(p1);             del(p1 + m);             del(p0 + m);             merge(p0, p1);             merge(p0 + m, p1 + m);             add(p0);           } else {             del(p0);             del(p1);             del(p1 + m);             del(p0 + m);             merge(p0, p1 + m);             merge(p0 + m, p1);             add(p0);           }         }         cout << ans <<   n ;       }     }     void add(int x) {       int y = x + m;       x = findfa(x);       y = findfa(y);       if (x == 0)         curset[y] = 1, ans += cnt[y];       else if (y == 0)         curset[x] = 1, ans += cnt[x];       else if (cnt[x] > cnt[y])         curset[y] = 1, ans += cnt[y];       else         curset[x] = 1, ans += cnt[x];     }     void del(int x) {       x = findfa(x);       if (curset[x]) {         ans -= cnt[x];         curset[x] = 0;       }     }   } NSPACE;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long a, b, x, y;     cin >> a >> b;     x = (a - b) / 2;     y = x + b;     if ((x > y) || (x + y != a) || (x ^ y) != b)       cout <<  -1  << endl;     else       cout << x <<     << y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<char, string>>> vec;   int main() {     unsigned long long int n, i, j, n1, cnt = 0;     cin >> n;     string s;     char r;     for (i = 1; i <= n; i++) {       cin >> s;       n1 = s.size();       cnt = 0;       for (j = 0; j < n1; j++) {         if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  ||             s[j] ==  u ) {           cnt++;           r = s[j];         }       }       vec.push_back(make_pair(cnt, make_pair(r, s)));     }     sort(vec.begin(), vec.end());     vector<pair<string, string>> v1;     vector<pair<string, string>> v2, v4, v5;     vector<pair<int, pair<char, string>>> v3;     for (i = 0; i < vec.size(); i++) {       if (i == vec.size() - 1) {         v3.push_back(vec[i]);         break;       }       if (vec[i].first == vec[i + 1].first) {         if (vec[i].second.first == vec[i + 1].second.first) {           v1.push_back(make_pair(vec[i].second.second, vec[i + 1].second.second));           i++;           continue;         } else {           v3.push_back(vec[i]);           continue;         }       } else {         v3.push_back(vec[i]);         continue;       }     }     sort(v3.begin(), v3.end());     for (i = 0; i < v3.size(); i++) {       if (i == v3.size() - 1) break;       if (v3[i].first == v3[i + 1].first) {         v2.push_back(make_pair(v3[i].second.second, v3[i + 1].second.second));         i++;       }     }     n1 = min(v1.size(), v2.size());     cnt = 0;     cnt = cnt + n1;     if (v1.size() > n1) {       cnt += (v1.size() - n1) / 2;     }     cout << cnt << endl;     for (i = 0; i < n1; i++) {       cout << v2[i].first <<     << v1[i].first << endl;       cout << v2[i].second <<     << v1[i].second << endl;     }     if (cnt > n1) {       for (i = n1; i < v1.size(); i++) {         if (v1.size() - 1 > i) {           cout << v1[i].first <<     << v1[i + 1].first << endl;           cout << v1[i].second <<     << v1[i + 1].second << endl;           i++;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 153, M = 1e5 + 7;   int n, m, K, ed;   char s[M];   bitset<N * N> wall, now, can;   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) {         if (s[j] ==  # )           wall[i * m + j] = 1;         else           can[i * m + j] = now[i * m + j] = 1;         if (s[j] ==  E ) ed = i * m + j;       }     }     scanf( %s , s + 1);     if (now.count() == 1 && now[ed]) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= K; i++) {       if (s[i] ==  U )         now = (now >> m & can) | (now & (wall << m));       else if (s[i] ==  D )         now = (now << m & can) | (now & (wall >> m));       else if (s[i] ==  L )         now = (now >> 1 & can) | (now & (wall << 1));       else         now = (now << 1 & can) | (now & (wall >> 1));       if (now.count() == 1 && now[ed]) {         printf( %d n , i);         return 0;       }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using vi = vector<int>;   const int Z = int(1e5 + 1);   const int inf = int(2e9 + 1);   const ll llinf = ll(2e18 + 1);   const ll mod = ll(1e9 + 7);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, x;     cin >> n >> x;     int sum = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       sum += a;     }     sum = abs(sum);     cout << sum / x + int(sum % x != 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double EPS = 1e-9;   const int MAXN = (int)1e5 + 10;   const long long MOD = (long long)1e9 + 7;   long long TEN_POW[MAXN];   long long MOD_INV[MAXN];   long long FACT[MAXN];   long long INV_FACT[MAXN];   long long ACC[MAXN];   long long comb(int n, int p) {     if (p > n) return 0;     return (((FACT[n] * INV_FACT[p]) % MOD) * INV_FACT[n - p]) % MOD;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     MOD_INV[1] = 1;     for (int i = 2; i < MAXN; i++)       MOD_INV[i] = (MOD - (MOD / i) * MOD_INV[MOD % i] % MOD) % MOD;     TEN_POW[0] = FACT[0] = INV_FACT[0] = 1;     for (int i = 1; i < MAXN; ++i) {       FACT[i] = (FACT[i - 1] * i) % MOD;       INV_FACT[i] = (INV_FACT[i - 1] * MOD_INV[i]) % MOD;       TEN_POW[i] = (TEN_POW[i - 1] * 10) % MOD;     }     int n, t;     string s;     cin >> n >> t;     cin >> s;     ACC[0] = comb(n - 2, t - 1);     for (int i = 1; t - 1 <= n - i - 2; ++i) {       ACC[i] = (ACC[i - 1] + (TEN_POW[i] * comb(n - i - 2, t - 1)) % MOD) % MOD;     }     long long ans = 0;     for (int k = 0; k < n; ++k) {       long long cur = 0;       cur = ((s[k] -  0 ) *              ((ACC[min(n - k - 2, n - t - 1)] +                (comb(k, t) * TEN_POW[n - k - 1]) % MOD)) %              MOD) %             MOD;       ans = (ans + cur) % MOD;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x7fffffffffffffff;   const double eps = 1e-10;   unsigned int seed = 19260817;   const unsigned int _RAND_MAX_ = 4294967295u;   __inline__ __attribute__((always_inline)) unsigned int Rand() {     return seed = seed * 998244353u + 1000000007u;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a > 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) {     return a < b ? b : a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) {     return a < b ? a : b;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (a > b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) bool _cmp(const _Tp &a,                                                       const _Tp &b) {     return abs(a - b) <= eps;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     register char ch(getchar());     bool f(false);     while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (ch >= 48 && ch <= 57)       x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     register char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     register char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 100005;   int main() {     long long n, p;     read(n, p);     if (p >= n) {       printf( -1 n );       return 0;     }     long long cnt = 0;     while (true) {       long long now = n - cnt * p;       if (now <= 0) break;       long long num = 0, maxx = 0;       for (long long i = 0; i <= 32; ++i) {         if (now & (1ll << i)) {           ++num;           maxx += i + 1;         }       }       if (num <= cnt && maxx >= cnt) {         printf( %lld n , cnt);         return 0;       }       ++cnt;     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2050;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   long long fpow(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long dp[maxn][maxn], a[maxn];   char s[maxn];   int main() {     int i, j, k, m, n;     scanf( %s , s + 1);     n = strlen(s + 1);     for (i = 1; i <= n; i++) a[i] = a[i - 1] + (s[i] ==  ? );     for (k = 2; k <= n; k++)       for (i = 1; i + k - 1 <= n; i++) {         j = i + k - 1;         dp[i][j] = (dp[i][j] + (s[i] !=  (  ? dp[i + 1][j] : 0)) % mod;         dp[i][j] = (dp[i][j] + (s[j] !=  )  ? dp[i][j - 1] : 0)) % mod;         dp[i][j] = (dp[i][j] + mod -                     (s[i] !=  (  && s[j] !=  )  ? dp[i + 1][j - 1] : 0)) %                    mod;         dp[i][j] =             (dp[i][j] + (s[i] !=  )  && s[j] !=  (                               ? (dp[i + 1][j - 1] + fpow(2, a[j - 1] - a[i])) % mod                              : 0)) %             mod;       }     cout << dp[1][n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long a[N], b[1050], c[N];   int cnt = 0;   void init() {     cnt = 0;     for (int i = 1; i < N - 50; i++) a[cnt++] = i * i;     cnt = 0;     for (int i = 1; i < 1010; i++) b[cnt++] = i * i * i;     int u = 0, t = 0;     cnt = 0;     while (a[u] && b[t]) {       if (a[u] < b[t]) {         c[cnt++] = a[u++];       } else if (a[u] == b[t]) {         c[cnt++] = a[u++];         t++;       } else         c[cnt++] = b[t++];     }   }   int main() {     init();     int T;     cin >> T;     while (T--) {       int n;       scanf( %d , &n);       int i = 0;       while (c[i] <= n) {         i++;       }       printf( %d n , i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print(vector<long long> &a) {     for (int i = 0; i < a.size(); i++) cout << a[i] <<    n [i == a.size() - 1];   }   void print(vector<int> &a) {     for (int i = 0; i < a.size(); i++) cout << a[i] <<    n [i == a.size() - 1];   }   void print(int a[], int l, int r) {     for (int i = l; i <= r; i++) cout << a[i] <<    n [i == r];   }   void print(long long a[], int l, int r) {     for (int i = l; i <= r; i++) cout << a[i] <<    n [i == r];   }   long long qpow(long long x, long long y) {     long long temp = x;     long long ans = 1;     while (y) {       if (y & 1) ans = (ans * temp);       temp = (temp * temp);       y >>= 1;     }     return ans;   }   long long qpow(long long x, long long y, long long MOD) {     long long temp = x;     long long ans = 1;     while (y) {       if (y & 1) ans = (ans * temp) % MOD;       temp = (temp * temp) % MOD;       y >>= 1;     }     return ans;   }   int dp[200050];   void INIT() {     dp[3] = 1;     dp[7] = 1;     for (int i = 1; i <= 100; i++)       if (dp[i]) {         dp[i + 3] = 1;         dp[i + 7] = 1;       }   }   void solve() {     int n;     cin >> n;     if (dp[n]) {       cout <<  YES             <<   n ;     } else {       cout <<  NO             <<   n ;     }   }   int main() {     INIT();     int TT;     cin >> TT;     while (TT--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   void setmin(T& a, T val) {     if (a > val) a = val;   }   template <class T>   void setmax(T& a, T val) {     if (a < val) a = val;   }   void addmod(long long& a, long long val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   void submod(long long& a, long long val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   const int N = 100005;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long wtotal = n * m / 2, btotal = n * m / 2;       if ((n * m) % 2) wtotal++;       long long x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long x3, y3, x4, y4;       cin >> x3 >> y3 >> x4 >> y4;       long long k1 = abs(x2 - x1 + 1) * abs(y2 - y1 + 1),                 k2 = abs(x4 - x3 + 1) * abs(y4 - y3 + 1);       long long black = k1 / 2;       if ((x1 + y1) % 2 && k1 % 2) black++;       wtotal += black;       btotal -= black;       long long white = k2 / 2;       if ((x3 + y3) % 2 == 0 && k2 % 2) white++;       btotal += white;       wtotal -= white;       long long x5 = max(x1, x3);       long long y5 = max(y1, y3);       long long x6 = min(x2, x4);       long long y6 = min(y2, y4);       if (y5 > y6 || x5 > x6)         cout << wtotal <<     << btotal <<   n ;       else {         long long bext = abs(x6 - x5 + 1) * abs(y6 - y5 + 1);         long long b = bext / 2;         if ((x5 + y5) % 2 && bext % 2) b++;         cout << wtotal - b <<     << btotal + b <<   n ;       }     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int main()   {    int t;    cin>>t;    while(t--)    {     long long n, m;     cin>>n>>m;     long k[n], c[m];     for(long i=0;i<n;i++)      cin>>k[i];     sort(k,k+n,[](long& a,long& b){ return a>b; });     for(long i=0;i<m;i++)      cin>>c[i];     long long p = 0;     long long r = 0;     for(long long i=0;i<n;i++)     {      assert(k[i]-1>=0 && k[i]-1 < m);      if(p >= m)       r += c[k[i]-1];      else if(c[p] < c[k[i]-1])       r += c[p++];      else       r += c[k[i]-1];     }     cout<<r<<  n ;    }   }
#include <bits/stdc++.h>   using namespace std;   long long int a[100005], sg[100005 * 4], lz[100005 * 4], res, x, y, z, n;   void lazy(long long int low, long long int high, long long int pos) {     sg[pos] += lz[pos];     if (low != high) lz[pos * 2 + 1] += lz[pos], lz[pos * 2 + 2] += lz[pos];     lz[pos] = 0;   }   void update(long long int low, long long int high, long long int pos,               long long int qlow, long long int qhigh, long long int va) {     lazy(low, high, pos);     if (qlow > high || qhigh < low) return;     if (qlow <= low && high <= qhigh) {       sg[pos] += va;       if (low != high) lz[pos * 2 + 1] += va, lz[pos * 2 + 2] += va;       return;     }     long long int mid = (high + low) / 2;     update(low, mid, pos * 2 + 1, qlow, qhigh, va);     update(mid + 1, high, pos * 2 + 2, qlow, qhigh, va);     sg[pos] = max(sg[pos * 2 + 1], sg[pos * 2 + 2]);   }   long long int ans(long long int low, long long int high, long long int pos) {     lazy(low, high, pos);     if (sg[pos] <= 0) return -1;     if (low == high) return a[low];     long long int mid = (high + low) / 2;     lazy(low, mid, pos * 2 + 1), lazy(mid + 1, high, pos * 2 + 2);     if (sg[pos * 2 + 2] > 0)       return ans(mid + 1, high, pos * 2 + 2);     else       return ans(low, mid, pos * 2 + 1);   }   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &x, &y);       x--;       if (y == 0)         y = -1;       else         scanf( %lld , &z), a[x] = z;       update(0, n, 0, 0, x, y);       res = ans(0, n, 0);       printf( %lld n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 12345678987654321ll;   long long dp[3000];   int n;   int main() {     cin >> n;     int t, c;     for (int i = 1; i <= n; i++) dp[i] = inf;     for (int i = 1; i <= n; i++) {       cin >> t >> c;       ++t;       for (int i = n + t; i > n; i--) {         dp[n] = min(dp[n], dp[i - t] + c);       }       for (int i = n; i - t >= 0; i--) {         dp[i] = min(dp[i], dp[i - t] + c);       }     }     cout << dp[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int maxn = 1e5 + 300;   const int INF = 0x3f3f3f3f;   int main() {     int k;     scanf( %d , &k);     if (k == 1) {       puts( YES n2 1 n1 2 );     } else if (k % 2 == 0) {       puts( NO );     } else {       puts( YES );       printf( %d %d n , 2 * k + 4, k * (k + 2));       for (int i = 2; i <= k; i++) {         printf( 1 %d n , i);       }       int nn = k + 2;       for (int i = 2; i <= k; i++) {         printf( %d %d n , i, k + 1);         printf( %d %d n , i, k + 2);         for (int j = i + 1; j <= k; j++) {           if (i % 2 == 0 && j == i + 1) continue;           printf( %d %d n , i, j);         }       }       printf( %d %d n , k + 1, k + 2);       for (int i = 2; i <= k; i++) {         printf( %d %d n , 1 + nn, i + nn);       }       for (int i = 2; i <= k; i++) {         printf( %d %d n , i + nn, nn + k + 1);         printf( %d %d n , i + nn, nn + k + 2);         for (int j = i + 1; j <= k; j++) {           if (i % 2 == 0 && j == i + 1) continue;           printf( %d %d n , i + nn, j + nn);         }       }       printf( %d %d n , k + 1 + nn, k + 2 + nn);       printf( %d %d n , 1, nn + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, res = 0, i, t;     vector<string> v;     cin >> n;     for (i = 0; i < n; i++) {       string s;       cin >> s;       v.push_back(s);     }     for (int j = 0; j < 7; j++) {       t = 0;       for (i = 0; i < n; i++) {         if (v[i][j] ==  1 ) t++;       }       res = max(t, res);     }     cout << res << endl;   }