malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int count_on(int mask) {     int ans = 0;     while (mask) {       if (mask & 1) {         ans++;       }       mask >>= 1;     }     return ans;   }   int dp[1 << 20];   string bin(int mask) {     string str =   ;     while (mask) {       if (mask & 1) {         str += ( 1 );       } else {         str += ( 0 );       }       mask >>= 1;     }     reverse(str.begin(), str.end());     if (str ==   ) {       str =  0 ;     }     return str;   }   int main() {     string str;     cin >> str;     vector<int> masks;     int N = str.size();     for (int i = 0; i < N; i++) {       int mask = 0;       for (int j = 0; i + j < N && j < 20; j++) {         int dig = str[i + j] -  a ;         if (mask & (1 << dig)) {           break;         }         mask |= (1 << dig);         masks.push_back(mask);         dp[mask] = count_on(mask);       }     }     for (int i = 0; i < (1 << 20); i++) {       for (int j = 0; j < 20; j++) {         if (i & (1 << j)) {           dp[i] = max(dp[i], dp[i ^ (1 << j)]);         }       }     }     int best = 0;     for (auto mask : masks) {       int ans = dp[mask] + dp[((1 << 20) - 1) ^ mask];       best = max(best, ans);     }     cout << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> tree[100005];   int cat[100005];   bool vis[100005];   int n, m, ans = 0;   void dfs(int root, int num) {     vis[root] = true;     if (cat[root])       num++;     else       num = 0;     if (num > m) return;     if (tree[root].size() == 1 && vis[tree[root][0]]) {       ans++;       return;     }     for (int i = 0; i < tree[root].size(); i++) {       int c = tree[root][i];       if (!vis[c]) dfs(c, num);     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &cat[i]);     for (int i = 0; i < n - 1; i++) {       int f, s;       scanf( %d %d , &f, &s);       tree[f].push_back(s);       tree[s].push_back(f);     }     dfs(1, 0);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     string t;     cin >> s >> t;     long j = 0;     long ans = 0;     for (long i = 0; i < t.size(); i++) {       if (t[i] == s[j]) ++j;       if (j == s.size()) {         long rj = s.size() - 1;         for (long k = t.size() - 1; k >= 0; k--) {           if (t[k] == s[rj]) --rj;           if (rj == -1) {             cout << std::max(k - i, long(0));             return 0;           }         }         break;       }     }     cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char ch[n];     ch[n] =   0 ;     int a[n][2];     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];     }     int suma = 0;     int sumg = 0;     for (int i = 0; i < n; i++) {       if (((a[i][0] + suma) - sumg) <= 500) {         suma += a[i][0];         ch[i] =  A ;       } else if (((a[i][1] + sumg) - suma) <= 500) {         sumg += a[i][1];         ch[i] =  G ;       }     }     if ((abs(suma - sumg)) > 500) {       cout <<  -1 ;     } else {       cout << ch;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   map<int, int> mx, my;   vector<int> v;   long long cal() {     long long ans = 0;     int sz = v.size();     sort(v.begin(), v.end());     int l = 0, r;     while (l < sz) {       r = l;       while (r < sz - 1 && v[r + 1] == v[l]) r++;       ans += 1ll * (r - l + 1) * (r - l) / 2;       l = r + 1;     }     return ans;   }   struct point {     int x;     int y;   } px[N], py[N];   bool cmpx(point &u, point &v) { return u.x < v.x; }   bool cmpy(point &u, point &v) { return u.y < v.y; }   int read() {     char c = getchar();     int ans = 0;     while (c ==     || c ==   n ) c = getchar();     while (c >=  0  && c <=  9 ) ans = ans * 10 + c -  0 , c = getchar();     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       int cx = 0, cy = 0;       long long ans = 0;       mx.clear();       my.clear();       int n, m, k;       cin >> n >> m >> k;       for (int i = 1, x; i <= n; i++) {         x = read();         mx[x] = 1;       }       for (int i = 1, y; i <= m; i++) {         y = read();         my[y] = 1;       }       for (int i = 1, x, y; i <= k; i++) {         x = read();         y = read();         if (mx.count(x) && my.count(y)) continue;         if (mx.count(x))           py[++cy].x = x, py[cy].y = y;         else           px[++cx].x = x, px[cx].y = y;       }       sort(px + 1, px + cx + 1, cmpx);       sort(py + 1, py + cy + 1, cmpy);       map<int, int>::iterator P = mx.begin();       int L = 1, R;       while (P != mx.end()) {         v.clear();         v.push_back(px[L].y);         int l = P->first;         P++;         int r = P->first;         if (P == mx.end()) break;         if (r < px[L].x) continue;         R = L;         while (R < cx && px[R + 1].x < r) R++, v.push_back(px[R].y);         ans += 1LL * (R - L + 1) * (R - L) / 2 - cal();         L = R + 1;       }       L = 1;       P = my.begin();       while (P != my.end()) {         v.clear();         v.push_back(py[L].x);         int l = P->first;         P++;         int r = P->first;         if (P == my.end()) break;         if (r < py[L].y) continue;         R = L;         while (R < cy && py[R + 1].y < r) R++, v.push_back(py[R].x);         ans += 1LL * (R - L + 1) * (R - L) / 2 - cal();         L = R + 1;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, excluidos = 0;   vector<priority_queue<int, vector<int>, greater<int>>> Vpq;   bool umVazio() {     for (auto u : Vpq) {       if (u.size() == 0) return true;     }     return false;   }   int procura(int indAnterior, int i) {     int num = -1;     while (Vpq[i].size() != 0) {       if (Vpq[i].top() > indAnterior) {         num = Vpq[i].top();         Vpq[i].pop();         return num;       } else {         excluidos++;         Vpq[i].pop();       }     }     return num;   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(0);     cin >> n;     int a;     Vpq.resize(6);     for (int i = 0; i < n; i++) {       cin >> a;       if (a == 4) {         Vpq[0].push(i);       } else if (a == 8) {         Vpq[1].push(i);       } else if (a == 15) {         Vpq[2].push(i);       } else if (a == 16) {         Vpq[3].push(i);       } else if (a == 23) {         Vpq[4].push(i);       } else if (a == 42) {         Vpq[5].push(i);       }     }     bool flag = 1;     while (flag) {       int indAnterior = -2;       for (int i = 0; i < 6; i++) {         indAnterior = procura(indAnterior, i);         if (indAnterior == -1) {           excluidos += i;           flag = 0;           break;         }       }     }     for (int i = 0; i < 6; i++) {       excluidos += Vpq[i].size();     }     cout << excluidos << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T& x) {     x = 0;     char c;     int sign = 1;     do {       c = getchar();       if (c ==  - ) sign = -1;     } while (c <  0  || c >  9 );     do {       x = x * 10 + c -  0 ;       c = getchar();     } while (c <=  9  && c >=  0 );     x *= sign;   }   const int N = 101, inf = 1e6;   int t, n, cnt, a[N], k[N];   bool vis[inf << 1];   bool check(int x) {     for (register int i = 1; i <= n; ++i)       if (vis[a[i] + x]) return 0;     for (register int i = 1; i <= n; ++i) vis[a[i] + x] = 1;     return 1;   }   inline int solve() {     cnt = 0;     memset(vis, 0, sizeof vis);     read(n);     for (register int i = 1; i <= n; ++i) read(a[i]);     sort(a + 1, a + n + 1);     for (register int i = 2; i <= n; ++i)       if (a[i] == a[i - 1]) return puts( NO ), 0;     for (register int i = 1; i <= inf; ++i)       if (cnt == n)         break;       else if (check(i))         k[++cnt] = i;     if (cnt == n) {       puts( YES );       for (register int i = 1; i <= n; ++i) printf( %d  , k[i]);       printf(  n );     } else       puts( NO );     return 0;   }   int main() {     read(t);     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long binPow(long long a, long long b) {     a = a % 1000000007;     if (a == 0) return 0;     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     string p;     cin >> p;     int size = p.size();     int PI[size];     PI[0] = 0;     for (int i = 1; i < size; i++) {       int j = PI[i - 1];       while (j > 0 && p[i] != p[j]) j = PI[j - 1];       if (p[i] == p[j]) j++;       PI[i] = j;     }     unordered_map<int, int> make_pair;     int j = PI[size - 1];     while (j > 0) {       make_pair[j]++;       j = PI[j - 1];     }     int y;     int last = 1;     long long count = 0;     for (int i = 0; i < m; i++) {       cin >> y;       if (y < last) {         if (make_pair[last - y] == 0) {           cout << 0 <<   n ;           return 0;         }       } else {         count += y - last;       }       last = min(n + 1, y + size);     }     count += max(0, n + 1 - last);     cout << binPow(26, count) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n], brr[n];     for (int i = 0; i < n; ++i) {       cin >> arr[i] >> brr[i];     }     for (int i = 0; i < n; ++i) {       if (arr[i] != brr[i]) {         cout <<  rated ;         return 0;       }     }     for (int i = 0; i < n - 1; ++i) {       if (arr[i] < arr[i + 1] && brr[i] < brr[i + 1]) {         cout <<  unrated ;         return 0;       }     }     cout <<  maybe ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int t, n, i, x, mx, mn, f, j, s, r, y, c, m, k, c1;     cin >> t;     while (t--) {       cin >> n;       vector<long long int> v;       f = 0;       for (i = 0; i < n; i++) {         cin >> x;         v.push_back(x);         if (x == 0) f = 1;       }       s = 2;       r = pow(3, n);       while (s < r) {         x = s;         s++;         c = c1 = 0;         set<long long int> S;         for (i = 0; i < n; i++) {           if (x % 3 == 1)             c += v[i];           else if (x % 3 == 2)             c -= v[i];           else             S.insert(v[i]);           x /= 3;         }         if (S.count(c)) f = 1;       }       if (f)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     int n;     std::cin >> n;     std::vector<int> data(n);     for (int i = 0; i < n; i++) {       std::cin >> data[i];     }     int s;     int t;     std::cin >> s;     std::cin >> t;     --s;     --t;     if (s > t) {       std::swap(s, t);     }     int sum1 = 0;     for (int i = s; i < t; i++) {       sum1 += data[i];     }     int sum2 = std::accumulate(data.begin(), data.end(), 0) - sum1;     int solution = std::min(sum1, sum2);     std::cout << solution << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int f[N], ff[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       f[x]++;     }     multiset<int> ms;     for (int i = 1; i < N; i++) {       ms.insert(f[i]);       ff[f[i]]++;     }     int q;     cin >> q;     while (q--) {       char c;       int x;       cin >> c >> x;       ff[f[x]]--;       ms.erase(ms.find(f[x]));       if (c ==  + ) {         f[x]++;       } else {         f[x]--;       }       ff[f[x]]++;       ms.insert(f[x]);       if (ms.empty()) {         cout <<  NO n ;         continue;       }       if (*ms.rbegin() >= 8) {         cout <<  YES n ;         continue;       }       vector<int> t(8);       for (int i = 1; i < 8; i++) t[i] = ff[i];       bool f = 0;       int twos = 0;       for (int i = 7; i >= 4; i--) {         if (t[i]) {           f = 1;           t[i]--;           t[i - 4]++;           break;         }       }       for (int i = 7; i >= 2; i--) {         twos += (i / 2) * t[i];       }       if (f && twos >= 2) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   const int inf = 1e7 + 7;   long long mod = 1e9 + 7;   const double eps = 1e-9;   using namespace std;   int num[1000005];   char s[1000005];   int main() {     cin >> s;     int len = strlen(s);     num[len] = 0;     for (int i = len - 1; i >= 0; i--) {       if (s[i] ==  0 )         num[i] = num[i + 1] - 1;       else {         num[i] = num[i + 1] + 1;         if (num[i] > 0) {           num[i] = 0;           s[i] =  0 ;         }       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long double ld;   const long double PI =       3.141592653589793238462643383279502884197169399375105820974944;   long long mod = 1e9 + 7;   const long long inf = 1e18;   const long long maxn = 3e5 + 5;   void solve() {     long long n, k;     cin >> n >> k;     vector<pair<long long, pair<long long, long long>>> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second.first;       v[i].second.second = i + 1;     }     sort((v).begin(), (v).end());     multiset<pair<long long, long long>> s;     vector<long long> ans;     for (auto i : v) {       while (!s.empty() && (*s.begin()).first < i.first) s.erase(s.begin());       while ((long long)((s).size()) > k) {         auto it = --s.end();         ans.push_back((*it).second);         s.erase(it);       }       if ((long long)((s).size()) == k) {         auto it = --s.end();         if ((*it).first >= i.second.first) {           ans.push_back((*it).second);           s.erase(it);           s.insert({i.second.first, i.second.second});         } else           ans.push_back(i.second.second);       } else         s.insert({i.second.first, i.second.second});     }     cout << (long long)((ans).size()) <<   n ;     for (auto i : ans) cout << i <<    ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc = 1;     while (tc--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const int N = 1005;   int a[N][N];   int dp[N][N][2];   int d[] = {2, 5};   void print(int x, int y, int z) {     if (x == 0 && y == 0) return;     if (x == 0 || y && dp[x - 1][y][z] > dp[x][y - 1][z]) {       print(x, y - 1, z);       cout <<  R ;     } else {       print(x - 1, y, z);       cout <<  D ;     }   }   int main() {     int n;     cin >> n;     int zx = -1, zy = -1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         cin >> a[i][j];         if (a[i][j] == 0) {           zx = i;           zy = j;         }       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         for (int k = 0; k < 2; ++k) {           if (i == 0 && j == 0)             dp[i][j][k] = 0;           else if (i == 0)             dp[i][j][k] = dp[i][j - 1][k];           else if (j == 0)             dp[i][j][k] = dp[i - 1][j][k];           else             dp[i][j][k] = min(dp[i][j - 1][k], dp[i - 1][j][k]);           if (a[i][j] == 0) dp[i][j][k] = 1;           for (int x = a[i][j]; x && x % d[k] == 0; x /= d[k]) dp[i][j][k]++;         }     int z = dp[n - 1][n - 1][0] > dp[n - 1][n - 1][1];     if (zx != -1 && dp[n - 1][n - 1][z] != 0) {       cout << 1 << endl;       for (int i = 0; i < zx; i++) cout <<  D ;       for (int i = 0; i < zy; i++) cout <<  R ;       for (int i = zx + 1; i < n; i++) cout <<  D ;       for (int i = zy + 1; i < n; i++) cout <<  R ;       return 0;     }     cout << dp[n - 1][n - 1][z] << endl;     print(n - 1, n - 1, z);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       if (i == a[a[a[i]]]) {         return cout <<  YES , 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int T, N, P, ap[109][109];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d %d , &N, &P), P += 2 * N;       for (int df = 1; df < N && P; df++)         for (int i = 0; i < N && P; i++) ap[i][(i + df) % N] = 1, P--;       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++)           if (ap[i][j]) printf( %d %d n , i + 1, j + 1);       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++) ap[i][j] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     int s = 0, i;     cin >> n;     while (n != 0) {       s = 0;       for (i = 0;; ++i) {         s += (1 << i);         if (s >= n) break;       }       if (s == n) {         cout << i + 1 <<    ;         n -= (1 << i);       } else {         cout << i + 1 <<    ;         n -= (1 << i);       }     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a1, a2;     cin >> a1 >> a2;     int res = 0;     while (a1 && a2 && (a1 > 1 || a2 > 1)) {       if (a1 > a2) swap(a1, a2);       ++a1;       a2 -= 2;       ++res;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long fact[1100000];   void find_fact() {     fact[0] = fact[1] = 1;     for (int i = 2; i <= 1e6; i++) fact[i] = (i * fact[i - 1]) % mod;   }   bool isvalid(long long num, int num1, int num2) {     while (num > 0) {       int cval = (num % 10);       if ((cval != num1) && (cval != num2)) return 0;       num = (num / 10);     }     return 1;   }   long long my_exp(int base, int exp) {     if (exp == 0) return 1;     if (exp == 1) return base;     long long ans = my_exp(base, exp / 2);     ans = (ans * ans) % mod;     if (exp % 2) ans = (ans * base) % mod;     return ans;   }   long long my_comb(int n, int i) {     return (fact[n] * my_exp((fact[i] * fact[n - i]) % mod, mod - 2)) % mod;   }   int main() {     find_fact();     int num1, num2, n;     cin >> num1 >> num2 >> n;     long long csm, ans = 0;     for (int i = 0; i <= n; i++) {       csm = (i * num1 + (n - i) * num2);       if (isvalid(csm, num1, num2)) ans = (ans + my_comb(n, i)) % mod;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &first, B second) {     return (first > second) ? (first = second, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &first, B second) {     return (first < second) ? (first = second, 1) : 0;   }   const int MAXN = 2e5 + 5;   int N, K, A, B, Q;   int total[MAXN];   class SegmentTree {    public:     typedef struct segment_st {       int numa, numb;       int l, r;     } TreeNode;     vector<TreeNode> tree;     int N;     int tree_size;     vector<int> leaves;     SegmentTree(int n) { build_tree(n); }     int query(int ll, int rr, int limit) { return query(1, ll, rr, limit); }     void update(int at, int val) { internal_update(at, val); }       private:     void initialize_node(int at) {       tree[at].numa = 0;       tree[at].numb = 0;     }     void update_up(int at) {       int left = at + at;       int right = at + at + 1;       tree[at].numa = tree[left].numa + tree[right].numa;       tree[at].numb = tree[left].numb + tree[right].numb;     }     void update_result(int &res, int val) { res += val; }     void update_leaf_value(int at, int &val, int d) {       tree[at].numa = min(A, total[d]);       tree[at].numb = min(B, total[d]);     }     int query(int at, int ll, int rr, int limit) {       if (ll > tree[at].r || rr < tree[at].l) return 0;       if (ll <= tree[at].l && tree[at].r <= rr) {         if (limit == 0) {           return tree[at].numb;         } else {           return tree[at].numa;         }       } else {         int res = 0;         update_result(res, query(at + at, ll, rr, limit));         update_result(res, query(at + at + 1, ll, rr, limit));         return res;       }     }     void internal_update(int at, int &val) {       int tmp = at;       at = leaves[at];       update_leaf_value(at, val, tmp);       at >>= 1;       while (at) {         update_up(at);         at >>= 1;       }     }     void build_tree(int n) {       N = n;       int base = 1;       while (base < N) base <<= 1;       tree_size = base << 1;       leaves.resize(N + 1);       tree = vector<TreeNode>(tree_size);       init(1, 1, n);     }     void init(int at, int ll, int rr) {       tree[at].l = ll;       tree[at].r = rr;       initialize_node(at);       if (ll == rr) {         leaves[ll] = at;       } else {         int mid = (tree[at].l + tree[at].r) >> 1;         init(at + at, tree[at].l, mid);         init(at + at + 1, mid + 1, tree[at].r);         update_up(at);       }     }   };   int main() {     scanf( %d %d %d %d %d , &N, &K, &A, &B, &Q);     SegmentTree tree(N);     int c;     for (int(i) = 0; (i) < (Q); ++(i)) {       scanf( %d , &c);       if (c == 1) {         int d, a;         scanf( %d %d , &d, &a);         total[d] += a;         tree.update(d, a);       } else {         int p;         scanf( %d , &p);         int res = 0;         if (p - 1 >= 1) res += tree.query(1, p - 1, 0);         p += K;         if (p <= N) res += tree.query(p, N, 1);         printf( %d n , res);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mx, my, w;   map<double, int> a, b;   int rev(long long x) {     long long ret = 0;     while (x) {       ret *= 10;       ret += x % 10;       x /= 10;     }     return ret;   }   long long get(long long x, long long y) {     a.clear();     for (long long i = 1; i <= y; ++i) {       double tmp = 1.0 * rev(i) / i;       a[tmp]++;     }     long long ret = 0;     for (long long i = 1; i <= x; ++i) {       double tmp = 1.0 * i / rev(i);       ret += a[tmp];     }     return ret;   }   int main() {     cin >> mx >> my >> w;     if (get(mx, my) < w) {       puts( -1 );       return 0;     }     int nx = mx, ny = 1, ax = mx, ay = my;     long long now = get(nx, ny);     a.clear();     for (long long i = 1; i <= nx; ++i) {       a[1.0 * i / rev(i)]++;     }     b.clear();     for (long long i = 1; i <= ny; ++i) {       b[1.0 * rev(i) / i]++;     }     while (nx >= 1 && ny <= my) {       if (now < w) {         ny++;         double tmp = 1.0 * rev(ny) / ny;         now += a[tmp];         b[tmp]++;       } else {         if (1ll * nx * ny < 1ll * ax * ay) {           ax = nx;           ay = ny;         }         double tmp = 1.0 * nx / rev(nx);         nx--;         now -= b[tmp];         a[tmp]--;       }     }     cout << ax <<     << ay << endl;     return 0;   }