malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long N = 0, M, K;   long long MOD = 998244353;   string S, S1;   struct st {     long long x, i;   };   bool operator<(const st& a, const st& b) {     if (a.x == b.x) return a.i < b.i;     return a.x < b.x;   }   long long gcd(long long a, long long b) {     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   long long fact(long long x) {     long long x1 = 1;     while (x >= 1) {       x1 *= x;       x--;     }     return x1;   }   void prime(long long n, vector<long long>& pr) {     vector<long long> lp(n + 90);     for (long long i = 2; i <= n; ++i) {       if (!lp[i]) {         pr.push_back(i);         lp[i] = i;       }       for (long long j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] <= n;            ++j) {         lp[i * pr[j]] = pr[j];       }     }   }   void dfs(long long x, vector<long long>& b, vector<long long>& w,            vector<vector<long long>>& v) {     w[x] = 1;     b.push_back(x);     for (long long i : v[x]) {       if (!w[i]) dfs(i, b, w, v);     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, s1;     long long n, k = 0, m;     long long x = 0, y = 0, ans = 0;     cin >> s >> n;     vector<long long> a;     for (long long i = 0; i < n; i++) {       s1 =   ;       cin >> x >> y >> k;       m = y - x + 1;       k = k % m;       for (long long j = y - k; j <= y - 1; j++) s1 += s[j];       s.erase(y - k, k);       s.insert(x - 1, s1);     }     cout << s <<   n ;     cin >> N;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   long long fastpo(long long a, long long x) {     if (x == 0) return 1ll;     if (x == 1) return a;     long long y = fastpo(a, x / 2);     if (x % 2 == 0) {       return y * y;     }     return y * y * a;   }   long long inv(long long a, long long M) { return fastpo(a, M - 2); }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     if (g != 1)       return -1;     else {       long long res = (x % m + m) % m;       return res;     }   }   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long N = 2e6 + 5;   vector<long long> dp(N, 0), ci(N, 0), ai(N, 0), bi(N, 0), ans(N, 0);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 1; i < N; i++) {       if (i == 1) {         dp[i] = 1;         ci[i] = 0;         ai[i] = 0;         bi[i] = 1;         ans[i] = 0;       } else if (i == 2) {         dp[i] = 2;         ci[i] = 0;         ai[i] = 1;         bi[i] = 1;         ans[i] = 0;       } else {         ci[i - 1] = dp[i - 3];         ai[i - 1] = dp[i - 2] - dp[i - 3];         bi[i - 1] = dp[i - 1] - dp[i - 2];         dp[i] = ((ci[i - 1] + ai[i - 1] * 3 + bi[i - 1] * 2) % M + M) % M;         ans[i] = (ans[i - 3] + bi[i - 2]) % M;       }     }     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long res = ((ans[n] * 4) % M + M) % M;       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void test() {     int t;     cin >> t;     while (t--) {       int i = 0;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int i = 0;     int n;     cin >> n;     map<int, int> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       m[x]++;     }     int g = 0;     for (auto i : m) {       if (i.first != 0) g++;     }     cout << g;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int M, tp, xx, lll, cc, ndl = 0, N, dl, nf, nef, T;   struct bl {     long long int type;     long long int l, c, x;   };   bl t;   vector<bl> B;   vector<long long int> C;   map<long long int, long long int> MP;   ifstream in( input.txt );   long long int find_bl(long long int n) {     if (MP.count(n) == 0) {       long long int num = (lower_bound(C.begin(), C.end(), n) - C.begin());       t = B[num];       if (t.type == 1) {         T = t.x;         MP[n] = T;         return T;       } else {         nf = n - C[num - 1];         nef = (nf % t.l == 0) ? t.l : (nf % t.l);         T = find_bl(nef);         MP[n] = T;         return T;       }     } else       return MP[n];   }   int main() {     cin >> M;     for (int i = 1; i <= M; i++) {       cin >> tp;       t.type = tp;       if (tp == 1) {         cin >> xx;         t.x = xx;         B.push_back(t);         C.push_back(ndl + 1);         ndl++;       } else {         cin >> lll >> cc;         t.l = lll;         t.c = cc;         B.push_back(t);         C.push_back(ndl + (lll * cc));         ndl += lll * cc;       }     }     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> xx;       cout << find_bl(xx) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 102, T = 1000 * 1000 * 1000 + 7;   int a[2600][M];   bool mrk[2600][M];   string s;   int ff(long long sum, int n) {     if (sum < 0) return 0;     if (mrk[sum][n]) return a[sum][n];     if (sum > 25 && n == 1) return 0;     if (sum <= 25 && n == 1) return 1;     long long temp = 0;     for (int i = 0; i < 26; i++) temp += ff(sum - i, n - 1), temp %= T;     a[sum][n] = temp;     mrk[sum][n] = true;     return temp;   }   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long sum = 0;       for (int i = 0; i < s.length(); i++) sum += s[i] -  a ;       cout << (ff(sum, s.length()) + T - 1) % T << endl;     }     return 0;     ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxv = 10001;   map<string, int> tidx;   map<int, int> fp[maxv];   struct Edge {     int to, next;   } edge[maxv * 2];   int m, idx, head[maxv], ednum, deg[maxv];   char tmp[22];   bool mp[maxv][maxv];   void addedge(int u, int v) {     edge[ednum] = Edge{v, head[u]};     head[u] = ednum++;     edge[ednum] = Edge{u, head[v]};     head[v] = ednum++;   }   void cal(int u) {     int i, j, vi, vj;     deg[u] = 1;     for (i = head[u]; i != -1; i = edge[i].next) {       deg[u]++;       for (j = edge[i].next; j != -1; j = edge[j].next) {         vi = edge[i].to;         vj = edge[j].to;         if (!mp[vi][vj] && !mp[vj][vi]) fp[vi][vj] += 1, fp[vj][vi] += 1;       }     }   }   int main() {     int a, b, i, maxv, num;     string u, v;     memset(head, -1, sizeof(head));     map<string, int>::iterator it;     map<int, int>::iterator jt;     idx = ednum = 0;     scanf( %d , &m);     for (i = 0; i < m; i++) {       scanf( %s , tmp);       u = tmp;       scanf( %s , tmp);       v = tmp;       if (tidx.find(u) == tidx.end())         tidx[u] = a = idx++;       else         a = tidx[u];       if (tidx.find(v) == tidx.end())         tidx[v] = b = idx++;       else         b = tidx[v];       mp[a][b] = mp[b][a] = true;       addedge(a, b);     }     printf( %d n , idx);     for (i = 0; i < idx; i++) cal(i);     for (it = tidx.begin(); it != tidx.end(); it++) {       i = it->second;       maxv = 0, num = idx - fp[i].size() - deg[i];       for (jt = fp[i].begin(); jt != fp[i].end(); jt++) {         if (jt->second > maxv) {           maxv = jt->second;           num = 1;         } else if (jt->second == maxv)           num++;       }       printf( %s %d n , it->first.c_str(), num);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f, k, m;     int n[101][2];     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b >> c >> d >> k;       if (a % c == 0)         e = a / c;       else         e = a / c + 1;       if (b % d == 0)         f = b / d;       else         f = b / d + 1;       if ((e + f) <= k) {         n[i][0] = e;         n[i][1] = f;       } else {         n[i][0] = -1;       }     }     for (int i = 0; i < m; i++) {       if (n[i][0] != -1)         cout << n[i][0] <<     << n[i][1] << endl;       else         cout <<  -1  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, y;   string s;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> x >> y >> s;     long long zeros = 0;     int last = -1;     for (auto c : s) {       int b = (c -  0 );       if (b != last && !b) zeros++;       last = b;     }     if (zeros == 0) {       cout << 0 << endl;       return 0;     }     long long ans1 = x * (zeros - 1) + y;     long long ans2 = y * (zeros - 1) + y;     cout << min(ans1, ans2) << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sq(T x) {     return x * x;   }   const long long inf = 2147383647;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   const long long maxint = 2147483647;   const long long minint = -2147483648;   int n, m;   long long arr[100010], brr[100010];   long long dp1[100010], dp2[100010];   void input() {     int i;     for (i = 0; i < n; i++) {       scanf( %I64d , &arr[i]);     }     for (i = 0; i < m; i++) {       scanf( %I64d , &brr[i]);     }     sort(arr, arr + n);     sort(brr, brr + m);   }   void dpcalc() {     dp1[0] = 0;     int i;     for (i = 1; i < n; i++) {       dp1[i] = dp1[i - 1];       dp1[i] += i * (arr[i] - arr[i - 1]);     }     dp2[m - 1] = 0;     for (i = m - 2; i >= 0; i--) {       dp2[i] = dp2[i + 1];       int e = m - i - 1;       dp2[i] += e * (brr[i + 1] - brr[i]);     }   }   long long findCost(long long x) {     long long res = 0;     long long pos = upper_bound(arr, arr + n, x) - arr;     if (pos > 0) {       pos--;       res += dp1[pos];       res += (pos + 1) * (x - arr[pos]);     }     pos = lower_bound(brr, brr + m, x) - brr;     if (pos < m) {       res += dp2[pos];       res += (m - pos) * (brr[pos] - x);     }     return res;   }   int main() {     scanf( %d %d , &n, &m);     int i, j;     input();     dpcalc();     long long low = 1, high = 1000000000;     long long res = -1;     while (high - low > 5) {       long long m1 = (2 * low + high) / 3;       long long m2 = (low + 2 * high) / 3;       long long u = findCost(m1);       long long v = findCost(m2);       if (res == -1) res = u;       res = min(res, u);       res = min(res, v);       if (u > v) {         low = m1 + 1;       } else {         high = m2 - 1;       }     }     while (low <= high) {       res = min(res, findCost(low));       low++;     }     printf( %I64d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 100;   const int M = 30;   int n;   string s;   string t;   int mat[M][M][N];   int ones[N];   int ans;   long double javab;   set<char> g;   bool mark[30];   int chand[30];   bool oomade[30];   int main() {     cin >> s;     n = s.size();     for (int i = 0; i < n; i++) {       g.insert(s[i]);       chand[s[i] -  a ]++;       oomade[s[i] -  a ] = 1;     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n + i; j++) {         int y = j % n;         int f = (int)s[i] - (int) a ;         int l = (int)s[y] - (int) a ;         mat[f][l][j - i]++;       }     }     for (int i = 0; i < 26; i++) {       if (oomade[i] == 1) {         for (int j = 0; j < n; j++) {           int tmp = 0;           for (int k = 0; k < 26; k++) {             if (mat[i][k][j] == 1) {               tmp++;             }           }           ones[i] = max(ones[i], tmp);         }         ans += ones[i];       }     }     javab = (long double)ans / (n);     cout << fixed << setprecision(10) << javab;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};     int n, m;     cin >> n >> m;     vector<int> ans;     string s;     int idx = 0;     while (getline(cin, s)) {       int month = (s[5] -  0 ) * 10 + (s[6] -  0 );       int day = (s[8] -  0 ) * 10 + (s[9] -  0 );       int hour = (s[11] -  0 ) * 10 + (s[12] -  0 );       int mnt = (s[14] -  0 ) * 10 + (s[15] -  0 );       int sec = (s[17] -  0 ) * 10 + (s[18] -  0 );       int totalSec = sec + mnt * 60 + hour * 3600 + day * 24 * 3600;       for (int i = 0; i < month - 1; i++) {         totalSec += months[i] * 24 * 3600;       }       while (idx < ans.size() and ans[idx] + n <= totalSec) {         idx++;       }       ans.push_back(totalSec);       if (ans.size() - idx >= m) {         for (int i = 0; i < 19; i++) {           printf( %c , s[i]);         }         puts(  );         return 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fir[5000];   int sec[5000];   int init(int x, int y) {     printf( ? %d %d n , x, y);     fflush(stdout);     scanf( %d , &x);     return x;   }   void print(int sch, const vector<int> &ans) {     printf( ! n );     fflush(stdout);     printf( %d n , sch);     fflush(stdout);     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     fflush(stdout);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) fir[i] = init(0, i);     for (int i = 0; i < n; i++) sec[i] = init(i, 0);     vector<int> ans;     int sch = 0;     for (int i = 0; i < n; i++) {       bool t = true;       int col[5000], p[5000], b[5000];       b[0] = i;       memset(col, 0, sizeof col);       for (int j = 0; j < n; j++) {         int x = sec[j] ^ b[0];         if (x >= n || col[x]) {           t = false;           break;         }         p[j] = x;         col[x]++;       }       if (t) {         memset(col, 0, sizeof col);         col[i]++;         for (int j = 1; j < n; j++) {           int x = fir[j] ^ p[0];           if (x >= n || col[x]) {             t = false;             break;           }           b[j] = x;           col[x]++;         }       }       if (t) {         for (int j = 0; j < n; j++)           if (j != b[p[j]]) t = false;       }       if (t) {         if (!sch) {           for (int j = 0; j < n; j++) ans.push_back(p[j]);         }         sch++;       }     }     print(sch, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, ans = 999999999999999999, mn = 123456789000LL;     cin >> n >> m;     long long x = n;     vector<pair<long long, long long> > v;     long long cnt = 0;     for (long long i = 2; i <= sqrt(m); i++) {       if (m % i == 0) {         cnt = 0;         while (m % i == 0) {           cnt++;           m = m / i;         }         v.push_back({i, cnt});       }     }     if (m > 1) {       mn = 1;       v.push_back({m, 1});     }     for (int i = 0; i < v.size(); i++) {       long long y = x;       long long temp = 0;       while (y) {         temp += y / v[i].first;         y = y / v[i].first;       }       temp = temp / v[i].second;       ans = min(temp, ans);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;         void solve()   {       int n,i,j=2,x,m,d,k;       cin >> n;       if(n%2==1)       {cout <<  NO  << endl;return;}       while(j<1000000009 && j<=n)       {           if(n==j)           {              // cout <<  loop  << endl;                  cout <<  YES  << endl;               return;           }           //cout << n <<     << j << endl;           j*=2;       }             n=n/2;       j=sqrt(n);       if(j*j < n){          if(n%2==1)       {           cout <<  NO  << endl;return;       }       n/=2;       j=sqrt(n);           if(j*j < n)               {           cout <<  NO  << endl;return;       }       else {           {           cout <<  YES  << endl;return;       }       }          }          //if(j%2==1) {cout <<  NO  << endl;return;}       cout <<  YES  << endl;         }         int main()   {       ios_base::sync_with_stdio(false); cin.tie(NULL);       int t=1;       cin >> t;       while(t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   vector<long long> v;   long long dp[1001][2001][4];   long long rec(long long i, long long mask, long long comp) {     if (i == n && comp == k)       return 1;     else if (i == n)       return 0;     else if (comp > k)       return 0;     if (dp[i][comp][mask] != -1) return dp[i][comp][mask];     if (i == 0) {       return dp[i][comp][mask] =                  (rec(i + 1, 0, comp + 1) + rec(i + 1, 1, comp + 2) +                   rec(i + 1, 2, comp + 2) + rec(i + 1, 3, comp + 1)) %                  998244353;     }     if (mask == 0) {       return dp[i][comp][mask] =                  (rec(i + 1, 0, comp) + rec(i + 1, 3, comp + 1) +                   rec(i + 1, 1, comp + 1) + rec(i + 1, 2, comp + 1)) %                  998244353;     } else if (mask == 1) {       return dp[i][comp][mask] = (rec(i + 1, 0, comp) + rec(i + 1, 1, comp) +                                   rec(i + 1, 2, comp + 2) + rec(i + 1, 3, comp)) %                                  998244353;     } else if (mask == 2) {       return dp[i][comp][mask] = (rec(i + 1, 0, comp) + rec(i + 1, 1, comp + 2) +                                   rec(i + 1, 2, comp) + rec(i + 1, 3, comp)) %                                  998244353;     } else if (mask == 3) {       return dp[i][comp][mask] =                  (rec(i + 1, 0, comp + 1) + rec(i + 1, 1, comp + 1) +                   rec(i + 1, 2, comp + 1) + rec(i + 1, 3, comp)) %                  998244353;     }   }   void solve() {     memset(dp, -1, sizeof(dp));     cin >> n >> k;     cout << rec(0, 0, 0);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long q = 1;     while (q--) {       v.clear();       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long g, x, y, z;   int n, m;   int nn, mm;   deque<long long> q;   long long a[3010][3010];   long long b[3010][3010];   long long c[3010][3010];   int main() {     scanf( %d%d%d%d , &nn, &mm, &n, &m);     scanf( %lld%lld%lld%lld , &g, &x, &y, &z);     for (int i = 1; i <= nn; i++) {       for (int j = 1; j <= mm; j++) {         a[i][j] = g;         g = g * x + y;         g %= z;       }     }     for (int i = 1; i <= nn; i++) {       for (int j = mm; j >= 1; j--) {         while (!q.empty() && a[i][q.back()] >= a[i][j]) {           q.pop_back();         }         q.push_back(j);         while (!q.empty() && q.front() - q.back() + 1 > m) {           q.pop_front();         }         if (j <= mm - m + 1) b[i][j] = a[i][q.front()];       }       while (!q.empty()) q.pop_front();     }     for (int i = 1; i <= mm - m + 1; i++) {       for (int j = nn; j >= 1; j--) {         while (!q.empty() && b[q.back()][i] >= b[j][i]) {           q.pop_back();         }         q.push_back(j);         while (!q.empty() && q.front() - q.back() + 1 > n) {           q.pop_front();         }         if (j <= nn - n + 1) c[j][i] = b[q.front()][i];       }       while (!q.empty()) q.pop_front();     }     long long ans = 0;     for (int i = 1; i <= nn - n + 1; i++) {       for (int j = 1; j <= mm - m + 1; j++) {         ans += c[i][j];       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long _pow(long long a, long long b, long long m) {     if (b == 0) return 1;     long long t = _pow(a, b / 2, m);     t = (t * t) % m;     if (b & 1)       return (t * a) % m;     else       return t;   }   int main(int argc, char *argv[]) {     int n;     cin >> n;     vector<string> v;     int cnt = 0;     bool zero = false;     string ex =  1 ;     for (int i = 0; i < n; i++) {       string x;       cin >> x;       v.push_back(x);       bool f = true;       if (x[0] ==  0  and x.size() == 1)         zero = true;       else if (x[0] ==  1 ) {         int cn = 0;         int j;         for (j = 1; j < x.size(); j++)           if (x[j] !=  0 ) {             ex = x;             break;           } else             cn++;         if (j == x.size()) cnt += cn;       } else         ex = x;     }     if (zero)       cout << 0 << endl;     else {       cout << ex;       for (int i = 0; i < cnt; i++) cout << 0;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int mod = 1e9 + 7;   const int N = 1e5 + 10;   inline int add(int x, int y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline int mul(int x, int y) {     x = (1LL * x * y) % mod;     return x;   }   int main() {     string s;     cin >> s;     string a =  abcdefghijklmnopqrstuvwxyz ;     long long k = 0;     for (int i = 0; i <= s.size() - 1; ++i) {       if (s[i] <= a[k]) {         s[i] = a[k];         k++;       }     }     if (k == 26) {       cout << s;     } else {       cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     vector<pair<int, int>> a;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a.push_back({x, i});     }     sort(a.begin(), a.end(), greater<pair<int, int>>());     int numRow = a[0].first + 1;     vector<vector<int>> ans(numRow, vector<int>(n, 0));     for (int i = 0; i < a[0].first; i++) ans[i][a[0].second] = 1;     int row = 0;     for (int i = 1; i < n; i++) {       auto [block, col] = a[i];       for (int i = 1; i <= block; i++) ans[(row + i) % numRow][col] = 1;       if (row < numRow - 2) row++;     }     if (!accumulate(ans[numRow - 1].begin(), ans[numRow - 1].end(), 0)) numRow--;     cout << numRow << endl;     for (int i = 0; i < numRow; i++) {       for (auto x : ans[i]) cout << x;       cout << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   int q;   unsigned int a[200002];   unsigned int b[200002];   unsigned int w;   int main() {     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       int t, l, r, k;       scanf( %d%d%d , &t, &l, &r);       --l, --r;       if (t == 1) {         scanf( %d , &k);         if (k > 0) {           w = k;           for (int i = l; i < r; ++i)             if (a[i]) {               a[i] = min(a[i], w);             } else {               a[i] = w;             }         } else {           w = -k;           for (int i = l; i < r; ++i)             if (b[i]) {               b[i] = min(b[i], w);             } else {               b[i] = w;             }         }       } else {         long long ans = 0;         for (int i = l; i < r; ++i)           if (a[i] > 0 && b[i] > 0) ans += a[i] + b[i];         printf(              %lld                n ,             ans);       }     }     return 0;   }