malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int pow(long long int x, long long int y, long long int m) {     long long int res = 1;     x = x % m;     while (y > 0) {       if (y & 1) res = ((res % m) * (x % m)) % m;       y = y >> 1;       x = ((x % m) * (x % m)) % m;     }     return res % m;   }   template <typename Arg1>   void ZZ(const char* name, Arg1&& arg1) {     std::cerr << name <<   =   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void ZZ(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   =   << arg1;     ZZ(comma, args...);   }   const long long int INF = 0xFFFFFFFFFFFFFFFL;   long long int clz(unsigned long long N) {     return N ? 64LL - __builtin_clzll(N) : -INF;   }   clock_t time_p = clock();   void abhigyan10() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   long long int seed;   mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());   inline long long int rnd(long long int l = 0, long long int r = INF) {     return uniform_int_distribution<long long int>(l, r)(rng);   }   const long long int mod = 1000000007;   long long int modinv(long long int x) { return pow(x, mod - 2, mod); }   vector<long long int> a;   int bs(long long int x, long long int n) {     long long int l = 0, h = n - 1, m, ans = 0;     while (l <= h) {       m = (l + h) / 2;       if (a[m] <= x) {         l = m + 1;         ans = max(ans, m);       } else {         h = m - 1;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int s = 0, t, n, p, i;     cin >> n >> p;     a.resize(n);     for (i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     for (i = 0; i < n; i++) s = max(s, a[i] - i);     t = a[n - 1];     for (i = 0; i < n;) {       int d = t + i;       int u = bs(d, n) + 1 - i;       if (u < p)         i++;       else         t--;       if (t < s) break;     }     cout << max(0LL, t - s + 1) <<   n ;     for (i = s; i <= t; i++) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long powmod(long long a, long long l, long long md) {     long long res = 1;     while (l) {       if (l & 1) res = res * a % md;       l /= 2;       a = a * a % md;     }     return res;   }   long long binpow(long long a, long long l) {     long long res = 1;     while (l) {       if (l & 1) res = res * a;       l /= 2;       a = a * a;     }     return res;   }   long long __set(long long b, long long i) { return b | (1 << i); }   long long __unset(long long b, long long i) { return b & (~(1UL << i)); }   long long __check(long long b, long long i) { return b & (1 << i); }   long long mulmod(long long a, long long b, long long md) {     return ((a % md) * (b % md)) % md;   }   long long addmod(long long a, long long b, long long md) {     return (a + b) % md;   }   long long submod(long long a, long long b, long long md) {     return (((a - b) % md) + md) % md;   }   long long divmod(long long a, long long b, long long md) {     return mulmod(a, powmod(b, md - 2, md), md);   }   const long long inf = 0xFFFFFFFFFFFFFFFL;   priority_queue<long long, vector<long long>, greater<long long> > pq;   clock_t time_p = clock();   void time() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   long long d[3][10];   signed main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     for (long long i = 0; i < 3; i++) {       string s;       cin >> s;       if (s[1] ==  m ) {         d[0][s[0] -  0 ]++;       } else if (s[1] ==  p ) {         d[1][s[0] -  0 ]++;       } else {         d[2][s[0] -  0 ]++;       }     }     long long mx = 3;     for (long long i = 0; i < 3; i++) {       for (long long j = 1; j <= 9; j++) mx = min(mx, 3 - min(3ll, d[i][j]));       for (long long j = 1; j <= 7; j++) {         long long tp = 0;         if (!d[i][j]) tp++;         if (!d[i][j + 1]) tp++;         if (!d[i][j + 2]) tp++;         mx = min(mx, tp);       }     }     cout << mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500001;   int a[maxn][2];   int cur, n;   int r[maxn][2], tot;   void dosth() {     int i;     a[1][cur ^ 1] = a[1][cur];     a[n][cur ^ 1] = a[n][cur];     for (i = 2; i < n; ++i)       a[i][cur ^ 1] = a[i - 1][cur] + a[i][cur] + a[i + 1][cur] > 1 ? 1 : 0;     cur ^= 1;   }   int count() {     int f = !a[1][0], i, j, ans = 0, tmp = 1;     a[0][0] = a[1][0];     for (i = 2; i <= n; ++i) {       if (a[i][0] != ((i + f) & 1)) {         if (1) {           for (j = 1; j <= tmp / 2; ++j) a[i - j][0] = a[i][0];           for (j = tmp / 2 + 1; j <= tmp; ++j) a[i - j][0] = a[i - tmp - 1][0];         }         ans = max(ans, tmp), tmp = 1, f ^= 1;       } else         tmp++;     }     for (j = 1; j <= tmp / 2; ++j) a[i - j][0] = a[n][0];     for (j = tmp / 2 + 1; j <= tmp; ++j) a[i - j][0] = a[i - tmp - 1][0];     return (max(ans, tmp) - 1) / 2;   }   int main() {     scanf( %d , &n);     int i, j;     cur = 0;     for (i = 1; i <= n; ++i) {       char c;       do c = getchar();       while (!isdigit(c));       a[i][0] = c - 48;     }     printf( %d n , count());     for (i = 1; i <= n; ++i) putchar(a[i][0] +  0 ), putchar(   );     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %1d , num + i);     for (int i = 1; i <= n && k; i++) {       if (num[i] == 4 && num[i + 1] == 7) {         if (i % 2 == 0 && num[i - 1] == 4) {           if (k % 2) {             num[i] = 7;           }           break;         }         if (i % 2 == 1 && i + 2 <= n && num[i + 2] == 7) {           if (k % 2) {             num[i + 1] = 4;           }           break;         }         if (i % 2 == 0)           num[i] = 7;         else           num[i + 1] = 4;         k--;       }     }     for (int i = 1; i <= n; i++) printf( %d , num[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 1;     for (int i = 6; i <= n; i++) {       if (n % i == 0) {         int k1 = 0, k0 = 0;         int f = 0;         int x = i;         while (x > 1 and f == 0) {           int x2 = x % 2;           if (x2 == 1 and k0 > 0)             k1++;           else if (x2 == 0 and k1 == 0)             k0++;           else             f = 1;           x /= 2;         }         if (k1 - k0 == 0 and f == 0) ans = i;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, ans[2005];   char a[2010][2010];   void load() {     scanf( %d%d%d n , &n, &m, &k);     for (int i = 0; i < n; i++) {       scanf( %s , a[i]);     }   }   void solve() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  L ) {           if (j - i >= 0) {             ans[j - i]++;           }         }         if (a[i][j] ==  R ) {           if (j + i < m) {             ans[j + i]++;           }         }         if (a[i][j] ==  U ) {           if (i % 2 == 0) {             ans[j]++;           }         }       }     }     for (int i = 0; i < m; i++) {       if (i > 0) printf(   );       printf( %d , ans[i]);     }     printf(  n );   }   int main() {     load();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m;     cin >> m;     int c[m];     int sum1 = 0;     for (int i = 0; i < m; i++) {       cin >> c[i];       sum1 += c[i];     }     int x, y;     cin >> x >> y;     int flag = 0;     int k = 1;     int sum2 = 0;     if (sum2 >= x && sum2 <= y && sum1 - sum2 >= x && sum1 - sum2 <= y) {       flag = 1;       cout <<  1  << endl;     } else {       for (int i = 1; i <= m; i++) {         k = i;         sum2 += c[i - 1];         if (sum2 >= x && sum2 <= y && sum1 - sum2 >= x && sum1 - sum2 <= y) {           flag = 1;           cout << i + 1 << endl;           break;         }       }     }     if (flag == 0) {       cout <<  0  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y;   char a[100005];   int main(void) {     scanf( %d%d%d , &n, &x, &y);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (a[x] == a[y])       puts( 0 );     else       puts( 1 );   }
#include <bits/stdc++.h>   using namespace std;   int kk[(100010)];   map<int, int> possible;   int main() {     int t, m, k, tj, rj, pre(0);     bool first(false), already(false);     scanf( %d , &t);     for (int i = 0; i < t; ++i) {       first = false;       already = false;       pre = 0;       possible.clear();       scanf( %d%d , &m, &k);       for (int j = 1; j <= k; ++j) {         scanf( %d , &kk[j]);       }       for (int j = 0; j < m - 1; ++j) {         scanf( %d%d , &tj, &rj);         if (rj == 1 && !first) {           first = true;           for (int l = 1; l <= k; ++l) {             if (kk[l] == 0) {               already = true;               break;             }           }           if (!already) {             for (int l = 1; l <= k; ++l) {               if (kk[l] <= pre) {                 possible[l] = kk[l];               }             }           }         }         if (tj == 0) {           pre += 1;         } else {           kk[tj] -= 1;           if (first && !already) {             if (possible[tj] != 0) {               possible.erase(tj);             }           }         }       }       if (!already && first) {         int min = 100001;         map<int, int>::iterator it = possible.begin();         while (it != possible.end()) {           int count = (*it).second;           if (count != 0 && count < min) {             min = (*it).second;           }           it++;         }         pre -= min;       }       for (int j = 1; j <= k; ++j) {         if (possible[j] != 0) {           printf( %c ,  Y );         } else if (kk[j] <= pre) {           printf( %c ,  Y );         } else {           printf( %c ,  N );         }       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   long long int B = 257;   char s[1000100];   char t[1000100];   int n;   int m;   unsigned long long int hash1[1000100];   unsigned long long int hash2[1000100];   struct resp {     unsigned long long int count;     unsigned long long int indices[1000100];   } indice;   long long int expBinaria(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b % 2) res = res * a;       b = b / 2;       a = a * a;     }     return res;   }   void armaHashes() {     hash1[0] = 0;     for (int i = 1; i <= n; i++) {       hash1[i] = hash1[i - 1] * B + s[i - 1];     }     hash2[0] = 0;     for (int i = 1; i <= m; i++) {       hash2[i] = hash2[i - 1] * B + t[i - 1];     }   }   long long int h_1(int i, int j) {     return hash1[j] - hash1[i - 1] * expBinaria(B, j - i + 1);   }   long long int h_2(int i, int j) {     return hash2[j] - hash2[i - 1] * expBinaria(B, j - i + 1);   }   void solve() {     long long int cuenta = 0;     if (h_1(2, n) == h_2(1, m)) {       indice.indices[cuenta] = 1;       cuenta++;     }     for (int i = 2; i < n; i++) {       if (h_1(1, i - 1) == h_2(1, i - 1) && h_1(i + 1, n) == h_2(i, m)) {         indice.indices[cuenta] = i;         cuenta++;       }     }     if (h_1(1, n - 1) == h_2(1, m)) {       indice.indices[cuenta] = n;       cuenta++;     }     indice.count = cuenta;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s;     cin >> t;     n = strlen(s);     m = strlen(t);     armaHashes();     solve();     cout << indice.count;     cout <<   n ;     for (int i = 0; i < indice.count; i++) {       cout << indice.indices[i];       cout <<   t ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<int> gr[50005];   int n, k;   bool vis[50005];   int lev[50005][505];   long long int dp[50005];   void dfs(int v) {     vis[v] = true;     lev[v][0] = 1;     for (auto ed : gr[v]) {       if (!vis[ed]) {         dfs(ed);         for (long long int i = 1; i < k + 1; i++) lev[v][i] += lev[ed][i - 1];       }     }   }   void solve(int v) {     vis[v] = true;     for (auto ed : gr[v]) {       if (!vis[ed]) {         solve(ed);         for (long long int i = 1; i < k; i++)           dp[v] += lev[ed][i - 1] * (lev[v][k - i] - lev[ed][k - i - 1]);       }     }     dp[v] /= 2;     dp[v] += lev[v][k];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     int a, b;     for (long long int i = 0; i < n - 1; i++) {       cin >> a >> b;       gr[a].push_back(b);       gr[b].push_back(a);     }     memset(lev, 0, sizeof(lev));     memset(vis, false, sizeof(vis));     dfs(1);     memset(vis, false, sizeof(vis));     memset(dp, 0, sizeof(dp));     solve(1);     long long int ans = 0;     for (long long int i = 1; i < n + 1; i++) ans += dp[i];     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<bool> Prime(20000000 + 1, 1);   vector<bool> Pal(20000000 + 1, 1);   void gen1() {     long long int n = 2000000;     Prime[1] = 0;     for (long long int i = 2; i <= 20000000; i++) {       if (Prime[i]) {         for (long long int j = i + i; j <= n; j += i) Prime[j] = false;       }     }   }   void gen2() {     long long int n = 20000000;     long long int num, rev = 0, digit;     for (long long int i = 1; i <= 20000000; i++) {       num = i;       while (num > 0) {         digit = num % 10;         rev = rev * 10 + digit;         num = num / 10;       }       if (i != rev) Pal[i] = false;       rev = 0;     }   }   long long int a, b;   int main() {     ios::sync_with_stdio(false);     gen1(), gen2();     cin >> a >> b;     long long int ans = 1, primes = 0, pals = 0;     for (long long int i = 1; i <= 20000000; i++) {       if (Prime[i]) primes++;       if (Pal[i]) pals++;       if (b * primes <= a * pals) ans = max(ans, i);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   bitset<6> a, b;   int main() {     int n;     cin >> n;     a = bitset<6>(n);     b.set(5, a[5]);     b.set(4, a[0]);     b.set(3, a[2]);     b.set(2, a[3]);     b.set(1, a[1]);     b.set(0, a[4]);     cout << b.to_ulong();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, c[100000], b[100000], a[100000], s1 = 0, s2 = 0, s3 = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       s1 += a[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> b[i];       s2 += b[i];     }     for (int i = 0; i < n - 2; i++) {       cin >> c[i];       s3 += c[i];     }     cout << s1 - s2 << endl << s2 - s3;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool a[30][30];   void fun(int x, int y) { a[x][y] = a[y][x] = true; }   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       memset(a, false, sizeof a);       int n, p;       cin >> n >> p;       if (n % 2 == 0) {         for (int i = 1; i <= n; i++) {           fun(i, i + 1);         }         fun(1, n);         int last;         for (int i = 1; i + 2 <= n; i += 2) {           fun(i, i + 2);           last = i + 2;         }         fun(2, last);         for (int i = 2; i + 2 <= n - 2; i += 2) {           if (i + 2 == n - 2) {             fun(i, i + 4);             last = i + 2;           } else             fun(i, i + 2);           last = i + 2;         }         fun(last, last + 2);         fun(1, last);         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n and p > 0; j++) {             if (i != j and a[i][j] == false) {               p--;               fun(i, j);             }           }         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++)             if (i < j and a[i][j]) cout << i <<     << j << endl;       } else {         for (int i = 1; i <= n; i++) {           fun(i, i + 1);         }         fun(1, n);         int last;         for (int i = 1; i + 2 <= n; i += 2) {           fun(i, i + 2);           last = i + 2;         }         fun(2, last);         for (int i = 2; i + 2 <= n; i += 2) {           fun(i, i + 2);           last = i + 2;         }         fun(1, last);         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n and p > 0; j++) {             if (i != j and a[i][j] == false) {               p--;               fun(i, j);             }           }         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++)             if (i < j and a[i][j]) cout << i <<     << j << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (n < k * 1ll * (k + 1) / 2) {       cout <<  NO  << endl;       return 0;     }     int nn = n - k * (k + 1) / 2;     vector<int> a(k);     for (int i = 0; i < k; ++i) {       a[i] = i + 1 + (nn / k) + (i >= k - nn % k);     }     if (nn != k - 1) {       cout <<  YES  << endl;       for (int i = 0; i < k; ++i) cout << a[i] <<    ;       cout << endl;     } else {       if (k > 3) {         --a[1];         ++a[k - 1];       }       if (k == 2 || k == 3) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         for (int i = 0; i < k; ++i) cout << a[i] <<    ;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, mod = 1e9 + 7;   long long a[N], x, n, sum;   long long fastpower(long long b, long long p) {     if (p == 0) return 1;     long long halfpower = fastpower(b, p / 2) % mod;     halfpower *= halfpower;     halfpower %= mod;     if (p % 2) halfpower = (halfpower * (b % mod)) % mod;     return halfpower;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     map<long long, long long> mp;     for (int i = 0; i < n; i++) mp[sum - a[i]]++;     for (auto i : mp) {       mp[i.first + 1] += (i.second / x);       if (i.second % x) {         cout << fastpower(x, min(i.first, sum));         return 0;       }     }   }
#include <bits/stdc++.h>   int const maxn = 255;   int const mod = 1e9 + 7;   long long a[maxn];   long long c[maxn][maxn];   long long pow(long long a, long long b, long long p) {     long long r = 1;     while (b) {       if (b & 1) r = (r * a) % p;       a = (a * a) % p;       b >>= 1;     }     return r;   }   int main() {     int n, k, i, j;     for (i = 0; i < maxn; i++) {       c[i][0] = c[i][i] = 1;       for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     }     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++)       a[i] = pow(pow(k, i, mod) - pow(k - 1, i, mod), n, mod);     long long ans = a[n];     for (i = 1; i <= n; i++) {       if (i & 1)         ans = (ans - ((c[n][i] * pow(k - 1, i * n, mod)) % mod * a[n - i]) % mod +                mod) %               mod;       else         ans =             (ans + ((c[n][i] * pow(k - 1, i * n, mod)) % mod * a[n - i]) % mod) %             mod;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long res = 1;     a = a % 1000000007;     while (b > 0) {       if (b & 1) {         res = (res * a) % 1000000007;         b--;       }       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   long long fermat_inv(long long y) { return power(y, 1000000007 - 2); }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       int n, q;       cin >> n >> q;       set<int> s;       for (int i = 0; i < n; i++) {         int a;         cin >> a;         s.insert(a);       }       map<long long, int> m;       for (auto it = s.begin(); it != s.end();) {         int val = *it;         val = -val;         it++;         if (it == s.end()) break;         val += (*it);         m[val]++;       }       auto it = m.end();       if (it == m.begin())         cout <<  0 n ;       else {         auto it1 = s.begin();         auto it2 = s.end();         it2--;         long long ans = (*it2) - (*it1);         it--;         ans -= it->first;         cout << ans <<   n ;       }       while (q--) {         int ty, x;         cin >> ty >> x;         if (ty == 0) {           auto it = s.lower_bound(x);           int ctr = 0;           long long val1 = 0;           if (it != s.begin()) {             it--;             long long val = x - (*it);             val1 += val;             ctr++;             m[val]--;             if (m[val] == 0) m.erase(val);           }           auto it1 = s.upper_bound(x);           if (it1 != s.end()) {             long long val = (*it1) - x;             m[val]--;             ctr++;             val1 += val;             if (m[val] == 0) m.erase(val);           }           if (ctr == 2) m[val1]++;           s.erase(x);         } else {           int ctr = 0;           auto it = s.lower_bound(x);           long long val1 = 0;           if (it != s.begin()) {             it--;             long long val = x - (*it);             val1 += val;             ctr++;             m[val]++;           }           auto it1 = s.upper_bound(x);           if (it1 != s.end()) {             long long val = (*it1) - x;             val1 += val;             ctr++;             m[val]++;           }           if (ctr == 2) m[val1]--;           if (m[val1] == 0) m.erase(val1);           s.insert(x);         }         auto it = m.end();         if (it == m.begin())           cout <<  0 n ;         else {           auto it1 = s.begin();           auto it2 = s.end();           it2--;           long long ans = (*it2) - (*it1);           it--;           ans -= it->first;           cout << ans <<   n ;         }       }     }     return 0;   }