malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int arr[1001];   int main() {     int n, m, c;     cin >> n >> m >> c;     fill(arr, arr + n + 1, -1);     int mid = (c + 1) / 2;     bool done = 0;     for (int j = 0; !done && j < m; j++) {       int x;       cin >> x;       if (x > mid) {         for (int i = n; i >= 1; i--) {           if (arr[i] == -1 || arr[i] < x) {             arr[i] = x;             cout << i << endl;             break;           }         }       } else {         for (int i = 1; i <= n; i++) {           if (arr[i] == -1 || arr[i] > x) {             arr[i] = x;             cout << i << endl;             break;           }         }       }       done = 1;       for (int i = 1; done && i <= n; i++) {         if (arr[i] == -1) {           done = 0;           break;         }         if (i < n && arr[i + 1] == -1) {           done = 0;           break;         }         if (i < n && arr[i] > arr[i + 1]) {           done = 0;           break;         }       }     }     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     unsigned long long a[n], M;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     stack<unsigned long long> s;     M = *max_element(a, a + n);     for (int i = 0; i < n; ++i) {       a[i] = (M - a[i]) % 2;       if (s.empty() || s.top() != a[i])         s.push(a[i]);       else         s.pop();     }     bool ans2 = false;     for (int i = 0; i < n - 1 && !ans2; ++i) {       ans2 = ans2 || (a[i] == a[i + 1]);     }     bool all1 = true, all0 = true;     while (!s.empty()) {       all0 = all0 && (s.top() == 0);       all1 = all1 && (s.top() == 1);       s.pop();     }     bool ans = all0 || all1;     cout << (ans ?  YES  :  NO ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, a[100005], l, r;   string s;   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(0), cin.tie(NULL);     ;     cin >> n;     for (__typeof(i) i = 0; i < n; ++i) {       cin >> a[i];     }     cin >> s;     l = -1000000000;     r = 1000000000;     int cur = 0;     int m = 0;     for (__typeof(i) i = 4; i < n; ++i) {       if (s[i] -  0  != cur) {         if (cur) {           m = INT_MAX;           for (__typeof(j) j = -4; j <= 0; ++j) {             m = min(m, a[i + j]);           }           r = min(r, m - 1);           cur = 0;         } else {           m = INT_MIN;           for (__typeof(j) j = -4; j <= 0; ++j) {             m = max(m, a[i + j]);           }           l = max(l, m + 1);           cur = 1;         }       }     }     cout << l <<     << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, x, y, z, m, n, ans;   string s, a;   int ara[10];   int main() {     cin >> a >> s;     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  0 ;       ara[x]++;     }     for (int i = 0; i < a.size(); i++) {       int x = a[i] -  0 ;       for (int j = 9; j > x; j--) {         if (ara[j]) {           ara[j]--;           a[i] =  0  + j;           break;         }       }     }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long int n, k;   bool prime[10000001];   vector<long int> v;   void sieve(long int n) {     prime[0] = false;     prime[1] = false;     long int m = (long int)sqrt(n);     for (long int i = 2; i <= m; i++)       if (prime[i])         for (long int k = i * i; k <= n; k += i) prime[k] = false;   }   int main() {     long int i, j, a, b, c;     scanf( %ld %ld , &n, &k);     memset(prime, true, sizeof(prime));     a = 1000 * 1000;     sieve(a);     for (i = 1; i <= a; i++) {       if (prime[i] == true) {         v.push_back(i);       }     }     if (k == 0 && n == 1) {       printf( 1 );     } else if (n < 2) {       printf( -1 );     } else {       if (n % 2 == 1) {         a = (n - 1) / 2;       } else {         a = n / 2;       }       if (a > k) {         printf( -1 );       } else if (a == k) {         i = 1;         vector<long int>::iterator it;         for (it = v.begin(); it != v.end() && (i <= a); ++it) {           if (*it == 2) {             continue;           } else {             printf( %ld %ld  , *it, *it + 1);             i++;           }         }         if (n % 2 == 1) {           printf( %ld , *it);         }       } else {         b = k - (a - 1);         printf( %ld %ld  , b, 2 * b);         i = 1;         vector<long int>::iterator it;         for (it = v.begin(); it != v.end() && (i < a); ++it) {           if (*it == 2) {             continue;           }           if ((*it == b) || ((*it + 1) == b) || ((*it + 1) == (2 * b))) {             continue;           } else {             printf( %ld %ld  , *it, *it + 1);             i++;           }         }         if (n % 2 == 1) {           while ((*it == b) || ((*it + 1) == b) || ((*it + 1) == (2 * b))) {             ++it;           }           printf( %ld , *it);         }       }     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e5 + 5, lim = 62, maxm = 65;   const long long inf = 1e18;   template <typename T>   inline T min(T a, T b) {     return a < b ? a : b;   }   int n;   long long a[maxn], mod, dp[maxm][maxn];   inline bool Comp(long long a, long long b) { return a > b; }   void radix_sort() {     std::vector<long long> bit[2];     for (int i = 1; i <= n; i++) {       bit[(a[i] & (1ll << (mod - 1))) > 0ll].push_back(a[i]);     }     int cnt = 0;     for (int i = 0; i < bit[1].size(); i++) a[++cnt] = bit[1][i];     for (int i = 0; i < bit[0].size(); i++) a[++cnt] = bit[0][i];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     std::sort(a + 1, a + n + 1, Comp);     for (int i = n; i >= 1; i--) a[i] = a[1] - a[i];     for (int i = 0; i <= lim; i++)       for (int j = 0; j <= n; j++) dp[i][j] = inf;     dp[0][0] = 0;     for (int i = 0; i < lim; i++) {       mod = i;       if (i) radix_sort();       long long cnt = 0, tot = 0;       mod = 1ll << i;       for (int j = 1; j <= n; j++) cnt += a[j] & mod ? 1 : 0;       for (int j = 0; j <= n; j++) {         tot += a[j] & mod ? 1 : 0;         dp[i + 1][cnt - tot + j] =             min(dp[i + 1][cnt - tot + j], dp[i][j] + tot + (n - j) - (cnt - tot));         dp[i + 1][tot] = min(dp[i + 1][tot], dp[i][j] + j - tot + cnt - tot);       }     }     printf( %lld n , dp[lim][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 5;   int n;   int s[N], c[N];   map<int, int> a, b;   int main() {     int i;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &s[i]);       c[i] = s[i];     }     printf( YES n );     if (n == 1) {       printf( 0 n%d n , s[0]);       return 0;     }     sort(c, c + n);     int m = (n + 2) / 3;     for (i = 0; i < n; i++) {       if (i < m) {         a[c[i]] = 0;         b[c[i]] = c[i];       } else if (i < m + m) {         a[c[i]] = c[i];         b[c[i]] = 0;       } else {         a[c[i]] = n - (i + 1);         b[c[i]] = c[i] - (n - (i + 1));       }     }     for (i = 0; i < n; i++) {       printf( %d , a[s[i]]);       if (i == n - 1)         printf(  n );       else         printf(   );     }     for (i = 0; i < n; i++) {       printf( %d , b[s[i]]);       if (i == n - 1)         printf(  n );       else         printf(   );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 5;   long long a[maxn];   map<long long, long long> mp, show;   int main() {     long long n, k, ans = 0;     scanf( %lld%lld , &n, &k);     for (int i = 0; i < n; i++) scanf( %lld , a + i);     for (int i = n - 1; i >= 0; i--) {       ans += mp[a[i]];       if (a[i] % k == 0) mp[a[i] / k] += show[a[i] * k];       show[a[i]]++;     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 200010, LOG = 20;   int n, m, k, u, v, x, y, t, a, b;   long long A[MAXN];   int par[MAXN][LOG];   long long dist[MAXN][LOG];   int ans[MAXN];   vector<int> G[MAXN];   void dfs(int node) {     for (int i = 1; i < LOG; i++) par[node][i] = par[par[node][i - 1]][i - 1];     for (int i = 1; i < LOG; i++)       dist[node][i] =           min(1ll * inf, dist[par[node][i - 1]][i - 1] + dist[node][i - 1]);     for (int v : G[node]) {       dfs(v);       ans[node] += ans[v];     }     ans[par[node][0]]++;     long long v = node, tmp = A[node];     for (int i = LOG - 1; i >= 0; i--)       if (dist[v][i] <= tmp) {         tmp -= dist[v][i];         v = par[v][i];       }     v = par[v][0];     ans[v]--;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 2; i <= n; i++) {       cin >> par[i][0] >> dist[i][0];       G[par[i][0]].push_back(i);     }     par[1][0] = 0;     dfs(1);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, a[100011], sum[100011], ans;   map<long long, long long> mp;   signed main() {     scanf( %lld , &t);     while (t--) {       mp.clear();       scanf( %lld , &n);       memset(a, 0, sizeof a);       memset(sum, 0, sizeof sum);       ans = 0;       for (register long long i = 1; i <= n; ++i) {         a[i] = getchar() -  0 ;         while (a[i] < 0 || a[i] > 9) a[i] = getchar() -  0 ;         a[i] = (a[i]) ? a[i] - 1 : -1;         sum[i] = sum[i - 1] + a[i];       }       mp[0] = 1;       for (register long long i = 1; i <= n; ++i) {         ans += mp[sum[i]];         ++mp[sum[i]];       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int i, ans, j, t;     int num[2005];     while (scanf( %d%d , &n, &k) != EOF) {       ans = 0;       for (i = 0; i < n; i++) scanf( %d , &num[i]);       for (i = 0; i < n; i++)         for (j = 0; j < n - i - 1; j++)           if (num[j] > num[j + 1]) {             t = num[j];             num[j] = num[j + 1];             num[j + 1] = t;           }       for (i = n - 1; i >= 0; i = i - k) ans += (num[i] - 1) * 2;       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 3e18 + 5;   int N;   long long pt[100005][3];   long long ans[3];   pair<long long, long long> gSeg[4];   void input() {     cin >> N;     for (int i = 0; i < (N); i++) cin >> pt[i][0] >> pt[i][1] >> pt[i][2];   }   inline long long mod2(long long x) { return (x % 2 + 2) % 2; }   bool check(long long v) {     for (int rem = 0; rem < (2); rem++) {       pair<long long, long long> seg[4];       for (int i = 0; i < (4); i++) {         seg[i].first = gSeg[i].first - v;         seg[i].second = gSeg[i].second + v;         if (mod2(seg[i].first) != rem) seg[i].first++;         if (mod2(seg[i].second) != rem) seg[i].second--;       }       int fail = 0;       for (int i = 0; i < (4); i++)         if (seg[i].first > seg[i].second) {           fail = 1;         }       if (fail) continue;       if (seg[0].second < seg[1].first + seg[2].first + seg[3].first) continue;       if (seg[0].first > seg[1].second + seg[2].second + seg[3].second) continue;       long long sum = seg[1].first + seg[2].first + seg[3].first;       for (int i = (1); i <= (3); i++) {         if (sum >= seg[0].first) break;         if (sum + seg[i].second - seg[i].first < seg[0].first) {           sum += seg[i].second - seg[i].first;           seg[i].first = seg[i].second;         } else {           seg[i].first += seg[0].first - sum;           if (mod2(seg[i].first) != rem) seg[i].first++;           if (seg[i].first > seg[i].second) {             seg[i].first--;             sum--;           } else {             break;           }         }       }       ans[0] = (seg[2].first + seg[3].first) / 2;       ans[1] = (seg[1].first + seg[3].first) / 2;       ans[2] = (seg[1].first + seg[2].first) / 2;       assert(mod2(seg[2].first + seg[3].first) == 0);       assert(mod2(seg[1].first + seg[3].first) == 0);       assert(mod2(seg[1].first + seg[2].first) == 0);       return true;     }     return false;   }   void solve() {     for (int i = 0; i < (4); i++) gSeg[i] = pair<long long, long long>(-INF, INF);     for (int i = 0; i < (N); i++) {       long long x = pt[i][0];       long long y = pt[i][1];       long long z = pt[i][2];       gSeg[0].first = max(gSeg[0].first, x + y + z);       gSeg[0].second = min(gSeg[0].second, x + y + z);       gSeg[1].first = max(gSeg[1].first, -x + y + z);       gSeg[1].second = min(gSeg[1].second, -x + y + z);       gSeg[2].first = max(gSeg[2].first, x - y + z);       gSeg[2].second = min(gSeg[2].second, x - y + z);       gSeg[3].first = max(gSeg[3].first, x + y - z);       gSeg[3].second = min(gSeg[3].second, x + y - z);     }     long long l = 0, r = 4e18 + 5;     while (l < r) {       long long m = (l + r) / 2;       if (check(m))         r = m;       else         l = m + 1;     }     assert(check(l));     cout << ans[0] <<     << ans[1] <<     << ans[2] <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int ts;     cin >> ts;     for (int t = 0; t < (ts); t++) {       input();       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, sum;   string a;   int main() {     cin >> a;     int l = a.size();     j = 0;     for (i = 0; i < l; i++) {       if (a[i] ==  a ) {         k++;       }     }     if (k > l / 2) {       j = l;     } else {       for (i = l - 1; i > 0; i--) {         if (k > i / 2) {           j = i;           break;         }       }     }     cout << j << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     scanf( %d , &n);     printf( %d n , n + n / 2);     for (i = 2; n >= i; i = i + 2) {       printf( %d  , i);     }     for (i = 1; n >= i; i = i + 2) {       printf( %d  , i);     }     for (i = 2; n >= i; i = i + 2) {       printf( %d  , i);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void cp() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   int main() {     cp();     {       long long a;       cin >> a;       ;       long long b;       cin >> b;       ;       if (a == b)         cout <<  0 ;       else {         long long y = log2(a ^ b) + 1;         cout << power(2, y) - 1;       }     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int first) { cerr << first; }   void __print(long first) { cerr << first; }   void __print(long long first) { cerr << first; }   void __print(unsigned first) { cerr << first; }   void __print(unsigned long first) { cerr << first; }   void __print(unsigned long long first) { cerr << first; }   void __print(float first) { cerr << first; }   void __print(double first) { cerr << first; }   void __print(long double first) { cerr << first; }   void __print(char first) { cerr <<      << first <<     ; }   void __print(const char *first) { cerr <<     << first <<    ; }   void __print(const string &first) { cerr <<     << first <<    ; }   void __print(bool first) { cerr << (first ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &first) {     cerr <<  { ;     __print(first.first);     cerr <<  , ;     __print(first.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &first) {     int f = 0;     cerr <<  { ;     for (auto &i : first) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long a[n + 1];     for (long long i = 1; i < n + 1; i++) cin >> a[i];     vector<long long> b;     b.push_back(0), b.push_back(0);     for (long long i = 1; i < n + 1; i++) b.push_back(a[i]);     for (long long i = 1; i < n + 1; i++) b.push_back(a[i]);     ;     vector<long long> dp(b.size());     for (long long i = 2; i < b.size(); i++) dp[i] = dp[i - 2] + b[i];     ;     long long best = 0;     for (long long i = 2; i < b.size(); i++) {       if (i + n - 1 >= b.size()) break;       best = max(best, dp[i + n - 1] - dp[i - 2]);     }     cout << best <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   int main() {     int n;     int d = 210;     cin >> n;     if (n < 3) {       cout << -1 << endl;       return 0;     }     if (n == 3) {       cout << 210 << endl;       return 0;     }     cout << 1;     int m = 1;     for (int i = 0; i < (n - 1); i++) {       m *= 10;       m %= 210;       if (i < n - 4) cout << 0;     }     int r = 210 - m;     if (r < 10)       cout << 00 << r << endl;     else if (r < 100)       cout << 0 << r << endl;     else       cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int main() {     long long p, k;     cin >> p >> k;     while (p) {       long long y = p % k;       if (y < 0) y += k;       v.push_back(y);       p -= y;       p /= k;       p *= -1;     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::map;   using std::max;   using std::min;   using std::multiset;   using std::pair;   using std::queue;   using std::set;   using std::sort;   using std::stack;   using std::string;   using std::vector;   int main() {     string a, b, c;     cin >> a >> b >> c;     int dataA[26] = {         0,     };     int dataB[26] = {         0,     };     int dataC[26] = {         0,     };     for (int i = 0; i < a.size(); i++) {       dataA[a[i] -  a ]++;     }     for (int i = 0; i < b.size(); i++) {       dataB[b[i] -  a ]++;     }     for (int i = 0; i < c.size(); i++) {       dataC[c[i] -  a ]++;     }     int cntB = 0;     int cntC = 0;     for (int cnt = 0; cnt <= 100000; cnt++) {       int tempA[26];       for (int i = 0; i < 26; i++) {         tempA[i] = dataA[i];       }       int flag = 1;       for (int i = 0; i < 26; i++) {         long long t = (long long)tempA[i] - (long long)cnt * dataB[i];         tempA[i] -= cnt * dataB[i];         if (t < 0) {           flag = 0;         }       }       if (flag == 0) {         break;       }       int x = 1000000;       for (int i = 0; i < 26; i++) {         if (dataC[i] == 0) continue;         x = max(0, min(x, tempA[i] / dataC[i]));       }       if (cnt + x > cntB + cntC) {         cntB = cnt;         cntC = x;       }     }     for (int i = 0; i < 26; i++) {       dataA[i] -= cntB * dataB[i];       dataA[i] -= cntC * dataC[i];     }     for (int i = 0; i < cntB; i++) {       cout << b;     }     for (int i = 0; i < cntC; i++) {       cout << c;     }     for (int i = 0; i < 26; i++) {       for (int j = 0; j < dataA[i]; j++) printf( %c , i +  a );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   struct EDGE {     int num, next;   } e[MAXN * 2];   int en = 0, start[MAXN];   inline void Add_edge(int p, int q) {     en++;     e[en].num = q;     e[en].next = start[p];     start[p] = en;     en++;     e[en].num = p;     e[en].next = start[q];     start[q] = en;   }   double stp[MAXN], edp[MAXN];   int n;   bool u[MAXN];   int size[MAXN];   double sst[MAXN], pro[MAXN];   void dfs(int p) {     u[p] = true;     size[p] = 1;     sst[p] = stp[p];     for (int i = start[p]; i != 0; i = e[i].next)       if (!u[e[i].num]) {         dfs(e[i].num);         size[p] += size[e[i].num];         sst[p] += sst[e[i].num];         pro[p] += size[e[i].num] * sst[e[i].num];       }     pro[p] += (n - size[p]) * (1 - sst[p]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int p, q;       scanf( %d%d , &p, &q);       Add_edge(p, q);     }     double stps = 0, edps = 0;     for (int i = 1; i <= n; i++) scanf( %lf%lf , &stp[i], &edp[i]);     for (int i = 1; i <= n; i++) {       stps += stp[i];       edps += edp[i];     }     for (int i = 1; i <= n; i++) {       stp[i] /= stps;       edp[i] /= edps;     }     dfs(1);     double ans = 0;     for (int i = 1; i <= n; i++) ans += pro[i] * edp[i];     printf( %.11lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   bool graph[101][101];   bool traversed[101];   void search(int x) {     for (int i = 0; i <= m; i++)       if (graph[x][i])         for (int k = 0; k < n; k++)           if (graph[k][i] && !traversed[k]) {             traversed[k] = true;             search(k);           }   }   int main() {     cin >> n >> m;     int size, lang;     int need = 0;     int all = 0;     for (int i = 0; i < n; i++) {       cin >> size;       if (size == 0) all++;       for (int k = 0; k < size; k++) {         cin >> lang;         graph[i][lang] = true;       }     }     if (all == n)       cout << all << endl;     else {       for (int i = 0; i < n; i++) {         if (!traversed[i]) {           need++;           traversed[i] = true;           search(i);         }       }       cout << need - 1 << endl;     }     return 0;   }