malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int b[1000005], a[40];   int main() {     int n, m, d;     cin >> n >> m;     for (int(i) = (0); (i) < (n); (i)++) {       scanf( %d , &d);       int j = 0;       while (d) a[j++] += d & 1, d /= 2;     }     for (int(i) = (0); (i) < (m); (i)++) scanf( %d , &b[i]);     sort(b, b + m);     for (int(i) = (0); (i) < (m); (i)++) {       int j = b[i];       while (j < 32 && !a[j]) a[j++] = 1;       if (j == 32) {         cout << i << endl;         return 0;       }       a[j]--;     }     cout << m << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 10 * 100 + 19;   const long long inf = 2e9 + 19;   long long n;   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     cout << 1ll * ((n + 1) / 2) * (n / 2) << endl;     for (long long i = 1; i <= n; i++)       for (long long j = i + 1; j <= n; j++)         if ((i & 1) != (j & 1)) cout << i <<     << j << endl;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXSIZE = 2001;   const long long BASE = 1000000007;   int n, m;   long long dp[MAXSIZE + 1][MAXSIZE + 1];   long long sum[MAXSIZE + 1][MAXSIZE + 1];   int main() {     scanf( %d%d , &n, &m);     for (int l = 1; l < m; l++) dp[1][l] = 1;     for (int i = 2; i <= n; i++) {       long long sum = 0;       for (int j = 1; j < m; j++) {         sum += (dp[i - 1][j]) % BASE;         dp[i][j] = (dp[i][j - 1] + sum) % BASE;       }     }     for (int j = 1; j < m; j++)       for (int t = n - 1; t >= 1; t--)         sum[n - t][j] = (sum[n - t - 1][j] + dp[n - t][j]) % BASE;     long long ANS = 0;     for (int t = 1; t <= n; t++) {       for (int j = 1; j < m; j++) {         long long count = sum[n - t][j] + dp[n - t + 1][j];         count %= BASE;         count = (count * (m - j)) % BASE;         ANS = (ANS + dp[t][j] * count) % BASE;       }     }     printf( %I64d , ANS);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int inf = 1e9 + 5;   void umin(int& a, int b) { a = min(a, b); }   void umax(int& a, int b) { a = max(a, b); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<array<int, 2>> a(n);     for (auto& ai : a) {       string s;       cin >> s;       for (char c : s) ai[c ==  N ]++;     }     int min_x = inf, min_y = inf, min_xy = inf;     int max_x = -inf, max_y = -inf, max_xy = -inf;     for (const auto& ai : a) {       umin(min_x, ai[0]);       umin(min_y, ai[1]);       umin(min_xy, ai[0] - ai[1]);       umax(max_x, ai[0]);       umax(max_y, ai[1]);       umax(max_xy, ai[0] - ai[1]);     }     auto checkAns = [&](int m) -> pair<int, int> {       int min_x2 = min_x + m;       int min_y2 = min_y + m;       int min_xy2 = min_xy + m;       int max_x2 = max(0, max_x - m);       int max_y2 = max(0, max_y - m);       int max_xy2 = max_xy - m;       if (min_x2 >= max_x2 && min_y2 >= max_y2 && min_xy2 >= max_xy2) {         for (int x : {min_x2, max_x2}) {           for (int xy : {min_xy2, max_xy2}) {             int y = x - xy;             if (max_y2 <= y && y <= min_y2 && y >= 0 && x + y > 0) return {x, y};           }         }         for (int y : {min_y2, max_y2}) {           for (int xy : {min_xy2, max_xy2}) {             int x = y + xy;             if (max_x2 <= x && x <= min_x2 && x >= 0 && x + y > 0) return {x, y};           }         }       }       return {-1, -1};     };     int l = 0, r = 1e6, dist = -1;     pair<int, int> ans = {-1, -1};     while (l < r) {       int m = (l + r) / 2;       pair<int, int> ret = checkAns(m);       if (ret.first != -1) {         r = m;         dist = m;         ans = ret;       } else {         l = m + 1;       }     }     cout << dist <<   n ;     cout << string(ans.first,  B ) << string(ans.second,  N ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using std::vector;   bool judge(int x) {     for (int i = 0; i < 31; i++) {       if (x == (1 << i) - 1) return true;     }     return false;   }   int get_hzero(int x) {     int res = 0, pre = 0;     for (int i = 0; i < 31; i++) {       if (x & (1 << i))         res = pre;       else         pre = i;     }     return res;   }   int main() {     int x;     while (~scanf( %d , &x)) {       int bit[100];       int ans = 0;       vector<int> vec;       while (!judge(x)) {         int num = get_hzero(x) + 1;         vec.push_back(num);         x ^= (1 << num) - 1;         ans++;         if (!judge(x)) x += 1, ans++;       }       printf( %d n , ans);       for (int i = 0; i < vec.size(); i++)         printf( %d%c , vec[i],    n [i == vec.size() - 1]);     }     return 0;   }
#include <bits/stdc++.h>   inline int in() {     int x = 0;     char c = getchar();     bool f = false;     while (c <  0  || c >  9 ) f |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return f ? -x : x;   }   const int N = 105;   int t[N], f[N * N][N], tot;   int main() {     int n = in(), res = 1;     for (int i = 1; i <= n; ++i) {       int a = in();       if (!t[a]) ++tot;       ++t[a];     }     if (tot <= 2) {       printf( %d n , n);       return 0;     }     f[0][0] = 1;     for (int i = 1; i <= 100; ++i)       if (t[i]) {         for (int j = 10000; j; --j)           for (int k = 1; k <= n; ++k)             for (int l = 1; l <= t[i] && l <= k && l * i <= j; ++l)               f[j][k] += f[j - l * i][k - l];       }     for (int i = 1; i <= 100; ++i)       if (t[i])         for (int j = 1; j <= t[i]; ++j)           if (f[i * j][j] == 1) res = std::max(res, j);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   const int mod = 1e9 + 7;   int prime[N], pp, pri[N], ans = 1, p[N], n, cnt[N], mx[N];   bool iscomp[N];   void primetable() {     for (int i = 2; i < N; i++) {       if (!iscomp[i]) prime[pp++] = i, pri[i] = i;       for (int j = 0; j < pp && 1ll * i * prime[j] < N; j++) {         iscomp[i * prime[j]] = 1;         pri[i * prime[j]] = prime[j];         if (i % prime[j] == 0) break;       }     }   }   int main() {     primetable();     scanf( %d n , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     sort(p + 1, p + n + 1);     for (int i = n; i; i--) {       if (!cnt[p[i]])         cnt[p[i]]++, mx[p[i]] = 1, ans = (1ll * ans * p[i]) % mod;       else {         int v = --p[i];         while (v != 1) {           int u = pri[v], ci = 0;           while (v % u == 0) v /= u, ci++;           if (cnt[u] < ci) {             for (int j = cnt[u] + 1; j <= ci; j++) ans = (1ll * ans * u) % mod;             cnt[u] = ci;             mx[u] = 1;           } else             mx[u] += (cnt[u] == ci);         }       }     }     for (int i = 1; i <= n; i++) {       int v = p[i], flag = 0;       while (v != 1) {         int u = pri[v], ci = 0;         while (v % u == 0) v /= u, ci++;         if (cnt[u] == ci && mx[u] == 1) flag = 1;       }       if (!flag) {         ans++;         break;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++) {         int k = i ^ j;         if (k >= j && k <= n && i + j > k && i + k > j && j + k > i) ans++;       }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int va, num;     bool operator<(const node &o) const { return va < o.va; }   } a[100005];   int n, m, nub, lastnode, nextnode, now;   int mark[400005], mm;   int ans[400005], co;   vector<int> save[400005];   void dfs(int h) {     mark[h] = 1;     for (int i = 0; i < save[h].size(); i++) {       if (mark[save[h][i]] == 1) {         mm = 1;         return;       }       if (mark[save[h][i]] == 0) {         dfs(save[h][i]);       }     }     ans[co] = h;     co++;     mark[h] = 2;   }   int main() {     scanf( %d %d , &n, &m);     nub = m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &a[j].va);         a[j].num = j;       }       sort(&a[0], &a[m]);       lastnode = -1;       for (int j = 0; j < m; j++) {         if (a[j].va == -1) continue;         nub++;         nextnode = nub;         now = a[j].va;         while (j < m && a[j].va == now) {           if (lastnode != -1) {             save[lastnode].push_back(a[j].num);           }           save[a[j].num].push_back(nextnode);           j++;         }         j--;         lastnode = nextnode;       }     }     for (int i = 0; i <= nub; i++) {       if (!mark[i]) {         dfs(i);       }     }     if (mm) {       printf( -1 n );     } else {       for (int i = co - 1; i >= 0; i--) {         if (ans[i] < m) {           printf( %d  , ans[i] + 1);         }       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     if (n == 1 && t == 10) {       cout << -1 << endl;       return 0;     }     if (t == 10) {       for (int i = 1; i < n; i++) cout << 1;       cout << 0 << endl;       return 0;     }     if (n == 1) {       cout << t << endl;       return 0;     }     cout << t;     for (int i = 1; i < n - 1; i++) cout << 0;     cout << t << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       string s;       int ans = 0;       cin >> s;       int curRow = 0, curCol = 0;       map<pair<pair<int, int>, pair<int, int>>, bool> mp;       for (int i = 0; i < s.size(); ++i) {         int desRow, desCol;         switch (s[i]) {           case  N :             desRow = curRow, desCol = curCol + 1;             if (mp[{{curRow, curCol}, {desRow, desCol}}])               ++ans;             else {               mp[{{curRow, curCol}, {desRow, desCol}}] = true;               mp[{{desRow, desCol}, {curRow, curCol}}] = true;               ans += 5;             }             break;           case  S :             desRow = curRow, desCol = curCol - 1;             if (mp[{{curRow, curCol}, {desRow, desCol}}])               ++ans;             else {               mp[{{curRow, curCol}, {desRow, desCol}}] = true;               mp[{{desRow, desCol}, {curRow, curCol}}] = true;               ans += 5;             }             break;           case  E :             desRow = curRow + 1, desCol = curCol;             if (mp[{{curRow, curCol}, {desRow, desCol}}])               ++ans;             else {               mp[{{curRow, curCol}, {desRow, desCol}}] = true;               mp[{{desRow, desCol}, {curRow, curCol}}] = true;               ans += 5;             }             break;           case  W :             desRow = curRow - 1, desCol = curCol;             if (mp[{{curRow, curCol}, {desRow, desCol}}])               ++ans;             else {               mp[{{curRow, curCol}, {desRow, desCol}}] = true;               mp[{{desRow, desCol}, {curRow, curCol}}] = true;               ans += 5;             }             break;         }         curRow = desRow, curCol = desCol;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int temp = 0, n;     cin >> n;     int arr[n];     bool b[n];     for (int j = 0; j < n; j++) {       cin >> arr[j];       b[j] = false;     }     for (int i = n - 1; i >= 0; i--) {       if (temp > 0) b[i] = true;       temp--;       temp = max(temp, arr[i]);     }     int ct = 0;     for (int k = 0; k < n; k++) {       if (!b[k]) ct++;     }     cout << ct << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[101], b[101], g[101][101];   int main() {     int i, j, n, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) scanf( %d , &b[i]);     memset(g, 0, sizeof(g));     for (i = 1; i <= n; i++) {       if (i + b[i] <= n) g[i][i + b[i]] = g[i + b[i]][i] = 1;       if (i - b[i] >= 1) g[i][i - b[i]] = g[i - b[i]][i] = 1;     }     for (k = 1; k <= n; k++) {       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           if (g[i][k] && g[k][j]) g[i][j] = 1;         }       }     }     bool flag = 1;     for (i = 1; i <= n; i++) {       if (i == a[i]) continue;       if (g[i][a[i]] == 0) flag = 0;       if (flag == 0) break;     }     if (flag)       printf( YES n );     else       printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-7;   const long long int m = 1000000007;   void solve() {     int n, m, r, c;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < s.length(); j++) {         if (s[j] ==  B ) {           r = i + 1 + count(s.begin(), s.end(),  B ) / 2;           c = j + 1 + count(s.begin(), s.end(),  B ) / 2;           cout << r <<     << c <<   n ;           return;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[2][2];   int main() {     int d, i, n;     cin >> n;     int k = n;     int cd = 0, ud = 0, c_i = 0, u_i = 0;     while (k--) {       cin >> i >> d;       if (i == 0)         c_i++;       else         u_i++;       if (d == 0)         cd++;       else         ud++;     }     cout << min(c_i, u_i) + min(cd, ud) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   vector<int> primes;   bool flag[100005];   bool flag2[100005];   void sieve(int n) {     for (int i = 2; i <= n; i++) {       if (!flag2[i]) {         primes.push_back(i);         for (int j = 2 * i; j <= n; j += i) {           flag2[j] = true;         }       }     }     int sz = 0;     for (int i = 1; i < primes.size(); i++) {       v.push_back(primes[i]);       sz++;       for (int j = primes[i] * 3; j <= n; j += primes[i]) {         if (!flag[j]) {           v.push_back(j);           sz++;           flag[j] = true;         }       }       if (sz % 2 == 1) {         if (primes[i] * 2 <= n && !flag[primes[i] * 2]) {           v.push_back(primes[i] * 2);           sz++;           flag[primes[i] * 2] = true;         } else {           flag[v[sz - 1]] = false;           v.erase(v.begin() + sz - 1);           sz--;         }       }     }     for (int i = 0; i < 1; i++) {       for (int j = primes[i]; j <= n; j += primes[i]) {         if (!flag[j]) {           v.push_back(j);           sz++;           flag[j] = true;         }       }       if (sz % 2 == 1) {         flag[v[sz - 1]] = false;         v.erase(v.begin() + sz - 1);         sz--;       }     }   }   int main() {     int n;     scanf( %d , &n);     if (n < 4) {       printf( 0 n );       return 0;     }     sieve(n);     printf( %d n , v.size() / 2);     for (int i = 0; i < v.size(); i++) {       printf( %d%s , v[i], (i & 1) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const INF = numeric_limits<int>::max();   int const N = 1e5 + 5;   string a[N];   int main() {     ios::sync_with_stdio(false);     vector<pair<int, int>> v;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       int m;       cin >> m;       for (int j = 0; j < m; j++) {         int x;         cin >> x;         v.push_back({x - 1, i});       }     }     sort(v.begin(), v.end());     string ans;     for (auto p : v) {       if (p.first > ans.size()) {         while (ans.size() < p.first) {           ans.push_back( a );         }       }       if (a[p.second].size() + p.first > ans.size()) {         int from =             a[p.second].size() - (p.first - ans.size() + a[p.second].size());         ans.append(a[p.second].begin() + from, a[p.second].end());       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       string s;       cin >> s;       long long int a, b;       cin >> a >> b;       long long int n = s.length();       vector<long long int> v1(n, -1), v2(n, -1);       long long int x = 0;       for (long long int i = 0; i < n; i++) {         if (i == 0) {           v1[i] = (s[i] -  0 ) % a;           continue;         }         v1[i] = (v1[i - 1] * 10 + (s[i] -  0 )) % a;       }       long long int base = 1;       for (int i = n - 1; i >= 0; i--) {         if (i == n - 1) {           v2[i] = (s[i] -  0 ) % b;         } else           v2[i] = ((s[i] -  0 ) * base + v2[i + 1]) % b;         base = (base * 10) % b;       }       long long int index = -1;       for (long long int i = 0; i < n - 1; i++) {         if (v1[i] == 0 && v2[i + 1] == 0 && s[i + 1] !=  0 ) {           index = i;           break;         }       }       if (index == -1)         cout <<  NO  << endl;       else {         cout <<  YES  << endl;         cout << s.substr(0, index + 1) << endl              << s.substr(index + 1, n - index - 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_SIZE = 200010;   pair<int, int> arr[MAX_SIZE], backup[MAX_SIZE];   long long prefix[MAX_SIZE];   int N;   void sortX(int l, int r) {     if (l >= r) return;     int mi = (l + r) / 2;     sortX(l, mi);     sortX(mi + 1, r);     int i = l, j = mi + 1, k = l;     while (i <= mi && j <= r) {       if (arr[i] < arr[j]) {         backup[k++] = arr[i++];       } else {         backup[k++] = arr[j++];       }     }     while (i <= mi) {       backup[k++] = arr[i++];     }     while (j <= r) {       backup[k++] = arr[j++];     }     for (int i = l; i <= r; i++) {       arr[i] = backup[i];     }   }   int lowerBound(int l, int r, int val) {     while (l <= r) {       int mi = (l + r) / 2;       if (arr[mi].second <= val) {         l = mi + 1;       } else {         r = mi - 1;       }     }     int mi = (l + r) / 2;     if (mi >= l && arr[mi].second > val) return mi - 1;     return mi;   }   long long mergeSortV(int l, int r) {     if (l >= r) return 0;     int mi = (l + r) / 2;     long long left = mergeSortV(l, mi);     long long right = mergeSortV(mi + 1, r);     long long mix = 0LL;     prefix[l] = 0LL;     for (int i = l; i <= mi; i++) {       prefix[i + 1] = prefix[i] + (long long)arr[i].first;     }     for (int i = mi + 1; i <= r; i++) {       int pos = lowerBound(l, mi, arr[i].second);       long long cnt = pos - l + 1;       mix += ((long long)arr[i].first * cnt - (prefix[pos + 1] - prefix[l]));     }     int i = l, j = mi + 1, k = l;     while (i <= mi && j <= r) {       if (arr[i].second < arr[j].second) {         backup[k++] = arr[i++];       } else {         backup[k++] = arr[j++];       }     }     while (i <= mi) {       backup[k++] = arr[i++];     }     while (j <= r) {       backup[k++] = arr[j++];     }     for (i = l; i <= r; i++) {       arr[i] = backup[i];     }     return left + right + mix;   }   long long solveBruteforce() {     long long sum = 0LL;     for (int i = 0; i < N; i++) {       for (int j = i + 1; j < N; j++) {         if (arr[i].second > arr[j].second) {           sum += (long long)max(arr[i].first - arr[j].first, 0);         } else if (arr[i].second < arr[j].second) {           sum += (long long)max(arr[j].first - arr[i].first, 0);         } else {           sum += (long long)max(arr[j].first - arr[i].first,                                 arr[i].first - arr[j].first);         }       }     }     return sum;   }   int main() {     cin >> N;     for (int i = 0; i < N; i++) {       int x;       cin >> x;       arr[i].first = x;     }     for (int i = 0; i < N; i++) {       int v;       cin >> v;       arr[i].second = v;     }     sortX(0, N - 1);     cout << mergeSortV(0, N - 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, x, y;     bool B[1005];     cin >> n >> m;     for (i = 0; i < n; i++) B[i] = true;     for (i = 0; i < m; i++) {       cin >> x >> y;       B[x - 1] = false;       B[y - 1] = false;     }     for (i = 0; i < n; i++)       if (B[i]) break;     cout << n - 1 << endl;     for (j = 0; j < n; j++) {       if (j == i) continue;       cout << j + 1 <<     << i + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   mt19937 rnd(       std::chrono::high_resolution_clock::now().time_since_epoch().count());   void ProdamGaraje() {     vector<long long> a[2000];     long long m, n;     cin >> n >> m;     for (long long i = 0; i < n; ++i) {       a[i].push_back(0);       for (long long j = 0; j < m; ++j) {         long long x;         cin >> x;         a[i].push_back(x + (a[i][(int)a[i].size() - 1]));       }     }     for (long long i = m - 1; i >= 1; --i) {       a[0][i] = max(a[0][i], a[0][i + 1]);     }     for (long long i = 1; i < n; ++i) {       if (i % 2 == 1) {         for (long long j = 1; j < m; ++j) {           a[i][j] += a[i - 1][j + 1];         }         for (long long j = 2; j < m + 1; ++j) a[i][j] = max(a[i][j], a[i][j - 1]);       } else {         for (long long j = m; j >= 2; --j) {           a[i][j] += a[i - 1][j - 1];         }         for (long long j = m - 1; j >= 1; --j)           a[i][j] = max(a[i][j], a[i][j + 1]);       }     }     if (n % 2 == 0) {       cout << a[n - 1][m - 1];     } else {       cout << a[n - 1][2];     }   }   void solve() {     int a, b, c;     cin >> a >> b >> c;     for (int i = 0; i < b; i++) {       int x;       cin >> x;       int y;       cin >> y;     }     for (int i = 0; i < c; i++) {       string s;       cin >> s;       int x;       cin >> x;       for (int j = 0; j < x; j++) {         int t;         cin >> t;       }     }     for (int i = 0; i < c; i++) {       string s;       cin >> s;       int x;       cin >> x;       for (int j = 0; j < x; j++) {         int t;         cin >> t;       }     }     int ans = rnd() % 2;     if (ans)       cout <<  YES ;     else       cout <<  NO ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) ProdamGaraje();   }