malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long K = 1000000000000000000;   map<int, int> M;   int q, mn, w[600005], nxt[600005], Q[600005], anc[600005], r;   char opt[5], s[600005];   long long ans0, ans, g, ansx, ansy;   int mask((1 << 30) - 1);   int calc(int x) { return w[Q[lower_bound(Q + 1, Q + r + 1, x) - Q]]; }   int main() {     mn = 1 << 30;     scanf( %d , &q);     int j(0);     for (int i = 1; i <= q; ++i) {       scanf( %s%d , opt, &w[i]);       s[i] = (ansy + opt[0] -  a ) % 26 +  a ;       w[i] ^= (ansx & mask);       mn = min(mn, w[i]);       if (i == 1) {         printf( %lld n , ans = w[i]);         ansx = ans & mask;         ansy = w[i] % 26;         while (r && w[Q[r]] >= w[i]) --r;         Q[++r] = i;         continue;       }       while (j && s[j + 1] != s[i]) j = nxt[j];       if (s[j + 1] == s[i]) ++j;       nxt[i] = j;       if (s[i] == s[nxt[i - 1] + 1])         anc[i - 1] = anc[nxt[i - 1]];       else         anc[i - 1] = nxt[i - 1];       for (int j = (s[i - 1] == s[1] ? i - 1 : nxt[i - 1]); j;) {         if (s[j + 1] == s[i])           j = anc[j];         else {           int o(calc(i - j));           g -= o;           map<int, int>::iterator it = M.lower_bound(o);           assert(it != M.end());           --it->second;           if (!it->second) M.erase(it);           j = nxt[j];         }       }       while (r && w[Q[r]] >= w[i]) --r;       Q[++r] = i;       int cnt(s[i] == s[1]);       map<int, int>::iterator it = M.lower_bound(w[i]);       while (it != M.end()) {         g -= (long long)it->first * it->second;         cnt += it->second;         M.erase(it);         it = M.lower_bound(w[i]);       }       g += (long long)cnt * w[i];       M.insert(make_pair(w[i], cnt));       ans += g, ans += mn;       if (ans >= K) ++ans0, ans -= K;       ansx = (ansx + g + mn) & mask;       ansy = (ansy + g + mn) % 26;       if (!ans0)         printf( %lld n , ans);       else {         cout << ans0 << setw(18) << setfill( 0 ) << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double chance[100005];   int main() {     int n, p;     while (cin >> n >> p) {       memset(chance, 0, sizeof chance);       long double tmp;       for (int i = 0; i < n; i++) {         int a, b;         cin >> a >> b;         int tem = b / p - (a - 1) / p;         tmp = (long double)tem / (b - a + 1);         chance[i] = tmp;       }       long double ans = 0;       for (int i = 1; i < n; i++) {         ans += chance[i] + chance[i - 1] - chance[i] * chance[i - 1];       }       ans += chance[0] + chance[n - 1] - chance[n - 1] * chance[0];       cout << fixed << setprecision(10) << ans * 2000.0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   const int N = 4e5 + 100;   int n, m;   vector<int> vc[N];   int to[N];   multiset<int> st;   void Ac() {     for (int i = 1, v; i <= n; ++i) {       scanf( %d , &v);       to[v] = i;     }     st.insert(n + 1);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       u = to[u];       v = to[v];       if (u > v) swap(u, v);       vc[u].push_back(v);       st.insert(v);     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += (*st.begin()) - i;       for (int v : vc[i]) {         st.erase(st.lower_bound(v));       }     }     printf( %I64d n , ans);   }   int main() {     while (~scanf( %d%d , &n, &m)) {       Ac();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long>::iterator itr;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     long long t;     cin >> t;     while (t--) {       long long num, k;       cin >> num >> k;       vector<long long> v;       vector<long long> v1;       for (long long i = 0; i < num; i++) {         long long x;         cin >> x;         v.push_back(x);       }       for (long long i = 0; i < num; i++) {         long long x;         cin >> x;         v1.push_back(x);       }       sort(v.begin(), v.end());       sort(v1.begin(), v1.end(), greater<long long>());       long long sum = 0;       for (long long i = 0; i < k; i++) {         if (v1[i] > v[i])           sum += v1[i];         else           sum += v[i];       }       for (long long i = k; i < num; i++) {         sum += v[i];       }       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 3e5 + 10;   vector<pair<int, int>> vp[N];   vector<int> v[N];   int pos[N];   int deg[N];   int vis[N];   vector<int> ans;   void dfs(int x, int p = 0, int o = 0) {     if (vis[x]) return;     v[p].push_back(x);     vis[x] = 1;     pos[x] = o;     for (auto &pp : vp[x]) {       int y, oo;       tie(y, oo) = pp;       dfs(y, x, oo);     }   }   int solve(int x) {     int cur = deg[x];     for (auto &y : v[x]) {       cur ^= solve(y);     }     if (cur) ans.push_back(pos[x]);     return cur;   }   int main() {     int n, m;     cin >> n >> m;     int cnt1 = 0, cnt_1 = 0;     for (int i = 1; i <= n; i++) {       cin >> deg[i];       if (deg[i] == 1) cnt1 ^= 1;       if (deg[i] == -1) cnt_1++;     }     if (cnt1 == 1 && cnt_1 == 0) {       puts( -1 );       return 0;     }     for (int i = 1; i <= n; i++) {       if (deg[i] == -1) {         deg[i] = cnt1;         cnt1 = 0;       }     }     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       vp[x].push_back({y, i});       vp[y].push_back({x, i});     }     dfs(1);     solve(1);     printf( %d n , ans.size());     for (auto &x : ans) printf( %d n , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string pal, pal2;     int x = 0;     bool b1 = false;     cin >> pal;     for (int i = 0; i < pal.size(); i++) {       if (pal[i] ==  W  and pal[i + 1] ==  U  and pal[i + 2] ==  B ) {         i += 2;         if (b1 == true) {           pal2 +=    ;           b1 = false;         }       } else {         b1 = true;         pal2 += pal[i];       }     }     cout << pal2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^  0 ), c = getchar();     return x * f;   }   const int N = 2e5 + 5;   int d, n, m;   struct node {     int x, p;   } a[N];   inline int operator<(const node x, const node y) {     if (x.p == y.p) return x.x > y.x;     return x.p > y.p;   }   inline int cmp(node x, node y) { return x.x < y.x; }   priority_queue<node> q;   long long ans;   int main() {     d = read(), n = read(), m = read();     for (int i = 1; i <= m; i++) a[i] = {read(), read()};     sort(a + 1, a + m + 1, cmp);     int t = n, j = 1;     while (t < d) {       while (j <= m && a[j].x <= t) q.push(a[j++]);       while (!q.empty() && q.top().x + n <= t) q.pop();       if (q.empty()) return puts( -1 ), 0;       int x = q.top().x, p = q.top().p;       int nxt = min(d, x + n);       if (j <= m && nxt >= a[j].x) nxt = a[j].x;       ans += 1ll * p * (nxt - t);       t = nxt;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nMod = 1e9 + 7;   inline long long GCD(long long a, long long b) {     while (b != 0) {       long long c = a % b;       a = b;       b = c;     }     return a;   };   inline long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; };   void vietnakid() {     int TC;     cin >> TC;     while (TC--) {       int n;       string s;       cin >> n;       cin >> s;       int fm = n, lr = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  > ) {           fm = min(fm, i);         } else {           lr = max(lr, i);         }       }       cout << min(fm, n - lr - 1) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     vietnakid();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long int word, prefix;     node *child[2];     node() {       word = prefix = 0;       child[0] = child[1] = NULL;     }   };   void insert(node *root, long long int x, long long int bit) {     root->prefix += 1;     if (bit < 0) {       root->word += 1;       return;     }     bool b = (x & (1 << bit));     if (root->child[b] == NULL) {       root->child[b] = new node();     }     insert(root->child[b], x, bit - 1);   }   node *deleteit(node *root, long long int x, long long int bit) {     if (root == NULL) {       return NULL;     }     root->prefix -= 1;     if (bit < 0) {       root->word -= 1;       if (root->word == 0 && root->prefix == 0) {         delete root;         return NULL;       }       return root;     }     bool b = (x & (1 << bit));     root->child[b] = deleteit(root->child[b], x, bit - 1);     if (root->word == 0 && root->prefix == 0) {       delete root;       return NULL;     }     return root;   }   long long int query(node *root, long long int x, long long int k,                       long long int bit, long long int ans) {     if (bit < 0 || root == NULL) {       return ans;     }     bool a = (x & (1 << bit)), a_complement = (!a);     bool b = (k & (1 << bit)), b_complement = (!b);     if (b == true) {       if (root->child[a] != NULL) {         ans += root->child[a]->prefix;       }       return query(root->child[a_complement], x, k, bit - 1, ans);     } else {       return query(root->child[a], x, k, bit - 1, ans);     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     node *root = new node;     long long int q, x, y, t;     cin >> q;     for (long long int i = 0; i < q; i++) {       cin >> t >> x;       if (t == 1) {         insert(root, x, 31);       } else if (t == 2) {         root = deleteit(root, x, 31);         if (root == NULL) {           root = new node;         }       } else {         cin >> y;         cout << query(root, x, y, 31, 0) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int a, b, n;     cin >> a >> b >> n;     bool exist(false);     for (int i = 0; i < 10; i++) {       if ((a * 10 + i) % b == 0) {         cout << a * 10 + i;         string s(n - 1,  0 );         cout << s << endl;         exist = true;         break;       }     }     if (!exist) cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vis[100010];   int pr[100010], e;   void Shai() {     vis[1] = true;     for (long long i = 2; i <= 1000ll; i++) {       if (!vis[i]) {         pr[++e] = i;         for (long long j = i * i; j <= 1000ll; j += i) {           vis[j] = true;         }       }     }   }   int n, cnta[100010];   int main() {     Shai();     int x, y;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &x, &y);       int X = x;       for (int j = 1; j <= e; ++j) {         if (X % pr[j] == 0) {           while (X % pr[j] == 0) {             X /= pr[j];             ++cnta[j];           }         }       }       bool lose = 0;       for (int j = 1; j <= e; ++j) {         int cntb = 0;         if (y % pr[j] == 0) {           while (y % pr[j] == 0) {             y /= pr[j];             ++cntb;           }         }         if ((cnta[j] + cntb) % 3 != 0) {           lose = 1;           break;         } else if (min(cnta[j], cntb) * 2 < max(cnta[j], cntb)) {           lose = 1;           break;         }       }       if (!(X == 1 && y == 1) && !((long long)min(X, y) * (long long)min(X, y) ==                                    (long long)max(X, y))) {         lose = 1;       }       for (int j = 1; j <= e; ++j) {         cnta[j] = 0;       }       if (!lose)         puts( Yes );       else         puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream in( test.in );   ofstream out( test.out );   const int DIM = 2e3 + 1;   const int INF = 1e9 + 7;   int dp[DIM];   set<int> mst;   deque<int> que;   vector<int> edg[DIM];   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int k, n;     cin >> k >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       mst.insert(x - k);     }     for (int x : mst) {       for (int i = 0; i < DIM; i++) {         if (i + x > -1 && i + x < DIM) edg[i].push_back(i + x);       }     }     fill(dp, dp + DIM, INF);     dp[DIM / 2] = 0;     que.push_back(DIM / 2);     int ans = INF;     for (; que.empty() == false; que.pop_front()) {       int x = que.front();       for (int y : edg[x]) {         if (dp[y] == INF)           dp[y] = dp[x] + 1, que.push_back(y);         else if (y == DIM / 2)           ans = min(ans, dp[x] + 1);       }     }     cout << (ans == INF ? -1 : ans) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 4;   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test = 1;     cin >> test;     for (int qw = 1; qw <= test; qw++) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       int sum = 0;       for (int i = 0; i < n; i++) sum += a[i];       if (!isPrime(sum)) {         cout << n << endl;         for (int i = 1; i <= n; i++) cout << i <<    ;         cout << endl;       } else {         int flag = 0;         for (int i = 0; i < n; i++) {           if (!isPrime(sum - a[i])) {             cout << n - 1 << endl;             flag = 1;             for (int j = 0; j < n; j++) {               if (i != j) cout << j + 1 <<    ;             }             cout << endl;           }           if (flag == 1) break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     t = 1;     while (t--) {       int n, m, i, j;       cin >> n >> m;       int a[n + 2][m + 2];       int ii = -1, jj = -1;       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           cin >> a[i][j];           if (a[i][j] > 0) ii = i;           jj = j;         }       }       if (ii == -1)         cout << jj << endl;       else {         for (i = ii; i >= 0; i--) {           for (j = jj; j >= 0; j--) {             int mn = 9000;             if (a[i][j] == 0) {               if ((i + 1) < n) mn = min(mn, a[i + 1][j]);               if ((j + 1) < m) mn = min(mn, a[i][j + 1]);               a[i][j] = mn - 1;             }           }         }         int sum = 0, in = 1;         for (i = 0; i < n; i++) {           for (j = 0; j < m; j++) {             sum += a[i][j];             if (i < n - 1 && j < m)               if (a[i + 1][j] <= a[i][j]) in = 0;             if (j < m - 1 && i < n)               if (a[i][j + 1] <= a[i][j]) in = 0;           }         }         if (in == 1)           cout << sum << endl;         else           cout << -1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long a, b, x, y;   long long best, ansp, ansq;   int main() {     while (cin >> a >> b >> x >> y) {       long long gg = gcd(x, y);       x /= gg;       y /= gg;       best = -1;       long long maxr = min(a / x, b / y);       if (maxr <= 0)         cout << 0 <<     << 0 << endl;       else         cout << x * maxr <<     << y * maxr << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 2e5 + 10;   int n, k;   long long fac[maxn + 10], afac[maxn + 10];   long long qpow(long long a, long long b) {     long long ret = 1LL;     while (b) {       if (b & 1) ret = ret * a % mod;       a = a * a % mod;       b >>= 1;     }     return ret;   }   long long inv(long long x) { return qpow(x, mod - 2); }   void Pre() {     fac[0] = 1LL;     for (int i = 1; i <= maxn; i++) fac[i] = fac[i - 1] * (long long)i % mod;     afac[maxn] = inv(fac[maxn]);     for (int i = maxn; i >= 1; --i) afac[i - 1] = afac[i] * i % mod;   }   long long C(long long n, long long m) {     if (m > n) return 0;     return fac[n] * afac[n - m] % mod * afac[m] % mod;   }   void solve() {     vector<pair<int, int> > h;     int l, r;     for (int i = 1; i <= n; i++) {       scanf( %d %d , &l, &r);       h.push_back(make_pair(l - 1, 1));       h.push_back(make_pair(r, -1));     }     sort(h.begin(), h.end());     long long cnt = 0LL, ans = 0LL;     int pos = h[0].first;     for (int i = 0; i < h.size(); i++) {       long long tmp = C(cnt, k) * (h[i].first - pos) % mod;       ans = (ans + tmp) % mod;       cnt += 1LL * h[i].second;       pos = h[i].first;     }     printf( %I64d n , ans);   }   int main() {     Pre();     while (scanf( %d %d , &n, &k) != EOF) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int INF = 0x3f3f3f3f;   char tmp[20][20];   char raw[MAXN];   long long n, m, T, k;   bool check(int l, int r) {     for (int i = 1; i <= n; i++) {       if (r - l + 1 < strlen(tmp[i]))         continue;       else {         int cur_len = strlen(tmp[i]);         bool flg = true;         for (int j = 0; j < cur_len; j++) {           if (tmp[i][cur_len - j - 1] == raw[r - j])             continue;           else {             flg = false;             continue;           }         }         if (flg) return false;       }     }     return true;   }   int main() {     scanf( %s , raw);     int l = 0, r = 0, res_len = 0, res_pos = 0;     scanf( %I64d  , &n);     for (int i = 1; i <= n; i++) scanf( %s , tmp[i]);     while (r < strlen(raw)) {       while (l <= r) {         if (check(l, r)) {           if (r - l + 1 > res_len) {             res_len = r - l + 1;             res_pos = l;           }           break;         }         l++;       }       r++;     }     cout << res_len <<     << res_pos << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int tot = 0, fh = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fh = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       tot = tot * 10 + c -  0 ;       c = getchar();     }     return tot * fh;   }   int n, cnt, a[20000], ha[20000], b[20000], c[20000], ans, f[200][20000];   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) ha[a[i]]++;     for (int i = 1; i <= 100; i++)       if (ha[i]) {         b[++cnt] = ha[i];         c[cnt] = i;       }     if (cnt == 1 || cnt == 2)       cout << n <<   n ;     else {       for (int i = 1; i <= cnt; i++) {         if (b[i] <= ans) continue;         for (int j = 1; j <= 10000; j++)           for (int k = 1; k <= 100; k++) f[k][j] = 0;         f[0][0] = 1;         for (int j = 1; j <= n; j++)           if (a[j] != c[i]) {             for (int k = j - 1; k >= 0; k--)               for (int p = 10000 - a[j]; p >= 0; p--)                 if (f[k][p]) f[k + 1][p + a[j]] = 1;           }         for (int j = b[i]; j > ans && j >= 1; j--) {           bool flag = true;           for (int k = 0; k < j; k++)             if (f[j - k][j * c[i] - k * c[i]] == 1) flag = false;           if (flag) ans = j;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   bool flag[21][21];   int deg[21], id[21];   vector<int> G[21];   inline int cmp(int x, int y) {     return deg[x] != deg[y] ? deg[x] < deg[y] : x < y;   }   bool vis[21];   inline void dfs(int np) {     vis[np] = 1;     for (int &x : G[np]) {       if (!vis[x]) {         dfs(x);         return;       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, ti, tj; i <= m; i++) {       scanf( %d%d , &ti, &tj);       if (ti != tj) flag[ti][tj] = flag[tj][ti] = 1;     }     for (int i = 1; i <= n; i++) {       id[i] = i;       for (int j = 1; j <= n; j++) {         if (flag[i][j]) deg[i]++, G[i].push_back(j);       }     }     for (int i = 1; i <= n; i++) sort(G[i].begin(), G[i].end(), cmp);     for (int i = 1; i <= n; i++) {       memset(vis, 0, sizeof(vis));       dfs(i);       int cnt = 0;       for (int j = 1; j <= n; j++) cnt += vis[j];       if (cnt == n) {         puts( Yes );         return 0;       }     }     puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300300;   int a[maxn];   set<int> st;   int MIN(int x, int y) { return x < y ? x : y; }   int MAX(int x, int y) { return x > y ? x : y; }   int main(void) {     st.clear();     int n, i, j, mi, mx, fg = 0, x;     scanf( %d , &n);     for (i = 1; i <= n - 1; i++) {       scanf( %d , &a[i]);       if (i == 1) {         mx = mi = a[i];       } else {         a[i] = a[i] + a[i - 1];         mx = MAX(mx, a[i]);         mi = MIN(mi, a[i]);       }       if (!st.count(a[i])) {         st.insert(a[i]);       } else         fg = 1;       if (a[i] == 0) fg = 1;     }     if (fg) {       printf( -1 n );       return 0;     }     for (i = 1; i <= n; i++)       if (i + mx >= 1 && i + mx <= n && i + mi >= 1 && i + mi <= n) {         fg = 1;         x = i;         break;       }     if (fg == 0) {       printf( -1 n );     } else {       printf( %d , x);       for (i = 1; i <= n - 1; i++) {         printf(  %d , x + a[i]);       }       printf(  n );     }     return 0;   }