malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 522133279;   const int MAXN = 100000;   const int TOTN = 100 + 100;   const long long MOD = 1000000007;   bool _su[MAXN];   vector<int> su;   vector<int> suc;   int n, k;   void shai() {     memset((_su), true, sizeof(_su));     for (int i = (2); i < (MAXN); i++) {       if (k <= 1) break;       if (_su[i] && k % i == 0) {         su.push_back(i);         suc.push_back(0);         while (k && k % i == 0) {           k /= i;           suc.back()++;         }         for (int j = 2; j * i < MAXN; j++) _su[j * i] = false;       }     }     if (k != 1) {       su.push_back(k);       suc.push_back(1);     }   }   vector<int> fen(int x) {     vector<int> cnt;     cnt.resize(su.size());     for (int i = (0); i < (su.size()); i++) {       while (x && x % su[i] == 0) {         x /= su[i];         cnt[i]++;       }     }     return cnt;   }   vector<vector<int> > lis;   bool divisible(vector<int> cnt) {     bool ok = true;     for (int i = (0); i < (cnt.size()); i++) {       if (cnt[i] < suc[i]) {         ok = false;         break;       }     }     return ok;   }   vector<int> getCnt(int l, int r) {     if (l == 0) return lis[r];     vector<int> res;     for (int i = (0); i < (lis[l].size()); i++) {       res.push_back(lis[r][i] - lis[l - 1][i]);     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     shai();     for (int i = (0); i < (n); i++) {       int a;       cin >> a;       lis.push_back(fen(a));     }     for (int i = (1); i < (n); i++) {       for (int j = (0); j < (lis[i].size()); j++) {         lis[i][j] += lis[i - 1][j];       }     }     int l = 0, r = 0;     long long ans = 0;     while (r < n) {       while (r < n && !divisible(getCnt(l, r))) r++;       if (r >= n) break;       ans += n - r;       l++;       if (l > r) r = l;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[100000];   int h[100000];   int queries[100000][3];   vector<pair<int, int> > type3[100000];   vector<int> adj[100000];   int visited[100000];   vector<int> who;   int top[100000];   int ok[100000];   vector<pair<int, int> > need[100000];   int which[100000];   int findSet(int x) {     if (p[x] == x) return x;     return p[x] = findSet(p[x]);   }   void mergeSet(int x, int y) {     int r1 = findSet(x);     int r2 = findSet(y);     if (h[r1] > h[r2])       p[r2] = r1;     else if (h[r2] > h[r1])       p[r1] = r2;     else {       p[r1] = r2;       h[r2] += 1;     }   }   bool sameSet(int x, int y) { return findSet(x) == findSet(y); }   void dfs(int x) {     visited[x] = 1;     for (int i = 0; i < type3[x].size(); i++)       if (visited[type3[x][i].first] == 1) ok[type3[x][i].second] = 1;     for (int i = 0; i < adj[x].size(); i++)       if (!visited[adj[x][i]]) dfs(adj[x][i]);     visited[x] = 2;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       top[i] = 1;       p[i] = i;     }     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &queries[i][0], &a);       if (queries[i][0] != 2) scanf( %d , &b);       queries[i][1] = a - 1;       queries[i][2] = b - 1;       if (queries[i][0] == 1) {         adj[b - 1].push_back(a - 1);         top[a - 1] = 0;       }       if (queries[i][0] == 2) {         who.push_back(a - 1);         which[who.size() - 1] = i;       }       if (queries[i][0] == 3) {         type3[who[b - 1]].push_back(make_pair(a - 1, i));         need[which[b - 1]].push_back(make_pair(a - 1, i));       }     }     for (int i = 0; i < n; i++)       if (top[i]) dfs(i);     for (int i = 0; i < m; i++) {       if (queries[i][0] == 1) mergeSet(queries[i][1], queries[i][2]);       if (queries[i][0] == 2)         for (int j = 0; j < need[i].size(); j++)           if (!sameSet(queries[i][1], need[i][j].first))             ok[need[i][j].second] = 0;       if (queries[i][0] == 3) {         if (ok[i])           printf( YES n );         else           printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int st[1000010];   int mod = 1000000007;   vector<vector<int> > g;   int dp[1000010][2];   int n, m, k;   int a[1000010];   int main() {     st[0] = 1;     for (int i = (1); i < (1000010); ++i) {       st[i] = st[i - 1] + st[i - 1];       if (st[i] >= mod) st[i] -= mod;     }     scanf( %d%d%d , &n, &m, &k);     int max1 = -1;     int min1 = 2000000000;     int tot = 0;     for (int i = (0); i < (m); ++i) {       int v1, v2;       scanf( %d%d , &v1, &v2);       v1--;       v2--;       if (((v2 - v1) != 1) && (v2 - v1 != k + 1)) {         cout << 0 << endl;         return 0;       }       if (v2 - v1 == k + 1) {         a[v1] = 1;         max1 = v1;         min1 = ((min1 < v1) ? (min1) : (v1));         tot++;       }     }     if (max1 - min1 > k) {       cout << 0 << endl;       return 0;     }     for (int i = (1); i < (n); ++i) a[i] += a[i - 1];     int res = 1;     for (int i = (0); i < (n); ++i) {       int v = i + k + 1;       if (v >= n) break;       if (i + k + 1 <= max1) continue;       if (i > min1) break;       int last = min(i + k, n - k - 2);       int sum = a[last] - a[i];       int c = a[i];       if (i) c -= a[i - 1];       if (c) res--;       if (res < 0) res += mod;       res += st[last - i - sum];       if (res >= mod) res -= mod;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     string c;     cin >> n >> c;     s = n;     string r =   ;     while (n > 0) {       if (n % 2 == 0) {         string y =   ;         y += c[s - n];         y += r;         r = y;       } else {         r += c[s - n];       }       n--;     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int M, N, maxH[100009], d[100009];   void dfs(int nod) {     if (nod >= (1 << N)) {       maxH[nod] = 0;       return;     }     int f1 = nod << 1, f2 = f1 | 1;     dfs(f1), dfs(f2);     maxH[nod] = max(maxH[f1] + d[f1], maxH[f2] + d[f2]);   }   int ans = 0;   void solve(int nod) {     if (nod >= (1 << N)) return;     int f1 = nod << 1, f2 = f1 | 1;     if (maxH[f1] + d[f1] < maxH[f2] + d[f2]) swap(f1, f2);     solve(f1);     ans += maxH[nod] - (maxH[f2] + d[f2]);     solve(f2);   }   int main() {     scanf( %d , &N), M = (1 << (N + 1)) - 1;     for (int i = 2; i <= M; i++) scanf( %d , &d[i]);     dfs(1);     solve(1);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int L, f, b;   int n;   int pos[110];   map<int, int> lot;   int findpos(int L) {     map<int, int>::iterator cur, next;     cur = lot.begin(), next = cur;     next++;     for (; next != lot.end(); cur++, next++) {       int back = cur->first + cur->second, front = next->first;       if (back + b + L + f <= front) return back + b;     }     return -1;   }   int main() {     scanf( %d%d%d , &L, &b, &f);     scanf( %d , &n);     lot.clear();     lot.insert(make_pair(-b, 0));     lot.insert(make_pair(L + f, 0));     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (a == 1) {         int pl = findpos(b);         pos[i + 1] = pl;         if (pl >= 0) lot.insert(make_pair(pl, b));         printf( %d n , pl);       } else {         if (pos[b] < 0) continue;         lot.erase(pos[b]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   string B, N;   long long b, pw[10], C;   int main() {     ios::sync_with_stdio(false);     cin >> B >> N >> C;     int it = N.size();     for (int i = N.size() - 1; i >= 0; i--) {       N[i]--;       if (N[i] <  0 )         N[i] =  9 ;       else         break;     }     b = 0;     for (int i = 0; i < B.size(); i++) b = (b * 10 + B[i] -  0 ) % C;     pw[0] = 1;     for (int i = 1; i < 10; i++) pw[i] = pw[i - 1] * b % C;     long long ans = 1;     for (int i = 0; i < N.size(); i++) {       ans = ans * ans % C;       long long tmp = ans;       ans = ans * ans % C;       ans = ans * ans % C;       ans = ans * tmp % C;       ans = ans * pw[N[i] -  0 ] % C;     }     ans = ans * (b - 1 + C) % C;     if (ans == 0)       cout << C << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, cnt = 1;     cin >> a >> b;     int d = a;     bool flag = true;     while (d >= cnt) {       if (flag) {         a -= cnt;         flag = false;         d = b;       } else {         b -= cnt;         flag = true;         d = a;       }       ++cnt;     }     if (a < cnt && flag)       cout <<  Vladik             <<   n ;     else       cout <<  Valera             <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long tripleIndx = n / 3;       if (!(n % 3)) tripleIndx--;       stack<long long> st;       while (tripleIndx--) {         st.push(tripleIndx % 4ll);         tripleIndx /= 4;       }       long long curA = 1;       long long curB = 2;       long long curC = 3;       long long a[4] = {0, 1, 2, 3};       long long b[4] = {0, 2, 3, 1};       long long c[4] = {0, 3, 1, 2};       while (!st.empty()) {         long long mod = st.top();         st.pop();         curA *= 4;         curA += a[mod];         curB *= 4;         curB += b[mod];         curC *= 4;         curC += c[mod];       }       if (n % 3 == 1) {         cout << curA <<   n ;       } else if (n % 3 == 2) {         cout << curB <<   n ;       } else {         cout << curC <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int a[maxn];   int main() {     int n;     while (cin >> n) {       int ans = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i]) ans++;       }       for (int i = 1; i <= n; i++) {         if (a[i] == 1) {           if (i == 1) continue;           if (a[i - 1] && i >= 1) continue;           if (i >= 2 && a[i - 2]) {             ans++;             continue;           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     for (long long(i) = (0); (i) < (n); (i)++) cin >> a[i];     int tmp = n + 1;     int ans = 0;     for (int i = n; i >= 1; --i) {       if (i < tmp) ans++;       tmp = min(tmp, i - a[i - 1]);     }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int cumsum[200005];   int a[200005];   int main()   {    int t;    scanf( %d ,&t);    while(t--)    {     int n;     scanf( %d ,&n);     for(int i=0;i<n;i++)     {      scanf( %d ,&a[i]);     }     for(int i=0;i<n;i++)     {      cumsum[i] = 0;     }        for(int i=0;i<n;i++)     {      if(a[i] == 0)       continue;      cumsum[i+1]--;      cumsum[max(0,i-a[i] + 1)]++;     }        for(int i=0;i<n;i++)     {      if(i != 0)       cumsum[i]+=cumsum[i-1];      if(cumsum[i] == 0)      {       printf( 0  );      }      else      {        printf( 1  );      }     }     printf(  n );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<long long, vector<long long>, greater<long long> > q;   int main() {     long long n;     while (cin >> n) {       long long e = 0, o = 0;       for (long long i = 1; i <= n; i++) {         long long x;         cin >> x;         if (x % 2)           o++;         else           e++;       }       long long xx = min(e, o);       cout << xx + (o - xx) / 3 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> S;   vector<int> ack;   int pop[1100100];   int kol[1100100];   int k[1234];   char c[1234];   const int INF = 1000000000;   int parse(int a) {     if (a == INF) return -INF;     return a;   }   int main() {     int n, m;     scanf( %d , &n);     for (int i = (0); i <= (int(n) - 1); ++i) {       int s;       scanf( %d , &s);       S.push_back(s);     }     sort(S.begin(), S.end());     scanf( %d , &m);     for (int i = (0); i <= (int(m) - 1); ++i) {       ack.push_back(S.back());       S.pop_back();     }     for (int i = (0); i <= (int(m) - 1); ++i) {       scanf(  %c%d , &c[i], &k[i]);     }     for (int q = m - 1; q >= 0; q--) {       for (int i = (0); i <= (int(1 << m) - 1); ++i) pop[i] = kol[i];       int mn = 1;       if (k[q] == 2) mn *= -1;       for (int i = (0); i <= (int(1 << m) - 1); ++i) {         kol[i] = -INF;         for (int j = (0); j <= (int(m) - 1); ++j)           if ((i & (1 << j)) != 0) {             int x = ack[j];             if (c[q] ==  b ) x = 0;             kol[i] =                 mn * max(mn * (pop[i ^ (1 << j)] + mn * x), parse(kol[i] * mn));           }       }     }     printf( %d n , kol[(1 << m) - 1]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0;     int n, a = 0, b;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> b;       a += b;     }     int m, c, d;     cin >> m;     for (int i = 0; i < m; i++) {       cin >> c >> d;       if (ans == 0) {         if (a >= c && a <= d) ans = a;         if (c > a) ans = c;       }     }     if (ans != 0)       cout << ans;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 20000;   struct node {     int flow;     int ff[5];     int ru;   } mat[maxn];   int n, m;   int kk[500];   int now;   int getup(int id) {     int ret = -1;     int k = id - m;     while (k >= 1) {       if (mat[k].flow != -1) {         ret = k;         break;       }       k -= m;     }     return ret;   }   int getright(int id) {     int ret = -1;     int k = id;     while (k % m != 0) {       k = k + 1;       if (mat[k].flow != -1) {         ret = k;         break;       }     }     return ret;   }   int getdown(int id) {     int ret = -1;     int k = id + m;     while (k <= n * m) {       if (mat[k].flow != -1) {         ret = k;         break;       }       k += m;     }     return ret;   }   int getleft(int id) {     int ret = -1;     int k = id;     while (k % m != 1) {       k--;       if (mat[k].flow != -1) {         ret = k;         break;       }     }     return ret;   }   int fl[maxn][5];   int ans;   int cnt;   int solve(int id) {     int ret = 0;     int k = id;     int ne;     int u, d, r, l;     while (k != -1) {       ret++;       ne = mat[k].ff[mat[k].flow];       u = mat[k].ff[1];       d = mat[k].ff[3];       r = mat[k].ff[2];       l = mat[k].ff[4];       if (u != -1) {         mat[u].ff[3] = d;       }       if (d != -1) {         mat[d].ff[1] = u;       }       if (r != -1) {         mat[r].ff[4] = l;       }       if (l != -1) {         mat[l].ff[2] = r;       }       k = ne;     }     return ret;   }   int main() {     kk[ U ] = 1;     kk[ R ] = 2;     kk[ D ] = 3;     kk[ L ] = 4;     kk[ . ] = -1;     now = 0;     cin >> n >> m;     string s;     for (int i = 1; i <= n; i++) {       cin >> s;       for (int j = 0; j < m; j++) {         mat[++now].flow = kk[s[j]];       }     }     for (int i = 1; i <= now; i++) {       if (mat[i].flow == -1) continue;       if (n != 1) fl[i][1] = getup(i);       if (m != 1) fl[i][2] = getright(i);       if (n != 1) fl[i][3] = getdown(i);       if (m != 1) fl[i][4] = getleft(i);       if (m == 1) {         fl[i][2] = fl[i][4] = -1;       }       if (n == 1) {         fl[i][1] = fl[i][3] = -1;       }     }     for (int i = 1; i <= now; i++) {       int ne = fl[i][mat[i].flow];       if (ne != -1) {         int nne = fl[ne][mat[ne].flow];         if (nne != i)           ;         mat[ne].ru = 1;       }     }     ans = 0;     for (int i = 1; i <= now; i++) {       if (mat[i].flow == -1) continue;       for (int i1 = 1; i1 <= now; i1++) {         for (int j = 1; j <= 4; j++) {           mat[i1].ff[j] = fl[i1][j];         }       }       int z = solve(i);       if (z > ans) {         ans = z;         cnt = 1;       } else if (z == ans) {         cnt++;       }     }     cout << ans <<     << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 100, MOD = 1e9 + 9, INF = 1e15, SQ = 370, LOG = 30;   int n, m, x, y, x2, y2, z, t, now, l, r;   int ans, dp[4][4 * N];   bool lazy[4 * N];   string s;   void bld(int b, int e, int pos) {     if (b == e - 1) {       if (s[b] ==  7 ) {         dp[3][pos]++;       } else {         dp[2][pos]++;       }       dp[0][pos] = dp[1][pos] = 1;       return;     }     int lch = pos << 1, rch = lch + 1, mid = e + b >> 1;     bld(b, mid, lch);     bld(mid, e, rch);     dp[3][pos] = dp[3][lch] + dp[3][rch];     dp[2][pos] = dp[2][lch] + dp[2][rch];     dp[1][pos] = max(dp[3][lch] + dp[1][rch], dp[1][lch] + dp[2][rch]);     dp[0][pos] = max(dp[2][lch] + dp[0][rch], dp[0][lch] + dp[3][rch]);   }   void shift(int pos, int lch, int rch) {     lazy[lch] = !lazy[lch];     lazy[rch] = !lazy[rch];     lazy[pos] = false;     swap(dp[0][lch], dp[1][lch]);     swap(dp[2][lch], dp[3][lch]);     swap(dp[0][rch], dp[1][rch]);     swap(dp[2][rch], dp[3][rch]);   }   void upd(int b, int e, int pos) {     if (b >= y || e <= x) return;     if (x <= b && e <= y) {       lazy[pos] = !lazy[pos];       swap(dp[0][pos], dp[1][pos]);       swap(dp[2][pos], dp[3][pos]);       return;     }     int lch = pos << 1, rch = lch + 1, mid = e + b >> 1;     if (lazy[pos]) shift(pos, lch, rch);     upd(b, mid, lch);     upd(mid, e, rch);     dp[3][pos] = dp[3][lch] + dp[3][rch];     dp[2][pos] = dp[2][lch] + dp[2][rch];     dp[1][pos] = max(dp[3][lch] + dp[1][rch], dp[1][lch] + dp[2][rch]);     dp[0][pos] = max(dp[2][lch] + dp[0][rch], dp[0][lch] + dp[3][rch]);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> s;     bld(0, n, 1);     while (m--) {       cin >> s;       if (s ==  count ) {         cout << dp[0][1] <<   n ;       } else {         cin >> x >> y;         x--;         upd(0, n, 1);       }     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:36777216 )   using namespace std;   const int inf = 1 << 30;   const long long Inf = 1LL << 62;   const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0};   const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};   const double eps = 1e-9;   const double pi = 3.1415926535897932384626433832795;   template <class T>   inline bool eq(const T &a, const T &b) {     return fabs(a - b) < eps;   }   template <class T>   inline bool deg2(const T &n) {     return (n & (n - 1)) == 0;   }   template <class T>   inline void chmax(T &a, const T &b) {     a = max(a, b);   }   inline int intRand(int l, int r) {     return ((rand() << 16) | rand()) % (r - l + 1) + l;   }   inline long long llRand(long long l, long long r) {     return (((1ll * rand()) << 48) | ((1ll * rand()) << 32) | (rand() << 16) |             rand()) %                (r - l + 1) +            l;   }   int i, n, len, j;   string s, pr;   int main() {     ios_base::sync_with_stdio(false);     srand(time(NULL));     cin >> n;     cin >> pr;     len = (int)pr.size();     for (i = 1; i < n; i++) {       cin >> s;       for (j = 0; j < len; j++)         if (s[j] != pr[j]) break;       len = j;       pr = s;     }     cout << len;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   using namespace std;   int n;   int main() {     cin >> n;     int k1 = 0;     int x = n;     while (x % 10 != 0) {       x++;       k1++;     }     int k2 = 0;     while (n % 10 != 0) {       n--;       k2++;     }     if (k1 > k2)       cout << n;     else       cout << x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[20000000 / 5], cnt;   bool flag[20000000];   void prepare() {     flag[1] = 1;     for (int i = 2; i <= m; i++) {       if (!flag[i]) {         p[cnt++] = i;       }       for (int j = 0; j < cnt && i * p[j] <= m; j++) {         flag[i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }   }   int main() {     cin >> n;     if (n == 2) {       puts( 1 1 );       return 0;     }     m = n * (n + 1) / 2;     prepare();     for (int i = 1; i <= n; i++)       if (!flag[i] && !flag[m - i]) {         for (int j = 1; j <= n; j++) {           printf( %d  , j == i ? 1 : 2);         }         puts(  );         return 0;       }     for (int i = 4; i <= n; i++)       if (!flag[i] && !flag[m - 3 - i]) {         for (int j = 1; j <= n; j++) printf( %d  , j == 3 ? 2 : j == i ? 3 : 1);         return 0;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ww {     long double x, y;   } a[100010];   int i, j, k, n, m, xx, yy;   long double LU[100010], RU[100010], LD[100010], RD[100010];   inline bool judge(long double len) {     int i, j;     j = 0;     for (i = 1; i <= n; i++) {       for (; a[j + 1].x + len < a[i].x; j++)         ;       if (max(LU[j], RU[i + 1]) - min(LD[j], RD[i + 1]) <= len) return 1;     }     return 0;   }   inline bool cc1(const ww &a, const ww &b) { return a.x < b.x; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &xx, &yy);       a[i].x = yy - xx, a[i].y = xx + yy;     }     sort(a + 1, a + n + 1, cc1);     LD[0] = RD[n + 1] = 1e10;     LU[0] = RU[n + 1] = -1e10;     for (i = 1; i <= n; i++)       LD[i] = min(LD[i - 1], a[i].y), LU[i] = max(LU[i - 1], a[i].y);     for (i = n; i; i--)       RD[i] = min(RD[i + 1], a[i].y), RU[i] = max(RU[i + 1], a[i].y);     long double l = 0, r = 1e10, mid;     for (; l + 1e-7 < r;) {       mid = (l + r) / 2;       if (judge(mid))         r = mid;       else         l = mid;     }     double an = r;     printf( %.10lf n , an / 2);     return 0;   }