malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p) {     if (p == 0) return 1;     long long my = bigmod(b, p / 2);     my *= my;     my %= 1000000009;     if (p & 1) my *= b, my %= 1000000009;     return my;   }   int setb(int n, int pos) { return n = n | (1 << pos); }   int resb(int n, int pos) { return n = n & ~(1 << pos); }   bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }   double p[100];   int n, k;   double pr[(1 << 20) + 5][21];   double prob(int mask, int pos) {     double tot = 0.0;     int i;     for (i = 0; i < n; i++) {       if (checkb(mask, i) == 0) tot += p[i];     }     return p[pos] / tot;   }   void prework() {     for (int mask = 0; mask < (1 << n); mask++) {       for (int i = 0; i < n; i++) {         if (checkb(mask, i) == 0) {           pr[mask][i] = prob(mask, i);         }       }     }   }   double dp[(1 << 20) + 5];   double motherfuckerareyoukiddingme(int x) {     for (int mask = (1 << n) - 1; mask >= 0; mask--) {       int bt = __builtin_popcount(mask);       if (bt >= k) {         if (bt == k && checkb(mask, x))           dp[mask] = 1.0;         else           dp[mask] = 0.0;       } else {         double ret = 0.0;         for (int i = 0; i < n; i++) {           if (checkb(mask, i) == 0) {             ret += pr[mask][i] * dp[setb(mask, i)];           }         }         dp[mask] = ret;       }     }     return dp[0];   }   int main() {     int i, d = 0;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %lf , &p[i]);     for (i = 0; i < n; i++)       if (p[i] > 0.0) d++;     k = min(d, k);     prework();     for (i = 0; i < n; i++) {       if (i) printf(   );       printf( %.10f , motherfuckerareyoukiddingme(i));     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, q = 0;     cin >> n >> m;     int k = n * m;     char a[k];     for (int j = 0; j < k; j++) {       cin >> a[k];       if (a[k] ==  M  || a[k] ==  Y  || a[k] ==  C ) {         q = 1;       }     }     if (q == 1) {       cout <<  #Color  << endl;     } else {       cout <<  #Black&White  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500000;   int n, m;   vector<int> nei[N + 1];   bool vis[N + 1];   int fa[N + 1], dep[N + 1];   void dfs(int x = 1) {     vis[x] = true;     for (int i = 0; i < nei[x].size(); i++) {       int y = nei[x][i];       if (vis[y]) continue;       fa[y] = x;       dep[y] = dep[x] + 1;       dfs(y);     }   }   vector<int> buc[N + 1];   void mian() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       nei[i].clear(), buc[i].clear(), vis[i] = fa[i] = dep[i] = 0;     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       nei[x].push_back(y);       nei[y].push_back(x);     }     dep[1] = 1;     dfs();     for (int i = 1; i <= n; i++)       if (dep[i] >= n + 1 >> 1) {         puts( PATH );         printf( %d n , dep[i]);         while (i) printf( %d  , i), i = fa[i];         puts(  );         return;       } else         buc[dep[i]].push_back(i);     puts( PAIRING );     int cnt = 0;     for (int i = 1; i <= n; i++) cnt += buc[i].size() >> 1;     printf( %d n , cnt);     for (int i = 1; i <= n; i++) {       for (int j = 0; j + 1 < buc[i].size(); j += 2)         printf( %d %d n , buc[i][j], buc[i][j + 1]);     }   }   int main() {     int testnum;     cin >> testnum;     while (testnum--) mian();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int in[100005];   int in2[100005];   int remlocate[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> in[i];     }     for (int i = 0; i < n; ++i) {       cin >> in2[i];       remlocate[in2[i]] = i;     }     int go1 = n - 1;     int go2 = n - 1;     int cnt = 0;     for (int i = 0; i < n; ++i) {       while (in2[go2] == 0) {         go2--;       }       if (in[go1] != in2[go2]) {         cnt++;         in2[remlocate[in[go1]]] = 0;         go1--;       } else {         go1--;         go2--;       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int MAXN = 1000005;   int dp[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     int x;     int maxn = 0;     for (int i = 0; i < n; i++) {       cin >> x;       dp[x]++;       maxn = max(maxn, dp[x]);       for (int j = x * 2; j < MAXN; j += x) {         dp[j] = max(dp[j], dp[x]);       }     }     cout << maxn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005];   long long b[100005];   long long x;   long long n, m;   long long c[100005];   long long d[100005];   void solve() {     cin >> n >> m;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (i) a[i] += a[i - 1];       c[i + 1] = 1e9;     }     for (long long i = 0; i < m; i++) {       cin >> b[i];       if (i) b[i] += b[i - 1];       d[i + 1] = 1e10;     }     cin >> x;     long long fans = 0;     for (long long i = 0; i < n; i++) {       for (long long j = i; j < n; j++) {         long long l = j - i + 1;         if (i)           c[l] = min(c[l], a[j] - a[i - 1]);         else           c[l] = min(c[l], a[j]);       }     }     for (long long i = 0; i < m; i++) {       for (long long j = i; j < m; j++) {         long long l = j - i + 1;         if (i)           d[l] = min(d[l], b[j] - b[i - 1]);         else           d[l] = min(d[l], b[j]);       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         if (c[i] * d[j] <= x) {           fans = max(fans, i * j);         }       }     }     cout << fans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long T;     T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1000000 + 9, MOD = 1000000000 + 7;   int f[N], n, a, b;   int main() {     scanf( %d , &n);     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       if (x == 1)         ++a;       else         ++b;     }     f[1] = 1;     f[0] = 1;     for (int i = 2; i <= a; ++i)       f[i] = (f[i - 1] + 1ll * f[i - 2] * (i - 1) % MOD) % MOD;     int ans = f[a];     for (int i = 1; i <= b; ++i) ans = 1ll * ans * (i + a) % MOD;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   vector<int> g[N], used, g1[N];   int gl[N];   bool ok = 1;   void dfs(int v, int glb) {     used[v] = 1;     gl[v] = glb;     for (int to : g[v])       if (!used[to]) dfs(to, glb + 1);   }   void dfs1(int v, int root) {     used[v] = 1;     for (int to : g1[v])       if (to == root)         ok = 0;       else if (!used[to])         dfs1(to, root);   }   int32_t main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     map<pair<int, int>, int> q;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       q[make_pair(a, b)] = i;       g[a].push_back(b);       g[b].push_back(a);       g1[a].push_back(b);     }     for (int i = 0; i < n; ++i) {       used.assign(n, 0);       dfs1(i, i);     }     used.assign(n, 0);     for (int i = 0; i < n; ++i)       if (!used[i]) dfs(i, 0);     if (ok) {       cout <<  1 n ;       for (int i = 0; i < m; ++i) cout <<  1  ;       return 0;     }     vector<int> res(m);     for (auto x : q) {       int a = x.first.first;       int b = x.first.second;       if (gl[a] > gl[b])         res[x.second] = 1;       else         res[x.second] = 2;     }     cout <<  2 n ;     for (int i = 0; i < m; ++i) cout << res[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, T, k, q;   const long long big = 1000000007;   const long long big2 = 998244353;   long long M[4][4] = {0};   vector<pair<int, int> > ANS;   bool inbounds(long long i, long long j) {     return i >= 0 && j >= 0 && i < 4 && j < 4;   }   void clearm() {     for (int c1 = 0; c1 < 4; c1++) {       long long ones = 0;       for (int c2 = 0; c2 < 4; c2++) {         ones += (M[c1][c2] == 1);       }       if (ones == 4) {         for (int c2 = 0; c2 < 4; c2++) {           M[c1][c2] = 2;         }       }     }     for (int c1 = 0; c1 < 4; c1++) {       long long ones = 0;       for (int c2 = 0; c2 < 4; c2++) {         ones += (M[c2][c1] != 0);       }       if (ones == 4) {         for (int c2 = 0; c2 < 4; c2++) {           M[c2][c1] = 2;         }       }     }     for (int c1 = 0; c1 < 4; c1++) {       for (int c2 = 0; c2 < 4; c2++) {         if (M[c1][c2] == 2) M[c1][c2] = 0;       }     }   }   void place(long long dx, long long dy) {     if (dx == 1) {       if (M[0][0] == 0) {         M[0][0] = 1;         M[1][0] = 1;         ANS.push_back({0, 0});         clearm();         return;       }       if (M[2][0] == 0) {         M[2][0] = 1;         M[3][0] = 1;         ANS.push_back({2, 0});         clearm();         return;       }     } else {       for (int c1 = 0; c1 < 4; c1++) {         if (M[c1][2] == 0) {           M[c1][2] = 1;           M[c1][3] = 1;           ANS.push_back({c1, 2});           clearm();           return;         }       }     }     for (int c1 = 0; c1 < 4; c1++) {       for (int c2 = 0; c2 < 4; c2++) {         if (M[c1][c2] == 0 && inbounds(c1 + dx, c2 + dy) &&             M[c1 + dx][c2 + dy] == 0) {           ANS.push_back({c1, c2});           M[c1][c2] = 1;           M[c1 + dx][c2 + dy] = 1;           clearm();           return;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long a, b, c, e;     string s;     cin >> s;     for (int c1 = 0; c1 < s.length(); c1++) {       if (s[c1] ==  0 ) {         place(1, 0);       } else {         place(0, 1);       }       cout << ANS[c1].first + 1 <<     << ANS[c1].second + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y;   bool f[1000010];   vector<int> v, b[1000010];   int ans = 0, res = 0;   int main(int argc, char **argv) {     scanf( %d , &n);     if (n == 1) {       puts( 1 );       return 0;     }     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       b[x].push_back(i);       if (!f[x]) {         f[x] = 1;         v.push_back(x);       }     }     for (int i = 0; i < (int)v.size(); ++i) {       for (int j = i; j < (int)v.size(); ++j) {         x = v[i];         y = v[j];         if (i == j) {           res = max(res, (int)b[x].size());           continue;         }         bool ok = 0;         int idx = -1;         ans = 0;         if (b[x][0] < b[y][0]) {           while (idx <= (int)b[x].back() || idx <= (int)b[y].back()) {             if (ok == 0) {               if (idx == -1) {                 ++ans;                 idx = b[x][0];               } else {                 int ii =                     lower_bound(b[x].begin(), b[x].end(), idx) - b[x].begin();                 if (ii < (int)b[x].size()) {                   ++ans;                   idx = b[x][ii];                 } else                   idx = 1e9;               }             } else {               if (idx == -1) {                 ++ans;                 idx = b[y][0];               } else {                 int ii =                     lower_bound(b[y].begin(), b[y].end(), idx) - b[y].begin();                 if (ii < (int)b[y].size()) {                   ++ans;                   idx = b[y][ii];                 } else                   idx = 1e9;               }             }             ok ^= 1;           }         } else {           swap(x, y);           while (idx <= (int)b[x].back() || idx <= (int)b[y].back()) {             if (ok == 0) {               if (idx == -1) {                 ++ans;                 idx = b[x][0];               } else {                 int ii =                     lower_bound(b[x].begin(), b[x].end(), idx) - b[x].begin();                 if (ii < (int)b[x].size()) {                   ++ans;                   idx = b[x][ii];                 } else                   idx = 1e9;               }             } else {               if (idx == -1) {                 ++ans;                 idx = b[y][0];               } else {                 int ii =                     lower_bound(b[y].begin(), b[y].end(), idx) - b[y].begin();                 if (ii < (int)b[y].size()) {                   ++ans;                   idx = b[y][ii];                 } else                   idx = 1e9;               }             }             ok ^= 1;           }         }         res = max(res, ans);       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 55;   const double eps = 1e-10;   pair<long long, long long> d[1000009];   long long f[1000009];   deque<pair<long long, long long> > dq;   long long dsum = 0;   int main() {     long long l, m;     scanf( %I64d %I64d , &l, &m);     int(n);     scanf( %d , &n);     d[0].first = 0;     d[0].second = 999999999;     for (int i = (1); i < (n + 1); ++i) {       scanf( %I64d %I64d , &d[i].first, &d[i].second);     }     sort(d, d + n + 1);     d[n + 1].first = l;     d[n + 1].second = 0;     n += 2;     long long ans = 0;     f[0] = m;     for (int i = (1); i < (n); ++i) {       f[i] = f[i - 1] - (d[i].first - d[i - 1].first);       while (f[i] < 0) {         if (((int)(dq).size()) == 0) {           ans = -1;           break;         }         long long buy = min(-f[i], dq[0].second);         dq[0].second -= buy;         ans += buy * dq[0].first;         dsum -= buy;         f[i] += buy;         if (dq[0].second == 0) dq.pop_front();       }       while (((int)(dq).size())) {         if (dq.back().first > d[i].second) {           dsum -= dq.back().second;           dq.pop_back();         } else           break;       }       if ((m - f[i] - dsum) > 0) {         dq.push_back(make_pair(d[i].second, m - f[i] - dsum));         dsum += m - f[i] - dsum;       }       if (ans == -1) break;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   bool judge(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   int main() {     int n;     scanf( %d , &n);     if (judge(n)) {       printf( 1 n );       return 0;     }     if (n % 2) {       if (judge(n - 2)) {         printf( 2 n );       } else {         printf( 3 n );       }       return 0;     } else {       printf( 2 n );       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[424242];   int main() {     long long n;     cin >> n;     int ans = 0;     if (n % 3 == 0) {       n /= 3;       int kp = 0;       for (int d = 1; d <= 50000; d++)         if ((4 * n) % d == 0) p[kp++] = d;       for (int a = 1; 8LL * a * a * a <= n; a++)         for (int id = 0; id < kp; id++) {           int b = p[id] - a;           if (b < a) continue;           if (2LL * b * (a + b) * (a + b) > n) continue;           long long d = (long long)(a + b) * (a + b) * (a - b) * (a - b) +                         4LL * (a + b) * n;           long long dd = sqrt(1.0 * d);           while (dd * dd < d) dd++;           while (dd * dd > d) dd--;           if (dd * dd == d) {             long long c = -a - b + dd / (a + b);             if (c < 2 * b || (c & 1)) continue;             c >>= 1;             if (a < b && b < c)               ans += 6;             else if (a == b && b == c)               ans += 1;             else               ans += 3;           }         }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int M = 11;   const int MOD = 1e9 + 7;   int n, m;   int dp[M][N][N];   int solve(int idx, int a, int b) {     if (idx >= m) return 1;     int& r = dp[idx][a][b];     if (r != -1) return r;     r = solve(idx + 1, a, b);     if (a < b) {       r = (r + solve(idx, a + 1, b)) % MOD;       r = (r + solve(idx, a, b - 1)) % MOD;     }     if (a + 1 < b) r = ((r - solve(idx, a + 1, b - 1)) % MOD + MOD) % MOD;     return r;   }   int main() {     cin >> n >> m;     memset(dp, -1, sizeof dp);     cout << solve(0, 1, n) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265358979323846264338;   const long long INF = 1000000000000000000;   const long long INF1 = 1000000000;   const long long MOD = 1000000007;   long long mpow(long long a, long long b) {     a %= MOD;     if (!b) return 1;     long long temp = mpow(a, b / 2);     temp = (temp * temp) % MOD;     if (b % 2) return (a * temp) % MOD;     return temp;   }   long long _pow(long long a, long long b) {     if (!b) return 1;     long long temp = _pow(a, b / 2);     temp = (temp * temp);     if (b % 2) return (a * temp);     return temp;   }   long long mod_in(long long n) { return mpow(n, MOD - 2); }   long long cl(long long a, long long b) {     if (a % b) return 1 + a / b;     return a / b;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     T = 1;     while (T--) {       long long n, k;       cin >> n >> k;       set<long long> s1, s2;       cout <<  ?  ;       for (int i = 1; i <= k; i++) cout << i <<    ;       cout <<   n ;       cout.flush();       long long pos, apos;       cin >> pos >> apos;       s1.insert(k + 1);       for (int i = 1; i <= k; i++) {         if (pos == i) continue;         cout <<  ?  ;         for (int j = 1; j <= k + 1; j++) {           if (i == j) continue;           cout << j <<    ;         }         cout <<   n ;         cout.flush();         long long x, y;         cin >> x >> y;         if (y == apos)           s1.insert(i);         else           s2.insert(i);       }       cout <<  ?  ;       for (long long x : s1) cout << x <<    ;       for (long long y : s2) cout << y <<    ;       cout <<   n ;       cout.flush();       long long u, v;       cin >> u >> v;       long long p1 = -1, p2 = -1, c[2] = {};       if (s1.count(u)) {         if (v > apos) {           p1 = 1;           p2 = 0;         } else {           p1 = 0;           p2 = 1;         }       } else {         if (v > apos) {           p1 = 0;           p2 = 1;         } else {           p1 = 1;           p2 = 0;         }       }       for (int i = 1; i <= k; i++) {         if (i == pos) continue;         if (s1.count(i))           c[p1]++;         else           c[p2]++;       }       cout <<  !   << c[0] + 1 <<   n ;       cout.flush();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5050;   const int inf = 0x3f3f3f3f;   int to[N * 2], nxt[N * 2], pre[N * 2], cnt, n, tot[N], dp[N][N][2];   void makeedge(int x, int y) {     to[cnt] = x;     nxt[cnt] = pre[y];     pre[y] = cnt++;     to[cnt] = y;     nxt[cnt] = pre[x];     pre[x] = cnt++;   }   int dfs(int x, int fa) {     int son = 0;     if (tot[x] == 1) {       son = 1;       dp[x][0][1] = 0;       dp[x][1][0] = 0;     } else {       dp[x][0][1] = 0;       dp[x][0][0] = 0;     }     for (int p = pre[x]; p != -1; p = nxt[p]) {       int y = to[p];       if (y == fa) continue;       int tmp = dfs(y, x);       for (int j = son; j >= 0; j--) {         for (int k = tmp; k >= 1; k--) {           dp[x][j + k][0] =               min(dp[x][j + k][0],                   min(dp[x][j][0] + dp[y][k][1] + 1, dp[x][j][0] + dp[y][k][0]));           dp[x][j + k][1] =               min(dp[x][j + k][1],                   min(dp[x][j][1] + dp[y][k][0] + 1, dp[x][j][1] + dp[y][k][1]));         }         dp[x][j][0] = min(inf, dp[x][j][0] + min(dp[y][0][1] + 1, dp[y][0][0]));         dp[x][j][1] = min(inf, dp[x][j][1] + min(dp[y][0][0] + 1, dp[y][0][1]));       }       son += tmp;     }     return son;   }   int main() {     scanf( %d , &n);     memset(pre, -1, sizeof(pre));     memset(dp, inf, sizeof(dp));     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       tot[x]++;       tot[y]++;       makeedge(x, y);     }     if (n == 2) {       printf( 1 n );       return 0;     }     int son = 0, S;     for (int i = 1; i <= n; i++) {       if (tot[i] != 1)         S = i;       else         son++;     }     dfs(S, 0);     printf( %d n , min(dp[S][son / 2][0], dp[S][son / 2][1]));   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[105];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, x, y, t, l, m, k = 0, r = 0, a, b, c, d, p = 0, q = 0, s, i,                                     j, ans = 0, ans1 = 0;     string s1;     char ch;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       q = a + b;       p = a - b;       s = c + d;       r = c - d;       x = p * n;       y = q * n;       if (x > s || y < r)         cout <<  No               <<   n ;       else         cout <<  Yes               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sci[200005], bn[200005];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int m, ple = 0, sat = 0, fi = 1, cn;       map<int, int> mp;       for (int i = 0; i < n; i++) {         scanf( %d , &sci[i]);         mp[sci[i]]++;       }       scanf( %d , &m);       for (int i = 1; i <= m; i++) {         scanf( %d , &bn[i]);       }       for (int i = 1; i <= m; i++) {         scanf( %d , &cn);         if (mp[bn[i]] > ple) {           ple = mp[bn[i]];           sat = mp[cn];           fi = i;         } else if (mp[bn[i]] == ple && mp[cn] > sat) {           sat = mp[cn];           fi = i;         }       }       printf( %d n , fi);     }   }