malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int main() {     int numDominoes;     char dominoes[3005];     int fallen = 0;     int count = 0;     int isL = 0;     int seenR = 0;     scanf( %d , &numDominoes);     for (int i = 0; i <= numDominoes; i++) {       scanf( %c , &dominoes[i]);     }     for (int i = 1; i <= numDominoes; i++) {       if (dominoes[i] ==  . ) {         count++;       } else if (dominoes[i] ==  R ) {         count = 0;         fallen++;         for (int j = i; j <= numDominoes; j++) {           if (dominoes[j] ==  L ) {             isL = 1;             break;           }         }         if (isL == 0) {           fallen += numDominoes - i;         }         isL = 0;         seenR = 1;       } else if (dominoes[i] ==  L ) {         fallen++;         if (count > 0 && seenR == 1) {           if (count % 2 == 0) {             fallen += count;           } else {             fallen += count - 1;           }         } else {           fallen += count;         }         count = 0;       }     }     printf( %d n , numDominoes - fallen);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int M[256 + 1];   int main() {     scanf( %d %d %d , &n, &a, &b);     if (a & 1) a++;     if (b & 1) b++;     int round = 1;     for (;;) {       a /= 2;       b /= 2;       if (a == b) break;       round++;       if (a & 1) a++;       if (b & 1) b++;     }     if (round == (int)log2(n))       printf( Final! n );     else       printf( %d n , round);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, diff, n_div;   int main() {     int i;     cin >> a >> b;     diff = a - b;     if (diff < 0) {       cout <<  0  << endl;     } else if (diff == 0) {       cout <<  infinity  << endl;       return 0;     } else {       for (i = 1; i * i <= diff; i++)         if (diff % i == 0) {           if (i > b) n_div++;           if (diff / i > b && diff / i != i) n_div++;         }       cout << n_div << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   vector<int> G[maxn];   int n, m, d[maxn], par[maxn], a[maxn], vis[maxn], flag = 1;   char s[1005][1005];   int find(int u) {     if (par[u] != u) par[u] = find(par[u]);     return par[u];   }   struct node {     int u, w;     node(int a, int b) { u = a, w = b; }   };   void topo() {     queue<node> q;     for (int i = 1; i <= n + m; i++) {       int fa = find(i);       if (!d[fa] && !vis[fa]) q.push(node(fa, 1)), vis[fa] = 1;     }     while (!q.empty()) {       node e = q.front();       q.pop();       int u = e.u;       a[u] = max(a[u], e.w);       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         a[v] = max(a[u] + 1, a[v]);         d[v]--;         if (d[v] == 0) q.push(node(v, a[v]));       }     }     for (int i = 1; i <= n + m; i++)       if (d[i]) puts( No ), exit(0);   }   void add(int i, int j) {     int fa = find(i), fb = find(j);     if (fa == fb) puts( No ), exit(0);     d[fa]++;     G[fb].push_back(fa);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n + m; i++) par[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);       for (int j = 1; j <= m; j++)         if (s[i][j] ==  = ) {           int fa = find(i), fb = find(j + n);           par[fa] = fb;         }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (s[i][j] ==  > )           add(i, n + j);         else if (s[i][j] ==  < )           add(n + j, i);     topo();     puts( Yes );     for (int i = 1; i < n; i++) printf( %d  , a[find(i)]);     printf( %d n , a[find(n)]);     for (int i = 1; i < m; i++) printf( %d  , a[find(i + n)]);     printf( %d n , a[find(n + m)]);   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const double eps = 1e-8;   const int maxn = 1e6 + 5;   const int INF = 1e9;   const int maxnode = 7e6 + 5;   const int sigma_size = 2;   void tran2(int num, int s[]) {     for (int i = 0; i < 31; i++) {       s[i] = (num >> (30 - i)) & 1;     }   }   struct Trie {     int ch[maxnode][sigma_size];     int val[maxnode], able[maxnode];     int sz;     void init() {       sz = 1;       memset(ch, 0, sizeof(ch));       memset(val, 0, sizeof(val));       memset(able, 0, sizeof(able));     }     int idx(int c) { return c; }     void insert(int *s) {       int u = 0, n = 31;       for (int i = 0; i < n; i++) {         able[u]++;         int c = idx(s[i]);         if (!ch[u][c]) {           val[sz] = 0;           ch[u][c] = sz++;         }         u = ch[u][c];       }       able[u]++;       val[u]++;     }     void del(int *s) {       int u = 0, n = 31;       for (int i = 0; i < n; i++) {         able[u]--;         int c = idx(s[i]);         u = ch[u][c];       }       able[u]--;       val[u]--;     }     int find_min(int *s) {       int u = 0, i = 1, num = 0;       int k = 0;       int r = 0;       for (k = 0; k < 31; k++) {         int y = idx(s[k]);         int x = y ^ 1;         able[u]--;         if (ch[u][y] && able[ch[u][y]] > 0) {           u = ch[u][y];         } else {           r += 1 << (30 - k);           u = ch[u][x];         }       }       able[u]--;       val[u]--;       return r;     }   } trie;   int a[maxn], p[maxn], n, s[maxn];   int main(void) {     scanf( %d , &n);     trie.init();     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       tran2(p[i], s);       trie.insert(s);     }     int tmp;     for (int i = 0; i < n; i++) {       tran2(a[i], s);       tmp = trie.find_min(s);       printf( %d  , tmp);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4 * 100000 + 10;   char ss[MAXN];   int main() {     scanf( %s , ss);     int cis;     int len = strlen(ss);     int l = len;     for (int i = 0; i < len; i++) {       ss[i + len] = ss[i];     }     len = strlen(ss);     int ans = 1;     int maxx = 1;     for (int i = 1; i < len; i++) {       if (ss[i] != ss[i - 1]) {         maxx++;         int dadasdsadadsadada;         ans = max(ans, maxx);       } else {         int sdd;         maxx = 1;       }     }     ans = min(ans, l);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ptr;   bool mark[100010];   bool bad[100010];   int ord[100010];   vector<int> dir[100010];   vector<int> rev[100010];   vector<int> adj[100010];   bool dfs(int idx) {     bool ret = bad[idx];     mark[idx] = true;     for (int i = 0; i < adj[idx].size(); i++)       if (!mark[adj[idx][i]]) ret |= dfs(adj[idx][i]);     return ret;   }   void setOrd(int idx) {     mark[idx] = true;     for (int i = 0; i < dir[idx].size(); i++)       if (!mark[dir[idx][i]]) setOrd(dir[idx][i]);     ord[--ptr] = idx;   }   int ccf(int idx) {     int cnt = 1;     mark[idx] = true;     for (int i = 0; i < rev[idx].size(); i++)       if (!mark[rev[idx][i]]) cnt += ccf(rev[idx][i]);     return cnt;   }   int main() {     cin >> n >> m;     ptr = n;     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--, b--;       dir[a].push_back(b);       rev[b].push_back(a);       adj[a].push_back(b);       adj[b].push_back(a);     }     int res = n;     for (int i = 0; i < n; i++)       if (!mark[i]) setOrd(i);     memset(mark, false, sizeof mark);     for (int i = 0; i < n; i++) {       if (!mark[ord[i]]) {         int tmp = ccf(ord[i]);         if (tmp > 1) bad[ord[i]] = true;       }     }     memset(mark, false, sizeof mark);     for (int i = 0; i < n; i++)       if (!mark[i] && !dfs(i)) res--;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static int io_sync_off = []() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     return 0;   }();   long long Pow(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) (res *= a) %= mod;       (a *= a) %= mod;       b >>= 1;     }     return res % mod;   }   long long inv(long long a, long long p) {     if (a == 1) return 1;     return (p - p / a) * inv(p % a, p) % p;   }   long long C(long long n, long long m, long long p) {     long long res = 1;     for (long long i = 1, j = n - m + 1; i <= m; ++i, ++j) {       res = res * inv(i, p) % p * j % p;     }     return res;   }   const int N = 2e5 + 10;   struct M {     bool operator<(const M &t) const { return x < t.x; }     int x, y, z;   };   long long Max[N * 4], tag[N * 4];   void push_down(int o) {     int lc = 2 * o, rc = 2 * o + 1;     tag[lc] += tag[o];     tag[rc] += tag[o];     Max[lc] += tag[o];     Max[rc] += tag[o];     tag[o] = 0;   }   void update(int a, int b, int v, int o, int l, int r) {     if (a == b) return;     if (a <= l && b >= r) {       tag[o] += v;       Max[o] += v;       return;     }     push_down(o);     int mid = (l + r) >> 1, lc = 2 * o, rc = 2 * o + 1;     if (a < mid) update(a, b, v, lc, l, mid);     if (b > mid) update(a, b, v, rc, mid, r);     Max[o] = max(Max[lc], Max[rc]);   }   M Mon[N];   pair<long long, long long> a[N], b[N];   int d[N];   void build(int o, int l, int r) {     if (r - l == 1) {       Max[o] = -b[l].second;       return;     }     int mid = (l + r) >> 1, lc = 2 * o, rc = 2 * o + 1;     build(lc, l, mid);     build(rc, mid, r);     Max[o] = max(Max[lc], Max[rc]);   }   int main() {     int n, m, p;     scanf( %d%d , &n, &m);     scanf( %d , &p);     for (int i = 0; i < n; ++i) scanf( %d%d , &a[i].first, &a[i].second);     for (int i = 0; i < m; ++i) scanf( %d%d , &b[i].first, &b[i].second);     for (int i = 0; i < p; ++i) scanf( %d%d%d , &Mon[i].x, &Mon[i].y, &Mon[i].z);     sort(a, a + n);     sort(b, b + m);     sort(Mon, Mon + p);     for (int i = 0; i < m; ++i) d[i] = b[i].first;     build(1, 0, m);     long long ans = -1e18;     int j = 0;     for (int i = 0; i < n; ++i) {       while (j < p && Mon[j].x < a[i].first) {         int l = upper_bound(d, d + m, Mon[j].y) - d;         update(l, m, Mon[j++].z, 1, 0, m);       }       ans = max(ans, Max[1] - a[i].second);     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int b, k;     cin >> b >> k;     int ans = 0;     for (int i = 1; i <= k; i++) {       int x;       cin >> x;       if (i != k)         ans = (ans + b * x % 2) % 2;       else         ans = (ans + x % 2) % 2;     }     if (ans % 2 == 0) {       cout <<  even ;     } else       cout <<  odd ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int n, m;   map<string, int> h;   string name[N], str[N], re[N];   bool f[N][N];   int g[N][N];   void print(int x, int y) {     if (x == 0) {       return;     }     print(x - 1, g[x][y]);     cout << name[y] << re[x - 1] << endl;   }   void work() {     scanf( %d , &n);     h.clear();     for (int i = 0; i < n; ++i) {       cin >> name[i];       h[name[i]] = i;     }     scanf( %d n , &m);     memset(f, 0, sizeof(f));     memset(g, 0, sizeof(g));     f[0][n] = 1;     for (int i = 0; i < m; ++i) {       getline(cin, str[i]);       re[i].clear();     }     for (int i = 0; i < m; ++i) {       string usr, buf = str[i];       int p = 0;       while (p < buf.size() && buf[p] !=  : ) {         usr += buf[p++];       }       int q = p;       while (q < buf.size()) {         re[i] += buf[q++];       }       set<int> mention;       while (p < buf.size()) {         string word;         while (p < buf.size() && isalnum(buf[p])) {           word += buf[p++];         }         if (h.count(word)) {           mention.insert(h[word]);         }         if (p < buf.size()) ++p;       }       if (usr ==  ? ) {         for (int j = 0; j <= n; ++j) {           if (!f[i][j]) continue;           for (int k = 0; k < n; ++k) {             if (mention.count(k) || k == j) continue;             f[i + 1][k] = 1;             g[i + 1][k] = j;           }         }       } else {         if (!h.count(usr)) {           puts( Impossible );           return;         }         int id = h[usr];         if (!mention.count(id)) {           for (int j = 0; j <= n; ++j) {             if (f[i][j] && id != j) {               f[i + 1][id] = 1;               g[i + 1][id] = j;             }           }         }       }     }     int x = -1;     for (int i = 0; i < n; ++i) {       if (f[m][i]) {         x = i;       }     }     if (x == -1) {       puts( Impossible );     } else {       print(m, x);     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       work();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int l, b, M, N;     cin >> M;     cin >> N;     l = std::max(M, N);     b = std::min(M, N);     if (b >= 2) {       cout << (b * (l / 2) + (b / 2) * (l % 2));     } else       cout << (b * (l / 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int xa[300005] = {0};     for (int i = 1; i <= 300000; i++) {       xa[i] = (xa[i - 1] ^ i);     }     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       long long x = xa[a - 1];       if (x == b) {         cout << a << endl;       } else {         if ((x ^ b) == a) {           cout << a + 2 << endl;         } else {           cout << a + 1 << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x[101];   double e[2][101 * 1001], sume[101 * 1001];   int main(int argc, const char* argv[]) {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , x + i);     if (m == 1) {       puts( 1.00 );       return 0;     }     int cur = 0, pre = 1;     e[pre][0] = m - 1;     for (int i = 0; i < n; i++) {       cur = i % 2;       pre = 1 - cur;       sume[0] = e[pre][0];       for (int j = 1; j <= (i + 1) * m; j++) sume[j] = sume[j - 1] + e[pre][j];       for (int s = 0; s <= (i + 1) * m; s++) {         int l, r;         if (s >= 1) {           l = max(s - m, 0), r = s - 1;           if (l - 1 >= 0)             e[cur][s] = sume[r] - sume[l - 1];           else             e[cur][s] = sume[r];           if (l <= s - x[i] && s - x[i] <= r) e[cur][s] -= e[pre][s - x[i]];           e[cur][s] /= (double)(m - 1.0);         } else           e[cur][s] = 0;       }     }     int sum = 0;     double ans = 0;     for (int i = 0; i < n; i++) sum += x[i];     for (int i = 0; i < sum; i++) ans += e[cur][i];     printf( %.9lf n , ans + 1.0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, tp, f, g, h, p[100], pi, q[100], qi, pas;   map<pair<long long, long long>, long long> m;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a;     for (b = 1; b <= a; b++) {       cin >> tp;       if (tp == 1) {         cin >> c >> d >> e;         pi = 0;         while (c > 0) {           pi++;           p[pi] = c % 2;           c /= 2;         }         c = d;         for (d = 1; d <= pi / 2; d++) {           swap(p[d], p[pi - d + 1]);         }         d = c;         qi = 0;         while (d > 0) {           qi++;           q[qi] = d % 2;           d /= 2;         }         for (d = 1; d <= qi / 2; d++) {           swap(q[d], q[qi - d + 1]);         }         c = 0;         f = 0;         for (d = 1; d <= min(pi, qi); d++) {           if (p[d] == q[d]) {             g = c;             if (p[d] == 0)               c = c * 2;             else               c = c * 2 + 1;           } else {             break;           }         }         f = d;         h = c;         for (d = f; d <= pi; d++) {           g = c;           if (p[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           m[make_pair(g, c)] += e;         }         c = h;         for (d = f; d <= qi; d++) {           g = c;           if (q[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           m[make_pair(g, c)] += e;         }       } else {         cin >> c >> d;         pas = 0;         pi = 0;         while (c > 0) {           pi++;           p[pi] = c % 2;           c /= 2;         }         c = d;         for (d = 1; d <= pi / 2; d++) {           swap(p[d], p[pi - d + 1]);         }         d = c;         qi = 0;         while (d > 0) {           qi++;           q[qi] = d % 2;           d /= 2;         }         for (d = 1; d <= qi / 2; d++) {           swap(q[d], q[qi - d + 1]);         }         c = 0;         f = 0;         for (d = 1; d <= min(pi, qi); d++) {           if (p[d] == q[d]) {             g = c;             if (p[d] == 0)               c = c * 2;             else               c = c * 2 + 1;           } else {             break;           }         }         f = d;         h = c;         for (d = f; d <= pi; d++) {           g = c;           if (p[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           pas = pas + m[make_pair(g, c)];         }         c = h;         for (d = f; d <= qi; d++) {           g = c;           if (q[d] == 0)             c = c * 2;           else             c = c * 2 + 1;           pas = pas + m[make_pair(g, c)];         }         cout << pas << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   int n;   int tmp[N];   int a[N], val[N], sta[N];   int dpl[N], dpr[N];   void init(int n, int *dp) {     int top = 0;     int mx = 0;     for (int i = 1; i <= n; i++) {       int ma = 0;       while (top && a[sta[top]] > a[i]) {         ma = max(ma, val[top]);         top--;       }       sta[++top] = i;       if (ma == 0)         val[top] = top;       else         val[top] = ma + 1;       mx = max(mx, val[top]);       dp[i] = mx;     }   }   int main() {     scanf( %d , &n);     if (n == 1) {       printf( %d %d n , 1, 0);       return 0;     }     int mi = 1e9, rt;     for (int i = 1; i <= n; i++) {       scanf( %d , &tmp[i]);       if (tmp[i] < mi) mi = tmp[i], rt = i;     }     for (int i = 1, j = rt - 1; i < n; i++, j--) {       if (j < 1) j += n;       a[i] = tmp[j];     }     init(n - 1, dpl);     for (int i = 1, j = rt + 1; i < n; i++, j++) {       if (j > n) j -= n;       a[i] = tmp[j];     }     init(n - 1, dpr);     int ans = 1e9, shft;     for (int i = 0; i < n; i++) {       if (ans > max(dpl[i], dpr[n - 1 - i]) + 1) {         ans = max(dpl[i], dpr[n - 1 - i]) + 1;         shft = rt - (i + 1);       }     }     if (shft < 0) shft += n;     printf( %d %d n , ans, shft);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   char s[maxn];   int tp[maxn >> 3], sz[maxn >> 3], n, cnt;   long long ans;   int main() {     scanf( %d , &n);     int l;     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       l = strlen(s + 1);       for (int k = 1; k <= l; k++) tp[i] ^= (1 << (int)(s[k] -  a ));     }     sort(tp + 1, tp + 1 + n);     cnt = 1;     for (int i = 1; i <= n; i++) {       if (tp[i] != tp[cnt]) tp[++cnt] = tp[i];       ++sz[cnt];     }     for (int i = 1; i <= cnt; i++) {       ans += 1LL * (sz[i] - 1) * sz[i] >> 1;       for (int k = 0; k <= 25; k++)         if (!((1 << k) & tp[i])) {           int c = tp[i] | (1 << k);           int p = lower_bound(tp + 1, tp + 1 + cnt, c) - tp;           if (tp[p] != c) continue;           ans += 1LL * sz[i] * sz[p];         }     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct comp1 {     bool operator()(const long long &a, const long long &b) { return (a > b); }   };   typedef struct node {     long long num;     vector<node *> des;   } node;   int n;   long long arr[8];   int best;   node *root;   vector<node *> imp;   bool prime[1000000 + 1];   set<long long> primes;   int breakInto(long long num) {     if (num == 0) return 0;     int cnt = 0;     for (set<long long>::iterator i = primes.begin(); i != primes.end(); i++) {       while (num % (*i) == 0) {         cnt++;         num /= (*i);       }       if (num == 1) break;     }     return cnt;   }   int count(node *curr) {     int cnt = 0;     if (curr->des.size() == 0) {       int ret = breakInto(curr->num);       if (ret == 1)         return 1;       else         return ret + 1;     }     cnt = 1 + breakInto(curr->num);     for (int i = 0; i < curr->des.size(); i++) cnt += count(curr->des[i]);     return cnt;   }   void print(node *curr) {     cout << curr->num <<  : ;     for (int i = 0; i < curr->des.size(); i++) print(curr->des[i]);   }   void recurse(int i) {     if (i == 0) {       root = new node();       root->num = arr[0];       imp.push_back(root);       recurse(i + 1);       root->num = 0;       node *nnode = new node();       nnode->num = arr[0];       root->des.push_back(nnode);       imp.push_back(nnode);       recurse(i + 1);       return;     }     if (i == n) {       best = min(best, count(root));       return;     }     for (int j = 0; j < imp.size(); j++) {       long long nnum = imp[j]->num;       if (nnum % arr[i] == 0) {         node *nnode = new node();         nnode->num = arr[i];         imp[j]->des.push_back(nnode);         imp.push_back(nnode);         imp[j]->num /= arr[i];         recurse(i + 1);         imp[j]->num *= arr[i];         imp[j]->des.pop_back();         imp.pop_back();       }     }   }   void precompute(void) {     for (int i = 0; i <= 1000000; i++) prime[i] = 1;     prime[0] = prime[1] = 0;     for (int i = 2; i * i <= 1000000; i++) {       for (int j = i * i; j <= 1000000; j += i) prime[j] = 0;     }   }   int main() {     best = 1000;     root = NULL;     precompute();     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &arr[i]);     sort(arr, arr + n, comp1());     for (int i = 0; i < n; i++) {       long long num = arr[i];       for (long long j = 2; j * j <= num; j++) {         if (prime[j]) {           while (num % j == 0) {             primes.insert(j);             num /= j;           }         }         if (num == 1) break;       }       if (num > 1) primes.insert(num);     }     recurse(0);     printf( %d n , best);     return 0;   }