malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -fhoist-adjacent-loads )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -fdelete-null-pointer-checks )   const int N = 105;   int f[N][N][N], n, m, q, Mod, C[N][N];   inline void Init() {     scanf( %d %d %d %d , &n, &m, &q, &Mod);     for (register int i = 0; i <= n; i++) {       C[i][0] = 1;       for (register int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;     }     return;   }   inline int Dfs(const int i, const int j, const int k) {     if (i < j) return 0;     if (j * 2 > i + 1) return 0;     if (f[i][j][k] != -1) return f[i][j][k];     f[i][j][k] = 0;     for (register int l = 0; l <= i - 1; l++)       for (register int w = 0; w <= j - (k == m); w++)         f[i][j][k] =             (f[i][j][k] + 1ll * C[i - 1][l] * Dfs(l, w, k + 1) % Mod *                               Dfs(i - l - 1, j - w - (k == m), k + 1) % Mod) %             Mod;     return f[i][j][k];   }   inline void Solve() {     memset(f, -1, sizeof(f));     memset(f[0], 0, sizeof(f[0]));     memset(f[1], 0, sizeof(f[1]));     for (register int k = 1; k <= n; k++) f[1][k == m][k] = f[0][0][k] = 1;     printf( %d n , Dfs(n, q, 1));     return;   }   int main() {     Init();     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int ans;     int a = abs(x1 - x2);     int b = abs(y1 - y2);     ans = max(a, b);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 335;   vector<vector<int> > B(NMAX);   int lastans, cnt[NMAX][100001];   int main() {     int N;     cin >> N;     int len = (int)ceil(sqrt(N + .0));     int num = 0, up = len;     for (int i = 0; i < N; i++) {       int a;       cin >> a;       if (i == up) {         up += len;         num++;       }       B[num].push_back(a);       cnt[num][a]++;     }     int M;     cin >> M;     for (int t = 0; t < M; t++) {       int type;       scanf( %d , &type);       if (type == 1) {         int l, r;         scanf( %d%d , &l, &r);         l = (l + lastans - 1) % N, r = (r + lastans - 1) % N;         if (l > r) swap(l, r);         int sum = 0, cur = 0;         for (int i = 0; i < NMAX; i++) {           if (r >= sum && r < sum + (int)B[i].size()) {             cur = B[i][r - sum];             B[i].erase(B[i].begin() + (r - sum));             cnt[i][cur]--;             break;           }           sum += (int)B[i].size();         }         sum = 0;         for (int i = 0; i < NMAX; i++) {           if (l >= sum && l < sum + (int)B[i].size()) {             B[i].insert(B[i].begin() + (l - sum), cur);             cnt[i][cur]++;             break;           }           sum += (int)B[i].size();         }       } else {         int l, r, k;         scanf( %d%d%d , &l, &r, &k);         l = (l + lastans - 1) % N, r = (r + lastans - 1) % N,         k = (k + lastans - 1) % N + 1;         if (l > r) swap(l, r);         int sum = 0, ans = 0;         for (int i = 0; i < NMAX; i++) {           if (sum >= l && sum + (int)B[i].size() - 1 <= r)             ans += cnt[i][k];           else if ((l >= sum && l < sum + (int)B[i].size()) ||                    (r >= sum && r < sum + (int)B[i].size())) {             for (int j = 0; j < (int)B[i].size(); j++) {               if (sum + j >= l && sum + j <= r && B[i][j] == k) ans++;             }           }           sum += (int)B[i].size();         }         lastans = ans;         printf( %d n , ans);       }       if (t % len == 0) {         vector<int> list;         for (int i = 0; i < NMAX; i++) {           for (int j = 0; j < (int)B[i].size(); j++) {             list.push_back(B[i][j]);             cnt[i][B[i][j]]--;           }           B[i].clear();         }         num = 0, up = len;         for (int i = 0; i < (int)list.size(); i++) {           if (i == up) {             num++;             up += len;           }           B[num].push_back(list[i]);           cnt[num][list[i]]++;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100000;   vector<int> g[MAX];   int k;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> k;     if (k % 2 == 0)       cout <<  NO n ;     else {       if (k == 1) {         cout <<  YES n ;         cout <<  2 1 n ;         cout <<  1 2 n ;         return 0;       }       cout <<  YES n ;       priority_queue<pair<int, int>, vector<pair<int, int>>,                      greater<pair<int, int>>>           q;       q.push({1, 0});       for (int i = 1; i < k + 2; i++) {         q.push({0, i});       }       int edges = 0;       while (q.size()) {         int e = q.top().first;         int m = q.top().second;         q.pop();         while (e < k) {           pair<int, int> aux = q.top();           q.pop();           if (aux.first < k) {             aux.first++;             q.push(aux);             g[m].push_back(aux.second);             e++;             edges++;           }         }       }       int n = k + 2;       cout << 2 * n <<     << (edges * 2) + 1 <<   n ;       cout <<  1   << n + 1 <<   n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < g[i].size(); j++) {           cout << i + 1 <<     << g[i][j] + 1 <<   n ;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < g[i].size(); j++) {           cout << (i + 1) + n <<     << (g[i][j] + 1) + n <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[] = {       1,          2,          4,          8,          16,          32,       64,         128,        256,        512,        1024,        2048,       4096,       8092,       16184,      32368,      64736,       129472,       258944,     517888,     1035776,    2071552,    4143104,     8286208,       16572416,   33144832,   66289664,   132579328,  265158656,   530317312,       1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968};   int main() {     int n;     scanf( %d , &n);     cout << a[n] << endl;   }
#include <bits/stdc++.h>   using namespace std;   char str[50][50];   bool test(int a, int b, int w, int h) {     int i, j;     for (i = 0; i <= w; i++) {       for (j = 0; j <= h; j++) {         if (str[i + a][j + b] ==  1 ) return 0;       }     }     return 1;   }   int main() {     int n, m, i, j, k, r;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %s , str[i]);     }     int ans = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         for (k = 0; k + i < n; k++) {           for (r = 0; r + j < m; r++) {             if (test(i, j, k, r)) {               if (2 * (k + r + 2) > ans) ans = 2 * (k + 2 + r);             }           }         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int d = 0;     if (b % a != 0) {       cout <<  -1 ;       return 0;     }     int c = b / a;     if (c == 1) {       cout <<  0 ;       return 0;     }     while (c != 0) {       if (c % 2 == 0) {         c = c / 2;         d++;       } else         break;     }     while (c != 0) {       if (c % 3 == 0) {         c = c / 3;         d++;       } else         break;     }     if (c == 1)       cout << d;     else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K;     cin >> N >> K;     int a[N], b[K];     int cnt = 0;     for (int i = (0); i < (N); i++) {       cin >> a[i];       if (a[i] == 0) cnt++;     }     if (cnt > K) {       cout <<  No n ;       return 0;     }     for (int i = (0); i < (K); i++) {       cin >> b[i];     }     sort(b, b + K);     reverse(b, b + K);     int ix = 0;     for (int i = (0); i < (N); i++) {       if (a[i] == 0) {         a[i] = b[ix++];       }     }     for (int i = (1); i < (N); i++) {       if (a[i - 1] > a[i]) {         cout <<  Yes n ;         return 0;       }     }     cout <<  No n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   long long int t, n, m, a[1000005] = {0}, d[1000005], b[1000005];   stack<long long int> s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, x, y;     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i < n; i++) d[i] = abs(a[i + 1] - a[i]);     for (i = 1; i < n; i++) {       while (!s.empty() && d[s.top()] < d[i]) s.pop();       a[i] = (s.empty()) ? 0 : s.top();       s.push(i);     }     while (!s.empty()) s.pop();     for (i = n - 1; i >= 1; i--) {       while (!s.empty() && d[s.top()] <= d[i]) s.pop();       b[i] = (s.empty()) ? n : s.top();       s.push(i);     }     while (m--) {       long long int l, r;       cin >> l >> r;       long long int ans = 0;       for (i = l; i < r; i++) {         x = i - max(a[i], l - 1);         y = min(b[i], r) - i;         ans += (x * y * d[i]);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int max0 = 50, maxn = 1000;   int n, first;   double p, q;   double a[maxn + 5][max0 + 5];   double b[maxn + 5][max0 + 5];   double dp[maxn + 5][max0 + 5];   int main() {     scanf( %d%d , &n, &first);     p = first / 1e9, q = 1 - p;     for (int i = (1), _end_ = (maxn + 1); i < _end_; ++i)       for (int j = (1), _end_ = (max0); j < _end_; ++j) {         if (j == 1) a[i][j] += p;         if (j == 2) a[i][j] += q, b[i][j] += q;         a[i][j] += a[i - 1][j - 1] * a[i][j - 1];         b[i][j] += a[i - 1][j - 1] * b[i][j - 1];       }     for (int i = maxn; i >= 1; --i)       for (int j = (1), _end_ = (max0); j < _end_; ++j)         a[i][j] *= 1 - a[i - 1][j], b[i][j] *= 1 - a[i - 1][j];     for (int i = (1), _end_ = (max0); i < _end_; ++i) dp[maxn][i] = i;     for (int i = maxn - 1; i >= 0; --i)       for (int j = (1), _end_ = (max0); j < _end_; ++j) {         double sum = 0;         for (int k = (1), _end_ = (max0); k < _end_; ++k) {           if (j == k) continue;           int pos = maxn - i;           if (j == 1)             dp[i][j] += b[pos][k] * dp[i + 1][k], sum += b[pos][k];           else if (j > k)             dp[i][j] += a[pos][k] * dp[i + 1][k], sum += a[pos][k];         }         (dp[i][j] /= sum) += j;       }     double ans = 0;     if (n <= maxn)       for (int i = (1), _end_ = (max0); i < _end_; ++i)         ans += a[n][i] * dp[maxn - n + 1][i];     else {       double sum0 = 0, sum1 = 0;       for (int i = (1), _end_ = (max0); i < _end_; ++i)         sum0 += a[maxn][i] * dp[0][i];       for (int i = (1), _end_ = (max0); i < _end_; ++i)         sum1 += a[maxn - 1][i] * dp[1][i];       ans = sum1 + (sum0 - sum1) * (n - maxn + 1);     }     printf( %.15f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g(300005);   int a[300005], s1[300005], s2[300005];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i(1); i <= n; i++) {       cin >> a[i];     }     for (int i(0); i < n - 1; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     long long mx = -1e15, kol = 0, kkol = 0, mxx = -1e15;     for (int i(1); i <= n; i++) {       if (a[i] > mx) {         if (mx + 1 == a[i]) {           mxx = mx;           kkol = kol;         } else {           mxx = a[i] - 1;           kkol = 0;         }         kol = 1;         mx = a[i];         continue;       }       if (a[i] == mx) kol++;       if (a[i] == mxx) kkol++;     }     for (int i(1); i <= n; i++) {       for (int j(0); j < g[i].size(); j++) {         if (a[g[i][j]] == mx)           s1[i]++;         else if (a[g[i][j]] == mxx)           s2[i]++;       }     }     long long ans = mx;     if (kol > 1) ans = mx + 1;     int ces = 0;     for (int i(1); i <= n; i++) {       if (s1[i] == kol - 1 && a[i] == mx && kol > 1) {         cout << mx + 1 << endl;         exit(0);       }       if (s1[i] == kol && kol > 1) {         cout << mx + 1 << endl;         return 0;       }       if (a[i] == mx && s1[i] > 1 && ces == 0) {         ans = max(ans, mx + 1);         ces = 1;         continue;       }       if (a[i] == mx && s1[i] > 1 && ces == 1) {         ans = max(ans, mx + 2);         continue;       }       if (s1[i] > 1 && ces == 0) {         ces = 1;         ans = max(mx + 1, ans);         continue;       }       if (s1[i] > 1 && ces == 1) {         ans = max(ans, mx + 2);         continue;       }       if (s2[i] > 0 && a[i] == mxx) {         ans = max(ans, mx + 1);         continue;       }       if (s1[i] == 1 && s2[i] > 0 && ces == 0) {         ans = max(ans, mx + 1);         ces = 1;         continue;       }       if (s1[i] == 1 && s2[i] > 0 && ces == 1) {         ans = max(ans, mx + 2);         continue;       }       if (s1[i] == 0 && kol > 1 && a[i] == mx) {         ans = max(ans, mx + 2);         ces = 1;         continue;       }       if (s1[i] == kol && s2[i] == 0 && kkol > 0 && a[i] != mx) {         ans = max(ans, mx + 1);         continue;       }       if (a[i] == mx && kol == 1 && s2[i] == kkol) {         cout << mx << endl;         exit(0);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int ailgis, bilgis;     cin >> a >> b;     ailgis = a.length();     bilgis = b.length();     if (a == b) {       cout <<  -1 ;       return 0;     }     if (ailgis > bilgis)       cout << ailgis;     else       cout << bilgis;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-10;   const double PI = acos(-1.0);   double tick() {     static clock_t oldtick;     clock_t newtick = clock();     double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC;     oldtick = newtick;     return diff;   }   template <typename T>   T mod(T a, T b) {     return (a < b ? a : a % b);   }   long long mulmod(long long a, long long b, long long m) {     long long q = (long long)(((long double)a * (long double)b) / (long double)m);     long long r = a * b - q * m;     if (r > m) r %= m;     if (r < 0) r += m;     return r;   }   template <typename T>   T expo(T e, T n) {     T x = 1, p = e;     while (n) {       if (n & 1) x = x * p;       p = p * p;       n >>= 1;     }     return x;   }   template <typename T>   T power(T e, T n, T m) {     T x = 1, p = e;     while (n) {       if (n & 1) x = mod(x * p, m);       p = mod(p * p, m);       n >>= 1;     }     return x;   }   template <typename T>   T powerL(T e, T n, T m) {     T x = 1, p = e;     while (n) {       if (n & 1) x = mulmod(x, p, m);       p = mulmod(p, p, m);       n >>= 1;     }     return x;   }   template <typename T>   T InverseEuler(T a, T m) {     return (a == 1 ? 1 : power(a, m - 2, m));   }   template <typename T>   T gcd(T a, T b) {     return __gcd(a, b);   }   template <typename T>   T lcm(T a, T b) {     return (a * (b / gcd(a, b)));   }   int a[55][55];   int ans[55];   bool v[55][55];   int main() {     int n;     scanf( %d , &n);     for (__typeof(1) i = 1; i <= n; ++i) {       for (__typeof(1) j = 1; j <= n; ++j) {         scanf( %d , &a[i][j]);         v[i][j] = false;       }     }     int first = 1, pos;     int reqd = n - 1;     for (__typeof(1) m = 1; m <= n - 1; ++m) {       pos = -1;       for (__typeof(1) i = 1; i <= n; ++i) {         int count = 0;         for (__typeof(1) j = 1; j <= n; ++j) {           if (a[i][j] == first && v[i][j] == false) {             count++;           }         }         if (count == reqd) {           pos = i;           ans[pos] = first;           first++;           reqd--;           for (__typeof(1) k = 1; k <= n; ++k) {             v[pos][k] = true;           }           for (__typeof(1) k = 1; k <= n; ++k) {             v[k][pos] = true;           }           break;         }       }       if (pos == -1) break;     }     for (__typeof(1) i = 1; i <= n; ++i) {       if (ans[i] == 0) {         ans[i] = first;         first++;       }     }     for (__typeof(1) i = 1; i <= n; ++i) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000033;   const long long p = 10007;   string s;   int n, k;   int A[1000005], pref[1000005];   long long P[1000005], H[1000005];   void go(int ind, int end) {     while (end <= n && s[end - ind] == s[end - 1]) end++;     pref[ind] = end - ind;   }   void f_pref() {     int ind = 1;     pref[1] = -1;     for (int i = 2; i <= n; i++) {       int l = i - ind + 1;       if (i < ind + pref[ind] && pref[l] + i < ind + pref[ind])         pref[i] = pref[l];       else {         go(i, max(ind + pref[ind], i));         ind = i;       }     }   }   void makehash() {     P[0] = 1;     for (int i = 1; i <= n; i++) P[i] = (P[i - 1] * p) % mod;     for (int i = 1; i <= n; i++) H[i] = (H[i - 1] * p + (int)s[i - 1]) % mod;   }   long long has(int p, int k) {     long long h = H[k] - (H[p - 1] * P[k - p + 1]) % mod;     if (h < 0) h += mod;     return h;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k >> s;     makehash();     f_pref();     for (int l = 1; l * k <= n; l++)       if (has(1, l * (k - 1)) == has(l + 1, l * k))         A[l * k] = max(A[l * k], 1 + min(l, pref[l * k + 1]));     int tmp = 0;     for (int i = 1; i <= n; i++) {       tmp = max(tmp, A[i]);       if (tmp != 0)         cout <<  1 ;       else         cout <<  0 ;       if (tmp != 0) tmp--;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     cout <<  + ;     for (int i = 0; i < 24; i++) cout <<  - ;     cout <<  + n ;     int r1 = (k + 1) / 3;     bool enough = 0;     int passenegrs = 0;     for (int i = 0; i < 27; i++) {       if (i == 0 || i == 23 || i == 25)         cout <<  | ;       else if (i == 24)         cout <<  D ;       else if (i == 26)         cout <<  ) ;       else if (i % 2 == 0)         cout <<  . ;       else {         if (passenegrs < r1 || k == 1 && !enough)           cout <<  O , passenegrs++;         else           cout <<  # ;         if (k == 1 || passenegrs == r1) enough = 1;       }     }     cout << endl;     int r2 = k / 3;     bool enough1 = 0;     int passenegrs1 = 0;     for (int i = 0; i < 26; i++) {       if (i == 0 || i == 23 || i == 25)         cout <<  | ;       else if (i % 2 == 0)         cout <<  . ;       else {         if ((passenegrs1 < r2 || k == 2) && !enough1)           cout <<  O , passenegrs1++;         else           cout <<  # ;         if (k == 2 || passenegrs1 == r2) enough1 = 1;       }     }     cout << endl;     bool r3 = 1;     for (int i = 0; i < 26; i++) {       if (i == 0 || i == 25)         cout <<  | ;       else if (i % 2 == 0)         cout <<  . ;       else {         if (k > 2 && r3)           cout <<  O , r3 = 0;         else if (i == 1)           cout <<  # ;         else           cout <<  . ;       }     }     cout << endl;     int r4 = (k - 1) / 3;     bool enough3 = 0;     int passenegrs3 = 0;     for (int i = 0; i < 27; i++) {       if (i == 0 || i == 23 || i == 25)         cout <<  | ;       else if (i == 26)         cout <<  ) ;       else if (i % 2 == 0)         cout <<  . ;       else {         if (passenegrs3 < r4 || k == 4 && !enough3)           cout <<  O , passenegrs3++;         else           cout <<  # ;         if (k == 4 || passenegrs3 == r4) enough3 = 1;       }     }     cout << endl;     cout <<  + ;     for (int i = 0; i < 24; i++) cout <<  - ;     cout <<  + ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) { return a > b; }   int main() {     long long n, m, i, j, k, t, a, b;     cin >> a >> b;     m = b - a;     if (m == 0) {       cout << 1 << endl;     } else {       if (m > 4) {         cout << 0 << endl;       } else {         n = 1;         for (i = a + 1; i <= b; i++) {           n = (n % 10 * i % 10) % 10;         }         cout << n << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     bool con = false;     for (int i = 1; i < 32000; i++) {       double M = 2 * n - i * (i + 1);       double k = (-1.0 + sqrtl(1 + 4 * M)) / 2.0;       if (k <= 0) break;       if (abs((long long int)k - k) <= 1e-9) {         con = true;         break;       }     }     if (con)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }