malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const unsigned long long MOD = 1e8 + 7;   const unsigned long long base = 71;   const unsigned long long max_n = 2e5 + 400;   unsigned long long n, m, k, q;   string s;   unsigned long long pw[2 * max_n + 200];   unsigned long long save[20][2 * max_n + 200];   unsigned long long seg[10 * max_n], lazy[10 * max_n];   void init(unsigned long long v, unsigned long long b, unsigned long long e) {     lazy[v] = -1;     if (b == e) {       seg[v] = s[b];       return;     }     unsigned long long mid = (b + e) / 2;     init(v << 1, b, mid);     init(v << 1 ^ 1, mid + 1, e);     seg[v] = (seg[v << 1] * pw[e - mid] + seg[v << 1 ^ 1]) % MOD;   }   void shift(unsigned long long v, unsigned long long b, unsigned long long e,              unsigned long long mid) {     if (lazy[v] == -1) return;     lazy[v << 1] = lazy[v << 1 ^ 1] = lazy[v];     seg[v << 1] = save[lazy[v]][mid - b];     seg[v << 1 ^ 1] = save[lazy[v]][e - mid - 1];     lazy[v] = -1;   }   void update(unsigned long long v, unsigned long long b, unsigned long long e,               unsigned long long l, unsigned long long r,               unsigned long long val) {     if (b > r || l > e) return;     if (l <= b && e <= r) {       seg[v] = save[val][e - b];       lazy[v] = val;       return;     }     unsigned long long mid = (b + e) / 2;     shift(v, b, e, mid);     update(v << 1, b, mid, l, r, val);     update(v << 1 ^ 1, mid + 1, e, l, r, val);     seg[v] = (seg[v << 1] * pw[e - mid] + seg[v << 1 ^ 1]) % MOD;   }   unsigned long long get(unsigned long long v, unsigned long long b,                          unsigned long long e, unsigned long long l,                          unsigned long long r) {     if (b > r || l > e) return 0;     if (l <= b && e <= r) return seg[v];     unsigned long long mid = (b + e) / 2;     shift(v, b, e, mid);     unsigned long long first = get(v << 1, b, mid, l, r);     unsigned long long second = get(v << 1 ^ 1, mid + 1, e, l, r);     first = (first * pw[max(0, int(min(r, e) - mid))] + second) % MOD;     return first;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cin >> n >> m >> k;     q = m + k;     cin >> s;     pw[0] = 1;     for (unsigned long long i = 1; i < max_n; i++)       pw[i] = (pw[i - 1] * base) % MOD;     for (unsigned long long i = 0; i < 10; i++) {       save[i][0] = i + 48;       for (unsigned long long j = 1; j < max_n; j++)         save[i][j] = (save[i][j - 1] * base + (i + 48)) % MOD;     }     init(1, 0, n - 1);     while (q--) {       unsigned long long type, l, r;       cin >> type >> l >> r;       l--, r--;       if (type == 1) {         unsigned long long c;         cin >> c;         update(1, 0, n - 1, l, r, c);         continue;       }       bool fl = 0;       unsigned long long d;       cin >> d;       if (d == r - l + 1) fl = 1;       if (!fl) fl = get(1, 0, n - 1, l, r - d) == get(1, 0, n - 1, l + d, r);       if (fl)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2E5 + 77;   void putint(int x) {     static bool first = true;     if (first) {       printf( %d , x);       first = false;     } else       printf(  %d , x);   }   struct QUERY {     int t, r;   } Q[maxn];   int cnt = 0;   int N, M, A[maxn], B[maxn], pb = 0;   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i < N; ++i) scanf( %d , A + i);     for (int i = 0; i < M; ++i) {       int t, r;       scanf( %d%d , &t, &r);       while (cnt && r >= Q[cnt - 1].r) --cnt;       if (!cnt || t != Q[cnt - 1].t) Q[cnt++] = (QUERY){t, r};     }     Q[cnt] = (QUERY){0, 0};     sort(A, A + Q[0].r);     int ptr[2] = {0, Q[0].r - 1}, d = Q[0].t == 1;     for (int i = 0; i < cnt; ++i) {       for (int j = Q[i].r; j > Q[i + 1].r; --j) {         B[pb++] = A[ptr[d]];         ptr[d] += d ? -1 : 1;       }       d ^= 1;     }     for (int i = Q[0].r - 1; i >= 0; --i) putint(B[i]);     for (int i = Q[0].r; i < N; ++i) putint(A[i]);     printf(  n );   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:136777216 )   using namespace std;   int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); }   const double PI = acos(-1.0);   const double eps = 1e-9;   const int INF = 1000000000;   string nextString() {     char buf[1000000];     scanf( %s , buf);     return buf;   }   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   string month[] = { January ,    February ,  March ,     April ,                      May ,        June ,      July ,      August ,                      September ,  October ,   November ,  December };   int main() {     string s = nextString();     int start;     for (int(i) = 0; (i) < (12); (i)++)       if (s == month[i]) start = i;     int n;     scanf( %d , &n);     int end = (n + start) % 12;     printf( %s n , month[end].c_str());     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int mod = (int)1e9 + 7;   const long long INF = 1000000000000000000LL;   const int WASTE = (int)2e5;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int x, y, p, q;       cin >> x >> y >> p >> q;       if (!p) {         cout << (x == 0 ? 0 : -1) <<   n ;         continue;       }       if (p == q) {         if (x == y)           cout << 0 <<   n ;         else           cout << -1 <<   n ;         continue;       }       int i = (x + p - 1) / p;       int i1 = (y - x - p + q - 1) / (q - p);       cout << (q * 1LL * max(i, i1) - y) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3;   int n, x[N], d[N], i, j;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> x[i] >> d[i];     for (i = 0; i < n; i++)       for (j = i + 1; j < n; j++)         if (x[i] + d[i] == x[j] && x[j] + d[j] == x[i]) return cout <<  YES , 0;     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int n;   char s[N];   bool ck(int l, int r) {     int a = 0, b = 0, c = 0, d = 0;     for (int i = l; i <= r; i++) {       if (s[i] ==  U )         a++;       else if (s[i] ==  D )         b++;       else if (s[i] ==  L )         c++;       else         d++;     }     if (a == b && c == d)       return 1;     else       return 0;   }   int main() {     scanf( %d , &n);     scanf( %s , s);     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) ans += ck(i, j);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i;     scanf( %d , &n);     char s[100];     int a[n], b[n], c[n];     scanf( %s , s);     for (i = 0; i < n; i++) {       int h = (int)s[i];       a[i] = h - 48;     }     for (i = 0; i < n; i++) {       b[n - i - 1] = a[i];       c[n - i - 1] = a[i];     }     i = n - 1;     int c1 = 1;     while (c1 == 1) {       if (b[i] == 1) {         c[i] = 0;         c1 = 1;         i--;       } else if (b[i] == 0) {         c[i] = 1;         c1 = 0;         i--;       }       if (i < 0) break;     }     int count = 0;     for (i = 0; i < n; i++) {       if (b[i] != c[i]) count++;     }     printf( %d n , count);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     string ans, in, dec, exp;     int flag = 0;     for (int i = 0; i < x.length(); i++) {       if (x[i] ==  . )         flag = 1;       else if (x[i] ==  e )         flag = 2;       else if (flag == 0)         in += x[i];       else if (flag == 1)         dec += x[i];       else if (flag == 2)         exp += x[i];     }     int e = stoi(exp);     ans += in;     if (e <= dec.length()) {       ans += dec.substr(0, e);       if (e < dec.length()) {         ans +=  . ;         ans += dec.substr(e, dec.length());       }     } else {       ans += dec;       ans += string(e - dec.length(),  0 );     }     flag = 0;     if (dec.length() < 2 && stoi(dec) == 0 && e == 0) ans = in;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int limN = 2e5 + 5;   char s[limN];   char arr[2000];   int bu[400];   int main() {     int t;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       scanf( %s , s);       for (int j = 0; j < 2000; j++) arr[j] =  . ;       for (int j = 0; j < 400; j++) bu[j] = 0;       int n = strlen(s);       int ini = 500;       int fin = 500;       bool f = true;       arr[ini] = s[0];       bu[s[0]]++;       int pos = ini;       for (int j = 1; j < n; j++) {         if (j == 1) {           fin++;           arr[fin] = s[j];           bu[s[j]]++;           pos = fin;           continue;         }         if (arr[pos - 1] == s[j]) {           pos--;           continue;         }         if (arr[pos + 1] == s[j]) {           pos++;           continue;         }         if (bu[s[j]] > 0) {           f = false;           break;         } else {           if (pos == ini) {             ini--;             arr[ini] = s[j];             bu[s[j]]++;             pos--;           } else if (pos == fin) {             fin++;             arr[fin] = s[j];             bu[s[j]]++;             pos++;           } else {             f = false;             break;           }         }       }       if (!f) {         printf( NO n );       } else {         printf( YES n );         for (int j = ini; j <= fin; j++) {           printf( %c , arr[j]);         }         for (int j =  a ; j <=  z ; j++) {           if (bu[j] == 0) {             printf( %c , j);           }         }         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxv = 110;   int n, m;   int val[Maxv][Maxv * Maxv];   int org[Maxv][Maxv];   int dp[Maxv][Maxv * Maxv];   int Len[Maxv];   int main() {     int i, j, k;     cin >> n >> m;     for (i = 1; i <= n; i++) {       scanf( %d , &Len[i]);       for (j = 1; j <= Len[i]; j++) scanf( %d , &org[i][j]);       int sum1 = 0;       for (j = 0; j <= Len[i]; j++) {         int sum2 = 0;         sum1 += org[i][j];         for (k = Len[i] + 1; k > j; k--) {           sum2 += org[i][k];           int tcost = j + Len[i] + 1 - k;           val[i][tcost] = max(sum1 + sum2, val[i][tcost]);         }       }       for (k = m; k >= 1; k--) {         for (j = 0; j <= Len[i] && j <= k; j++) {           dp[i][k] = max(dp[i][k], dp[i - 1][k - j] + val[i][j]);         }       }     }     printf( %d n , dp[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, x, a[100005], ct[100005];   int main() {     cin >> n >> x;     for (long long int i = 1; i <= n; ++i) cin >> a[i], ct[a[i]]++;     sort(a + 1, a + n + 1);     long long int ans = 0;     for (long long int i = 1; i <= n; ++i) {       long long int ch = x ^ a[i];       if (ch == a[i]) {         ans += (ct[ch] - 1);       } else if (ch <= 100000)         ans += ct[ch];     }     cout << ans / 2;   }
#include <bits/stdc++.h>   using namespace std;   const int Mod = (int)1e9 + 7;   const int MX = 1073741822;   const long long MXLL = 4e18;   const int Sz = 1110111;   inline void Read_rap() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline void randomizer3000() {     unsigned int seed;     asm( rdtsc  :  =A (seed));     srand(seed);   }   void files(string problem) {     if (fopen((problem +  .in ).c_str(),  r )) {       freopen((problem +  .in ).c_str(),  r , stdin);       freopen((problem +  .out ).c_str(),  w , stdout);     }   }   void localInput(const char in[] =  s ) {     if (fopen(in,  r )) {       freopen(in,  r , stdin);     } else       cerr <<  Warning: Input file not found  << endl;   }   int n;   const int N = 302;   int pref[N][N];   int dp[N][N];   int a[N];   int plen[N], len[N];   int main() {     Read_rap();     cin >> n;     for (int i = 1; i <= n; i++) {       static string s;       cin >> s;       static map<string, int> id;       if (!id.count(s)) id[s] = (int)(id.size());       a[i] = id[s];       len[i] = (int)(s.size());     }     for (int i = n; i >= 1; i--)       for (int j = n; j >= 1; j--)         if (a[i] == a[j]) pref[i][j] = pref[i + 1][j + 1] + 1;     for (int i = 1; i <= n; i++) plen[i] = plen[i - 1] + len[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         int len = i - j + 1;         for (int p = len; p < j; p++) {           int q = p - len + 1;           if (pref[j][q] >= len) dp[i][j] = max(dp[i][j], dp[p][q] + 1);         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         int len = i - j + 1;         if (dp[i][j]) {           int cost = len - 1 + plen[i] - plen[j - 1] - len;           ans = max(ans, cost * (dp[i][j] + 1));         }       }     }     int sum = accumulate(len + 1, len + n + 1, 0) + n - 1;     cout << sum - ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long ask(long long a, long long b, long long c, long long d) {     long long res;     cout <<  ?   << a <<     << b <<     << c <<     << d << endl;     cout.flush();     cin >> res;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     long long x1 = -1;     long long x2 = -1;     long long y1 = -1;     long long y2 = -1;     for (int i = 1; i < n; i++) {       if (ask(i, 1, i, n) % 2 == 1) {         if (x1 == -1)           x1 = i;         else {           x2 = i;           break;         }       }     }     if (x1 == -1) {       for (int i = 1; i < n; i++) {         if (ask(1, i, n, i) % 2 == 1) {           if (y1 == -1)             y1 = i;           else {             y2 = i;             break;           }         }       }       if (y2 == -1) y2 = n;       long long low = 1;       long long high = n;       x1 = n;       while (low <= high) {         long long mid = (low + high) / 2;         if (ask(low, y1, mid, y1) % 2 == 1) {           high = mid - 1;           x1 = min(x1, mid);         } else {           low = mid + 1;         }       }       x2 = x1;     } else {       if (x2 == -1) x2 = n;       long long low = 1;       long long high = n;       y1 = n;       while (low <= high) {         long long mid = (low + high) / 2;         if (ask(x1, low, x1, mid) % 2 == 1) {           y1 = min(y1, mid);           high = mid - 1;         } else {           low = mid + 1;         }       }       low = 1;       high = n;       y2 = n;       while (low <= high) {         long long mid = (low + high) / 2;         if (ask(x2, low, x2, mid) % 2 == 1) {           y2 = min(y2, mid);           high = mid - 1;         } else {           low = mid + 1;         }       }     }     cout <<  !   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     cout.flush();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[111111];   int y[111111];   int main() {     int i, n, m, t;     long long xx = 0, yy = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &t);       x[t] = i;       y[t] = n - i + 1;     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d , &t);       xx += x[t];       yy += y[t];     }     cout << xx <<     << yy << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const unsigned long long modn = 1000000007;   inline unsigned long long mod(unsigned long long x) { return x % modn; }   const int MAX = 100009;   int deg[MAX], ok[MAX];   vector<int> adj[MAX];   void dfs(int u, int p) {     if (deg[u] > 3) return;     ok[u]++;     if (deg[u] == 3) return;     for (int v : adj[u])       if (v != p) dfs(v, u);   }   int main() {     int i, n, a, b;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d %d , &a, &b);       adj[--a].push_back(--b);       adj[b].push_back(a);       deg[a]++;       deg[b]++;     }     for (i = 0; i < n; i++)       if (deg[i] == 1) dfs(i, -1);     for (i = 0; i < n; i++)       if (deg[i] == 3 && ok[i] <= 1) ok[i] = 0;     for (i = 0; i < n; i++) {       if (ok[i]) continue;       int ct = 0;       for (int v : adj[i])         if (!ok[v]) ct++;       if (ct > 2) break;     }     if (i < n)       puts( No );     else       puts( Yes );   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int n;   pair<long long, long long> a[maxn + 1];   pair<long long, long long> b;   priority_queue<long long, vector<long long>, greater<long long> > q;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a > b;   }   int main() {     int ans;     scanf( %d n , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i - 1].first, &a[i - 1].second);     }     b = a[0];     sort(a + 1, a + n, cmp);     int i = 1;     for (; i <= n && a[i].first > b.first; i++)       q.push(a[i].second - a[i].first + 1);     ans = i;     int lans = 0;     while (!q.empty()) {       long long k = q.top();       q.pop();       if (k > b.first) break;       b.first -= k;       lans++;       for (; i <= n && a[i].first > b.first; i++)         q.push(a[i].second - a[i].first + 1);       ans = min(ans, i - lans);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int acc[1002], s[1002];   int main() {     int n, t;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       s[t]++;     }     for (int i = 1; i < 1002; i++) {       acc[i] = acc[i - 1] + s[i];     }     int d;     cin >> d;     int total = 0;     for (int i = d + 1; i < 1002; i++) {       if (acc[i] - acc[i - d - 1] > total) total = acc[i] - acc[i - d - 1];     }     cout << total << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     std::map<long, long> map;     long q, id, leftMAX = 0, rightMAX = 0, firstTime = 0;     char c;     std::cin >> q;     while (q--) {       std::cin >> c >> id;       if (!firstTime--) {         map.insert(std::pair<long, long>(id, 0));       } else {         if (c ==  ? )           std::cout << std::min(map[id] - leftMAX, rightMAX - map[id])                     << std::endl;         else if (c ==  R )           map.insert(std::pair<long, long>(id, ++rightMAX));         else           map.insert(std::pair<long, long>(id, --leftMAX));       }     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   vector<int> up, down;   int main() {     int T, n;     char ch;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       up.clear();       down.clear();       for (int i = 1; i < n; i += 2) {         printf( ? %d %d n , i, i + 1);         fflush(stdout);         cin >> ch;         if (ch ==  < )           down.push_back(i), up.push_back(i + 1);         else           down.push_back(i + 1), up.push_back(i);       }       if (n & 1) down.push_back(n), up.push_back(n);       int Min = down[0], Max = up[0];       for (int i = 1; i < down.size(); i++) {         printf( ? %d %d n , Min, down[i]);         fflush(stdout);         cin >> ch;         if (ch ==  > ) Min = down[i];       }       for (int i = 1; i < up.size(); i++) {         printf( ? %d %d n , Max, up[i]);         fflush(stdout);         cin >> ch;         if (ch ==  < ) Max = up[i];       }       printf( ! %d %d n , Min, Max);       fflush(stdout);     }   }
#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 lcm(long a, long b) { return ((a * b) / gcd(a, b)); }   long long a[100000];   int main() {     long long i, j, k, l, m, n, maxx = 0, g = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 0; i < n; i++) {       while (a[i] % 2 == 0) {         a[i] /= 2;       }       while (a[i] % 3 == 0) {         a[i] /= 3;       }     }     sort(a, a + n);     if (a[0] == a[n - 1])       cout <<  Yes  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read(long long &x) { scanf( %lld , &x); }   void read(long long &x, long long &y) { scanf( %lld%lld , &x, &y); }   void read(long long &x, long long &y, long long &z) {     scanf( %lld%lld%lld , &x, &y, &z);   }   void print(long long x) { printf( %lld  , x); }   void println(long long x) { printf( %lld n , x); }   const long long N = 300100;   long long q, n, a[N], ans, b[N], sz;   int main() {     cin >> q;     for (; q--;) {       read(n);       for (long long i = 1; i <= n; i++) read(a[i]);       sort(a + 1, a + n + 1);       sz = 0;       for (long long i = 1; i <= n; i++)         if (i == 1 || a[i] != a[i - 1]) b[++sz] = a[i];       reverse(b + 1, b + sz + 1);       for (long long i = 1; i <= sz; i++) a[i] = b[i];       n = sz;       ans = a[1];       for (long long i = 1; i <= min(59LL, n); i++)         for (long long j = i + 1; j <= (i + 59LL, n); j++)           if (a[i] % a[j] != 0) ans = max(ans, a[i] + a[j]), j = n;       for (long long i = 1; i <= min(59LL, n); i++) {         if (i + 2 <= n && a[i] + a[i + 1] + a[i + 2] <= ans) break;         for (long long j = i + 1; j <= (i + 59LL, n); j++)           if (a[i] % a[j] != 0) {             if (j < n && a[i] + a[j] + a[j + 1] <= ans) break;             for (long long k = j + 1; k <= min(j + 59LL, n); k++)               if (a[i] % a[k] != 0 && a[j] % a[k] != 0)                 ans = max(ans, a[i] + a[j] + a[k]), k = n;           }       }       println(ans);     }   }