malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct state {     int x, y;   } bl[100005], rec[100005], cur[100005];   long long n, m;   bool cmp(const state& a, const state& b) {     if (a.y == b.y) return a.x < b.x;     return a.y < b.y;   }   bool funct() {     int counter = 1;     rec[0].x = 1, rec[0].y = 1;     for (int i = 0; i < (int)m; i++) {       if (bl[i].y != bl[i - 1].y + 1) {         counter = 1;         rec[0].y = n;       }       int k = i + 1;       int tmp = 0;       int c = 0;       for (k = i + 1; bl[k].y == bl[i].y; k++)         ;       k = k - 1;       for (int j = i; j <= k; j++) {         if (bl[j].x > tmp + 1) {           cur[c].x = tmp + 1;           cur[c].y = bl[j].x - 1;           c++;         }         tmp = bl[j].x;       }       if (n > tmp) {         cur[c].x = tmp + 1;         cur[c].y = n;         c++;       }       int t = 0;       for (int i = 0; i < counter; i++) {         while (cur[t].x <= rec[i].y && t < c) {           if (cur[t].y >= rec[i].x) {             cur[t].x = max(cur[t].x, rec[i].x);           } else {             cur[t].x = cur[t].y = -1;           }           t++;         }         if (t >= c) break;       }       counter = 0;       for (int i = 0; i < t; i++)         if (cur[i].x != -1 && cur[i].y != -1) {           rec[counter].x = cur[i].x;           rec[counter].y = cur[i].y;           counter++;         }       if (counter == 0) return false;       i = k;     }     if (bl[m - 1].y != n) {       return true;     }     if (rec[counter - 1].y == n) {       return true;     } else {       return false;     }   }   int main() {     cin >> n >> m;     int xx;     int yy;     for (int i = 0; i < (int)m; i++) {       cin >> xx >> yy;       bl[i].x = xx;       bl[i].y = yy;     }     sort(bl, bl + m, cmp);     if (funct()) {       cout << 2 * n - 2 << endl;     } else {       printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x;   int n, d;   int res[100010], a[100010], b[100010];   long long getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initab() {     for (int i = 0; i < n; i++) {       a[i] = i + 1;     }     for (int i = 0; i < n; i++) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (int i = 0; i < n; i++) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i++) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   void sol1() {     for (int i = 0; i < n; i++)       if (b[i]) {         for (int j = i; j < n; j++)           if (res[j] < a[j - i]) res[j] = a[j - i];       }   }   void sol2() {     int k = n - sqrt(n);     for (int i = 0; i < n; i++)       if (a[i] >= k) {         int l = n - i;         for (int j = 0; j < l; j++)           if (b[j] && res[j + i] < a[i]) res[j + i] = a[i];       }     for (int i = 0; i < n; i++)       if (!res[i]) {         for (int j = 0; j <= i; j++)           if (b[i - j] && res[i] < a[j]) res[i] = a[j];       }   }   int main() {     cin >> n >> d >> x;     initab();     int sd = sqrt(n) * 4;     if (d <= sd)       sol1();     else       sol2();     for (int i = 0; i < n; i++) printf( %d n , res[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 2e5 + 10;   int n, temp;   vector<int> ans;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> temp;       int pos = lower_bound(ans.begin(), ans.end(), temp) - ans.begin();       if (pos == ans.size())         ans.push_back(temp);       else         ans[pos] = temp;     }     cout << ans.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     int r = m * n - 2 * (k - 1);     cout << r <<    ;     int i = 0, j = 0;     for (; i < n; i++) {       if (i % 2 == 0) {         for (j = 0; j < m; j++) {           cout << i + 1 <<     << j + 1 <<    ;           r--;           if (r == 0) break;         }       } else {         for (j = m; j > 0; j--) {           cout << i + 1 <<     << j <<    ;           r--;           if (r == 0) break;         }       }       if (r == 0) break;     }     if (i % 2 == 0) {       if (j != m)         j++;       else         i++;     } else {       if (j != 0)         j--;       else         i++;     }     cout << endl;     r = 2;     for (; i < n; i++) {       if (i % 2 == 0) {         for (; j < m; j++) {           if (r == 2) cout << r <<    ;           cout << i + 1 <<     << j + 1 <<    ;           r--;           if (r == 0) {             cout << endl;             r = 2;           }         }       } else {         for (; j > 0; j--) {           if (r == 2) cout << r <<    ;           cout << i + 1 <<     << j <<    ;           r--;           if (r == 0) {             cout << endl;             r = 2;           }         }       }       if (r == 0) r = 2;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int digit(char c) {     char digits[] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 };     for (int i = 0; i < 10; i++) {       if (c == digits[i]) return 0;     }     return 1;   }   int main() {     int t = 0;     scanf( %d , &t);     while (t--) {       string s;       cin >> s;       int len = s.length();       int d = 1, c = 1, l = 1;       int cd = 0, cc = 0, cl = 0;       int flag = 0;       for (int i = 0; i < len; i++) {         if (int(s[i]) >= 48 && int(s[i]) <= 57) {           d = 0;           ++cd;         } else if (tolower(s[i]) == s[i]) {           l = 0;           ++cl;         } else if (toupper(s[i]) == s[i]) {           c = 0;           ++cc;         }         if ((d + c + l) == 0) {           flag = 1;           break;         }       }       if (flag == 1) {         cout << s << endl;         continue;       }       if ((d + c + l) == 1) {         if (d) {           if (cl <= cc) {             for (int i = 0; i < len; i++) {               if (toupper(s[i]) == s[i]) {                 s[i] =  7 ;                 break;               }             }           } else {             for (int i = 0; i < len; i++) {               if (tolower(s[i]) == s[i]) {                 s[i] =  7 ;                 break;               }             }           }           d = 0;         }         if (c) {           if (cl <= cd) {             for (int i = 0; i < len; i++) {               if (int(s[i]) >= 48 && int(s[i]) <= 57) {                 s[i] =  A ;                 break;               }             }           } else {             for (int i = 0; i < len; i++) {               if (tolower(s[i]) == s[i] && digit(s[i])) {                 s[i] = toupper(s[i]);                 break;               }             }           }           c = 0;         }         if (l) {           if (cc <= cd) {             for (int i = 0; i < len; i++) {               if (int(s[i]) >= 48 && int(s[i]) <= 57) {                 s[i] =  a ;                 break;               }             }           } else {             for (int i = 0; i < len; i++) {               if (toupper(s[i]) == s[i] && digit(s[i])) {                 s[i] = tolower(s[i]);                 break;               }             }           }         }         l = 0;       }       if ((d + c + l) == 2) {         if (!d) {           s[0] =  A ;           s[1] =  a ;         }         if (!c) {           s[0] =  a ;           s[1] =  7 ;         }         if (!l) {           s[0] =  A ;           s[1] =  7 ;         }       }       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int root[1000100];   unordered_map<int, int> mp[1000100];   pair<pair<int, int>, int> edge[1000100];   int cnt[1000100];   int find_root(int u) {     if (root[u] == u) return u;     return root[u] = find_root(root[u]);   }   bool cmp(pair<pair<int, int>, int> u, pair<pair<int, int>, int> v) {     return u.second < v.second;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       cnt[u]++;       cnt[v]++;       mp[u][v] = 1;       mp[v][u] = 1;     }     int mn = n, f = 0;     for (int i = 1; i <= n; i++) {       root[i] = i;       if (mn > cnt[i]) {         f = i;         mn = cnt[i];       }     }     vector<int> X, Y;     X.push_back(f);     for (int i = 1; i <= n; i++) {       if (i == f) continue;       if (!mp[f][i]) {         X.push_back(i);         root[i] = f;       } else         Y.push_back(i);     }     m = 0;     for (int i = 0; i < Y.size(); i++) {       for (int j = i + 1; j < Y.size(); j++) {         int u = Y[i], v = Y[j];         edge[++m] = pair<pair<int, int>, int>(pair<int, int>(u, v), mp[u][v]);       }     }     for (int i = 0; i < Y.size(); i++) {       for (int j = 0; j < X.size(); j++) {         int u = Y[i], v = X[j];         edge[++m] = pair<pair<int, int>, int>(pair<int, int>(u, v), mp[u][v]);       }     }     sort(edge + 1, edge + m + 1, cmp);     int ans = 0;     for (int i = 1; i <= m; i++) {       int u = edge[i].first.first, v = edge[i].first.second, w = edge[i].second;       int fu = find_root(u), fv = find_root(v);       if (fu == fv) continue;       root[fu] = fv;       ans += w;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   double gmin = 100000000000000017;   int a, b;   int Y1[100005], Y2[100005], L[100005];   double dist(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   double f(int i, int j) {     return dist(0, 0, a, Y1[i]) + L[j] + dist(a, Y1[i], b, Y2[j]);   }   int main() {     int t, i, j, c, d, idx1, idx2, m, n, idx;     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &a);     scanf( %d , &b);     for (i = 0; i < n; i++) scanf( %d , &Y1[i]);     for (i = 0; i < m; i++) scanf( %d , &Y2[i]);     for (i = 0; i < m; i++) scanf( %d , &L[i]);     for (i = 0; i < m; i++) {       int low = 0, high = n - 1;       while (high - low >= 3) {         int m1 = low + (high - low) / 3;         int m2 = high - (high - low) / 3;         if (f(m1, i) < f(m2, i))           high = m2;         else           low = m1;       }       double mini = 1000000000000;       for (j = low; j <= high; ++j) {         if (f(j, i) < mini) {           mini = f(j, i);           idx = j;         }       }       if (mini < gmin) {         gmin = mini;         idx1 = idx + 1;         idx2 = i + 1;       }     }     printf( %d  , idx1);     printf( %d  , idx2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     char s[110];     int x[30];   } a[2010];   int len, k, n;   int main() {     scanf( %d , &k);     scanf( %s , a[1].s);     len = strlen(a[1].s);     memset(a[1].x, 0, sizeof(a[1].x));     for (int i = 0; i < len; i++) a[1].x[a[1].s[i] -  a ]++;     for (int i = 2; i <= k; i++) a[i] = a[i - 1];     scanf( %d , &n);     while (n--) {       int p;       char c;       scanf( %d %c , &p, &c);       int i = 1;       while (p - a[i].x[c -  a ] > 0) {         p -= a[i].x[c -  a ];         i++;       }       for (int j = 0; j < len; j++)         if (a[i].s[j] == c) {           p--;           if (p == 0) {             a[i].s[j] =  ! ;             a[i].x[c -  a ]--;             break;           }         }     }     for (int i = 1; i <= k; i++)       for (int j = 0; j < len; j++)         if (a[i].s[j] !=  ! ) printf( %c , a[i].s[j]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int a[200010];   int main() {     int n = read();     int fen = 0, gu = 0;     for (int i = 1; i <= n; i++) a[i] = read();     bool ok = 1;     for (int i = 2; i <= n; i++) {       if (a[i] == a[i - 1]) ok = 0;     }     if (ok == 0) {       printf( NO );       return 0;     }     for (int i = 2; i <= n - 1; i++) {       if (a[i - 1] < a[i] && a[i] > a[i + 1])         fen++;       else if (a[i - 1] > a[i] && a[i + 1] > a[i])         gu++;     }     if (fen <= 1 && gu == 0)       printf( YES );     else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inft = 1000000009;   const int MAXN = 2000006;   bool P[MAXN];   int SP[MAXN];   int PAL[MAXN];   char S[123];   bool pal(int a) {     sprintf(S,  %d , a);     reverse(S, S + strlen(S));     int q;     sscanf(S,  %d , &q);     return a == q;   }   int main() {     for (int i = 0; i < (MAXN); ++i) P[i] = 1;     for (int i = 2; i < MAXN; ++i)       if (P[i])         for (int j = 2 * i; j < MAXN; j += i) P[j] = 0;     P[0] = P[1] = 0;     for (int i = 0; i < (MAXN); ++i)       if (i) SP[i] = SP[i - 1] + P[i];     for (int i = 1; i < MAXN; ++i) PAL[i] = PAL[i - 1] + pal(i);     int ret = 0;     int p, q;     scanf( %d%d , &p, &q);     for (int i = 0; i < (MAXN); ++i)       if (i && q * SP[i] <= p * PAL[i]) ret = i;     if (ret)       printf( %d n , ret);     else       printf( Palindromic tree is better than splay tree n );     return 0;   }
#include <bits/stdc++.h>   int main() {     char s[1000000], c;     int x = 0, y = 0, sum = 0, d;     scanf( %d , &d);     for (int i = 0; i < d; i++) {       scanf(  %c , &c);       s[i] = c;     }     for (int i = 0; i < strlen(s); i++) {       if (s[i] ==  L ) x--;       if (s[i] ==  R ) y++;     }     for (int i = x; i <= y; i++) {       sum++;     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print(int x, int b) {     if (x) {       print(x / b, b);       printf( %d , x % b);     }   }   int main() {     int k;     cin >> k;     for (int i = (1); i <= (k - 1); ++i)       for (int j = (1); j <= (k - 1); ++j)         print(i * j, k), printf( %c , j == k - 1 ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   bool possible(long long p, long long q, long long x, long long y) {     if (q < y) {       return false;     }     if (p < x) {       return false;     }     return q - y >= p - x;   }   int main() {     int t;     cin >> t;     while (t--) {       long long x, y, p, q;       cin >> x >> y >> p >> q;       long long l = 1, r = 1000000000;       while (l < r) {         long long mid = (l + r) / 2;         if (possible(mid * p, mid * q, x, y)) {           r = mid;         } else {           l = mid + 1;         }       }       if (possible(l * p, l * q, x, y)) {         cout << l * q - y << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     int i, j;     unsigned long long n, result, a[10];     a[0] = 0;     a[1] = 9;     for (i = 2; i <= 9; i++) a[i] = a[i - 1] * 10 + 9;     scanf( %llu , &n);     result = 0;     i = 9;     ;     while (n < a[i]) i--;     result = result + (n - a[i]) * (i + 1);     for (j = 1; j <= i; j++) result = result + (a[j] - a[j - 1]) * j;     printf( %llu , result);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream f( date.in );   queue<long long> q;   long long n, k, fr[1000001];   long long GCD(long long x, long long y) {     long long r;     do {       r = x % y;       x = y;       y = r;     } while (y != 0);     return x;   }   int main() {     long long ans;     cin >> n >> k;     ans = k;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       ans = GCD(x, ans);     }     cout << k / ans <<   n ;     for (int i = 0; i < k / ans; i++) cout << i * ans <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1000000], k, cnt, ans;   int main() {     cin >> n;     a[0] = 1;     a[1] = 1;     a[2] = 0;     for (int i = 1; i < n; i++) {       if (a[i] == 0) {         for (int j = i * i; j <= n; j += i) {           a[j] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       cnt = 0;       for (int j = i; j > 0; j--) {         if (i % j == 0) {           k = i / j;         } else {           continue;         }         if (a[k] == 0) {           cnt++;         }       }       if (cnt == 2) {         ans++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string p;     getline(cin, p);     bool f = 0;     for (int i = 0; i < p.size(); i++) {       if (p[i] >=  a  && p[i] <=  z ) {         if (p[i] ==  a  || p[i] ==  i  || p[i] ==  u  || p[i] ==  e  ||             p[i] ==  o  || p[i] ==  y )           f = 1;         else           f = 0;       }       if (p[i] >=  A  && p[i] <=  Z ) {         if (p[i] ==  A  || p[i] ==  I  || p[i] ==  U  || p[i] ==  E  ||             p[i] ==  O  || p[i] ==  Y )           f = 1;         else           f = 0;       }     }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long summ(long long n) { return (n * (n + 1)) / 2; }   long long sear(long long n, long long k) {     if (n == 1 && k == 1) return 0;     long long lo = 0, hi = n, mid;     long long sum, eaten;     while (lo <= hi) {       mid = lo + (hi - lo) / 2;       sum = summ(n - mid);       if (mid + k == sum)         return mid;       else if (mid + k > sum)         hi = mid - 1;       else         lo = mid + 1;     }     return mid;   }   int main() {     long long n, k;     cin >> n >> k;     if (n == 1 && k == 1) {       cout << 0 << endl;       return 0;     }     long long ans = sear(n, k);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long query(long long t, long long i, long long j, long long k) {     cout << t <<     << i <<     << j <<     << k <<     <<   n ;     cout.flush();     long long res;     cin >> res;     return res;   }   void solve() {     long long n;     cin >> n;     long long t1 = 1;     long long oo = 5e18;     vector<pair<long long, long long>> area(n + 1, {-oo, -1});     for (long long i = 1; i <= n; ++i) area[i].second = i;     long long t2 = 2;     for (long long i = 3; i <= n; ++i) {       long long q2 = query(2, t1, t2, i);       t2 = (q2 > 0 ? t2 : i);     }     long long mid = 3, max_s = 0;     for (long long i = 2; i <= n; ++i) {       if (i == t2) continue;       long long q1 = query(1, t1, t2, i);       area[i].first = q1;       if (q1 > max_s) {         max_s = q1;         mid = i;       }     }     area[mid].first = 0;     for (long long i = 2; i <= n; ++i) {       if (i == t2 || i == mid) continue;       long long q2 = query(2, t1, mid, i);       if (q2 > 0) area[i].first = oo - area[i].first;       if (q2 < 0) area[i].first = -oo + area[i].first;     }     sort(area.begin() + 1, area.end());     cout <<  0  ;     for (long long i = 1; i <= n; ++i)       cout << area[i].second << (i == n ?   n  :    );   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, centru;   int l[10];   int r[10];   int vars(int i, int tip) {     if (!tip) {       if (l[i] <= centru && centru <= r[i])         return centru - l[i];       else if (r[i] < centru)         return r[i] - l[i] + 1;       return 0;     } else if (tip == 1)       return ((bool)(l[i] <= centru && centru <= r[i]));     else {       if (l[i] <= centru && centru <= r[i])         return r[i] - centru;       else if (centru < l[i])         return r[i] - l[i] + 1;       return 0;     }   }   int tip[10];   int _s[3];   double sum;   void backtr(int poz) {     if (poz == (n + 1)) {       if (!_s[1]) return;       if (_s[2] >= 2) return;       if (_s[2] == 0) {         if (_s[1] == 1) return;       }       double prod = 1;       for (int i = 1; i <= n; i++) prod *= vars(i, tip[i]);       sum += centru * prod;       return;     }     for (int i = 0; i < 3; i++) {       _s[i]++;       tip[poz] = i;       backtr(poz + 1);       _s[i]--;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];     for (int i = 1; i <= 10000; i++) {       centru = i;       backtr(1);     }     for (int i = 1; i <= n; i++) {       sum /= (r[i] - l[i] + 1);     }     cout << fixed << setprecision(12) << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T abs(T &a) {     return a > 0 ? a : -a;   }   template <class T>   inline T min(T &a, T &b) {     return a < b ? a : b;   }   template <class T>   inline T max(T &a, T &b) {     return a > b ? a : b;   }   inline void read(int &x) {     char ch;     while ((ch = getchar()) && !(ch >=  0  && ch <=  9 ))       ;     x = ch -  0 ;     while ((ch = getchar()) && (ch >=  0  && ch <=  9 )) x = x * 10 + ch -  0 ;   }   const int N = 2000002;   int n, m, w[N], ans[N], dy[N], T = 1, t[N << 2];   void add(int x, int c) {     for (t[x += T] += c, x >>= 1; x; x >>= 1) t[x] = t[x << 1] + t[(x << 1) + 1];   }   int find(int k, int l, int r) {     int x = 1;     while (l < r) {       int mid = l + r >> 1;       if (t[x << 1] >= k)         x = x << 1, r = mid;       else         k -= t[x << 1], x = x << 1 | 1, l = mid + 1;     }     return l;   }   int main() {     read(n);     read(m);     int Len = n + m, gs = 0;     while (T < Len) T <<= 1, gs++;     T--;     for (int i = m + 1; i <= n + m; i++) w[i] = i - m, add(i, 1);     int x, y;     for (int i = m; i >= 1; i--) {       read(x);       read(y);       int p = find(y, 1, T + 1);       w[i] = w[p];       add(i, 1);       add(p, -1);       if (ans[w[i]] && ans[w[i]] != x) {         puts( -1 );         return 0;       }       ans[w[i]] = x;       if (dy[x] && dy[x] != w[i]) {         puts( -1 );         return 0;       }       dy[x] = w[i];     }     int j = 1;     for (int i = 1; i <= n; i++) {       if (ans[i])         printf( %d  , ans[i]);       else {         for (; dy[j]; j++)           ;         printf( %d  , j++);       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005];   map<long long, int> mp;   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long n;       scanf( %lld , &n);       long long sum = 0;       mp.clear();       for (int i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         sum += a[i];       }       long long res = 0;       for (int i = 1; i <= n; i++) {         res += mp[2 * sum - n * a[i]];         mp[n * a[i]]++;       }       printf( %lld n , res);     }   }