malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int pp(int x, int y) {     int i = 0;     int min = 1;     for (i = 0; i < y; i++) {       min = min * x;     }     return min;   }   int main() {     int n;     int a[100001];     int i, k, t, flag;     long long int min;     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++) {         cin >> a[i];       }       min = 0;       for (k = 1; k < n; k++) {         for (t = 0; k + pp(2, t) <= n; t++) {           flag = k + pp(2, t);         }         min = min + a[k];         a[flag] += a[k];         a[k] = 0;         cout << min << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, i, j;     cin >> t;     while (t--) {       long long n;       cin >> n;       set<long long> s;       s.insert(0);       s.insert(1);       for (i = sqrt(n); i > 0; i--) {         s.insert(n / i);         s.insert(i);       }       cout << s.size() <<   n ;       for (auto i = s.begin(); i != s.end(); i++) cout << *i <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int inf = 50000000;   const int maxn = 100010;   int check(vector<int> &v) {     int i, first, cur, j;     for (i = 0; i < v.size(); i++) {       first = j = 0;       cur = v[i];       while (j < 8) {         if (cur == 1) {           first = 1;           break;         }         cur = v[cur];         j++;       }       if (!first) return 0;     }     return 1;   }   int generator(vector<int> &v, int left, int k) {     if (left == 0) return check(v);     int i, ret = 0;     for (i = 1; i <= k; i++) {       v.push_back(i);       ret += generator(v, left - 1, k);       v.pop_back();     }     return ret;   }   long long modpow(long long a, long long b) {     long long x = 1, y = a;     while (b) {       if (b % 2) x = (x * y) % mod;       y = (y * y) % mod;       b /= 2;     }     return x;   }   long long temp[] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};   int main() {     int n, k;     scanf( %d , &n), scanf( %d , &k);     vector<int> v;     long long ans = temp[k];     ans = (ans * modpow(n - k, n - k)) % mod;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nBox, testC, iBox, nBird, A[109];   int main() {     scanf( %d , &nBox);     for (int i = 0; i < nBox; ++i) scanf( %d , &A[i]);     scanf( %d , &testC);     for (int i = 0; i < testC; ++i) {       scanf( %d%d , &iBox, &nBird);       --iBox;       if (iBox != 0) A[iBox - 1] += nBird - 1;       if (iBox != nBox - 1) A[iBox + 1] += A[iBox] - nBird;       A[iBox] = 0;     }     for (int i = 0; i < nBox; ++i) printf( %d n , A[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int calc(int x, int k) {     int SG;     if (k % 2 == 0) {       if (x >= 3)         SG = !(x % 2);       else         SG = x;     } else {       if (x >= 6) {         if (x % 2)           SG = 0;         else {           if (calc(x / 2, k) == 1)             SG = 2;           else             SG = 1;         }       } else {         if (x == 4)           SG = 2;         else if (x == 5)           SG = 0;         else           SG = x % 2;       }     }     return SG;   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int res = 0;     for (int i = 0; i < n; i++) {       res ^= calc(a[i], k);     }     puts(res > 0 ?  Kevin  :  Nicky );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     cout.tie(0);     int n, i;     cin >> n;     int a[n], f[105] = {0};     int m = 0;     for (i = 1; i <= n; i++) {       cin >> a[i];       f[a[i]]++;       if (f[a[i]] > m) m = f[a[i]];     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string a, b;       cin >> a;       cin >> b;       if (n == 1) {         if (a[0] ==  1  || a[0] ==  2 )           cout <<  NO n ;         else if (b[0] ==  1  || b[0] ==  2 )           cout <<  NO n ;         else           cout <<  YES n ;         continue;       }       a = a + b;       int i = 0;       bool dir = false;       while (i != 2 * n - 1) {         if (!dir) {           if (a[i] ==  1  || a[i] ==  2 ) {             i++;             if (i == n) break;             dir = false;           } else {             if (i < n)               i = i + n;             else               i = i - n;             dir = true;           }         } else {           if (a[i] ==  1  || a[i] ==  2 ) {             break;           } else {             i++;             dir = false;           }         }       }       if (i != 2 * n - 1)         cout <<  NO n ;       else {         if (!dir) {           if (a[i] ==  2  || a[i] ==  1 )             cout <<  YES n ;           else             cout <<  NO n ;         } else {           if (a[i] ==  2  || a[i] ==  1 )             cout <<  NO n ;           else             cout <<  YES n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000000007;   const long double PI = 2 * acos(0.0);   const vector<long long int> dx = {1, -1, 0, 0};   const vector<long long int> dy = {0, 0, 1, -1};   vector<long long int> ga(long long int n, bool oneIndexed = false) {     vector<long long int> a;     if (oneIndexed) a.push_back(0ll);     for (long long int i = 0; i < n; i++) {       long long int p;       cin >> p;       a.push_back(p);     }     return move(a);   }   vector<unsigned long long int> gau(unsigned long long int n,                                      bool oneIndexed = false) {     vector<unsigned long long int> a;     if (oneIndexed) a.push_back(0llu);     for (unsigned long long int i = 0; i < n; i++) {       unsigned long long int p;       cin >> p;       a.push_back(p);     }     return move(a);   }   vector<string> gas(unsigned long long int n, bool oneIndexed = false) {     vector<string> a;     if (oneIndexed) a.push_back(  );     for (unsigned long long int i = 0; i < n; i++) {       string p;       cin >> p;       a.push_back(p);     }     return move(a);   }   template <typename T, typename A>   void pa(vector<T, A> const &a, long long int begin = 0,           long long int end = -1) {     if (end == -1) end = a.size() - 1;     for (long long int i = begin; i <= end; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   template <typename T, typename A>   void papair(vector<T, A> const &a, long long int begin = 0,               long long int end = -1) {     if (end == -1) end = (long long int)a.size() - 1;     for (long long int i = begin; i <= end; i++) {       cout << a[i].first <<     << a[i].second <<   n ;     }     cout <<   n ;   }   void yes() { cout <<  YES n ; }   void no() { cout <<  NO n ; }   void yesno(int f) {     if (f)       yes();     else       no();   }   void solve() {     long long int n;     cin >> n;     vector<pair<long long int, long long int>> edges;     long long int p1 = n / 2, p2 = n / 2;     if (p1 + p2 < n) p2++;     for (long long int i = 1; i <= p1; i++) {       for (long long int j = p1 + 1; j <= n; j++) {         edges.push_back({i, j});       }     }     cout << (long long int)edges.size();     cout <<   n ;     papair(edges);   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   vector<long long> G[500005];   long long t1, d1, t2, d2;   long long dis1[500005], dis2[500005];   long long inp[500005], in[500005];   stringstream ss;   void dfs1(long long u, long long fa, long long d) {     if (d > d1) {       d1 = d;       t1 = u;     }     for (long long i = 0; i < G[u].size(); i++) {       if (G[u][i] == fa) continue;       dfs1(G[u][i], u, d + 1);     }   }   void dfs2(long long u, long long fa, long long d) {     if (d > d2) {       d2 = d;       t2 = u;     }     dis1[u] = d;     for (long long i = 0; i < G[u].size(); i++) {       if (G[u][i] == fa) continue;       dfs2(G[u][i], u, d + 1);     }   }   void dfs3(long long u, long long fa, long long d) {     dis2[u] = d;     for (long long i = 0; i < G[u].size(); i++) {       if (G[u][i] == fa) continue;       dfs3(G[u][i], u, d + 1);     }   }   void findpath(long long u, long long fa, long long t) {     inp[u] = true;     if (u == t) {       memcpy(in, inp, sizeof inp);       return;     }     for (long long i = 0; i < G[u].size(); i++) {       if (G[u][i] == fa) continue;       findpath(G[u][i], u, t);     }     inp[u] = false;   }   long long ans;   bool del[500005];   long long deg[500005];   void dfs4(long long u, long long fa) {     del[u] = true;     if ((dis1[u] > dis2[u] || del[t2]) && !del[t1]) {       ans += dis1[u];       ss << t1 <<     << u <<     << u << endl;     } else if (!del[t2]) {       ans += dis2[u];       ss << t2 <<     << u <<     << u << endl;     }     for (long long i = 0; i < G[u].size(); i++) {       if (G[u][i] == fa) continue;       if (in[G[u][i]]) dfs4(G[u][i], u);     }   }   signed main() {     cin >> n;     for (long long i = 1; i <= n - 1; i++) {       long long u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);       deg[u]++;       deg[v]++;     }     dfs1(1, 0, 0);     dfs2(t1, 0, 0);     dfs3(t2, 0, 0);     findpath(t1, 0, t2);     queue<long long> Q;     for (long long i = 1; i <= n; i++) {       if (deg[i] == 1) Q.push(i);     }     while (Q.size()) {       long long i = Q.front();       Q.pop();       if (in[i]) continue;       if (del[i]) continue;       del[i] = true;       if (dis1[i] > dis2[i]) {         ans += dis1[i];         ss << t1 <<     << i <<     << i << endl;       } else {         ans += dis2[i];         ss << t2 <<     << i <<     << i << endl;       }       for (long long j = 0; j < G[i].size(); j++) {         deg[G[i][j]]--;         if (deg[G[i][j]] == 1) Q.push(G[i][j]);       }     }     dfs4(t1, 0);     cout << ans << endl;     cout << ss.str() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct segtree {     int size = 1;     vector<pair<int, int>> v;     vector<pair<int, int>> lazy;     void init(int n) {       while (n > size) {         size *= 2;       }       v.assign(size * 2, {0, -1});       lazy.assign(size * 2, {0, -1});     }     void prop(int x, int lx, int rx) {       if (rx - lx == 1) return;       if (lazy[x] == make_pair(0, -1)) return;       v[x * 2 + 1] = lazy[x];       v[x * 2 + 2] = lazy[x];       lazy[x * 2 + 1] = lazy[x];       lazy[x * 2 + 2] = lazy[x];       lazy[x] = {0, -1};     }     void update(int l, int r, pair<int, int> val, int x, int lx, int rx) {       prop(x, lx, rx);       if (rx <= l || lx >= r) {         return;       }       if (lx >= l && rx <= r) {         v[x] = val;         lazy[x] = val;         return;       }       int m = (lx + rx) / 2;       update(l, r, val, x * 2 + 1, lx, m);       update(l, r, val, x * 2 + 2, m, rx);       v[x] = max(v[x * 2 + 1], v[x * 2 + 2]);     }     void update(int l, int r, pair<int, int> val) {       update(l, r + 1, val, 0, 0, size);     }     pair<int, int> get(int l, int r, int x, int lx, int rx) {       prop(x, lx, rx);       if (rx <= l || lx >= r) {         return {0, -1};       }       if (lx >= l && rx <= r) {         return v[x];       }       int m = (lx + rx) / 2;       pair<int, int> m1 = get(l, r, x * 2 + 1, lx, m);       pair<int, int> m2 = get(l, r, x * 2 + 2, m, rx);       return max(m1, m2);     }     pair<int, int> get(int l, int r) { return get(l, r + 1, 0, 0, size); }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     set<int> s;     vector<vector<pair<int, int>>> v(n);     vector<tuple<int, int, int>> actions;     for (int i = 0; i < m; i++) {       int j, l, r;       cin >> j >> l >> r;       j--;       actions.push_back({j, l, r});       s.insert(l);       s.insert(r);       v[j].push_back(make_pair(l, r));     }     auto s1 = s.begin();     auto s2 = s.begin();     if (s2 != s.end()) s2++;     map<int, int> mapa;     int ctr = 0;     mapa[*s1] = ctr;     ctr++;     while (s2 != s.end()) {       if ((*s1) != (*s2)) {         mapa[*s2] = ctr;         ctr++;       }       s1++;       s2++;     }     segtree prev;     prev.init(2 * m + 2);     vector<int> before(n, -1);     for (int i = 0; i < n; i++) {       pair<int, int> mx = {0, -1};       for (auto x : v[i]) {         int a = mapa[x.first];         int b = mapa[x.second];         mx = max(mx, prev.get(a, b));       }       mx.first++;       before[i] = mx.second;       mx.second = i;       for (auto x : v[i]) {         int a = mapa[x.first];         int b = mapa[x.second];         prev.update(a, b, mx);       }     }     vector<int> ok(n, false);     int lastmx = prev.get(0, 2 * m + 1).second;     while (lastmx >= 0) {       ok[lastmx] = true;       lastmx = before[lastmx];     }     vector<int> res;     int resnum = 0;     for (int i = 0; i < n; i++) {       if (!ok[i]) {         res.push_back(i);         resnum++;       }     }     cout << resnum <<   n ;     for (auto w : res) cout << w + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 9000;   const int mod = 1e9 + 7;   const int maxv = 9000;   bool vis[maxv + 1][maxv + 1], in[maxv + 1][maxv + 1];   vector<int> v[maxv + 1];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= maxv; i++) v[i].push_back(0), in[i][0] = true;     for (int i = 1; i <= n; i++) {       for (auto it : v[a[i]]) {         if (vis[a[i]][it]) continue;         for (int j = a[i] + 1; j <= maxv; j++) {           if (in[j][it ^ a[i]]) break;           v[j].push_back(it ^ a[i]);           in[j][it ^ a[i]] = true;         }         vis[a[i]][it] = true;       }       v[a[i]].clear();     }     set<int> ordered(v[maxv].begin(), v[maxv].end());     cout << ordered.size() <<   n ;     for (auto it : ordered) cout << it <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, l, m, n, cnt = 0, ans = 0;     char a[8][8];     for (i = 0; i < 8; i++)       for (j = 0; j < 8; j++) cin >> a[i][j];     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (a[i][j] ==  B ) cnt++;       }       if (cnt == 8) ans++;       cnt = 0;     }     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (a[j][i] ==  B ) cnt++;       }       if (cnt == 8) ans++;       cnt = 0;     }     if (ans == 16) ans = 8;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, l, v1, v2, k;     while (~scanf( %d%d%d%d%d , &n, &l, &v1, &v2, &k)) {       if (k >= n) {         printf( %.10lf n , l * 1.0 / v2);         continue;       }       int t = (n - 1) / k;       double s = v2 * 1.0 / v1;       double kk = (1 + s) / (3 + s);       double temp = kk + t * (1 - kk);       temp = l * 1.0 / (temp * v1);       printf( %.10lf n , temp * (kk / s + t * (1 - kk)));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 55;   int n, m;   int a[MAXN][MAXN];   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> m;       set<int> rows, columns;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cin >> a[i][j];           if (a[i][j] == 1) rows.insert(i), columns.insert(j);         }       }       int res = min(n - rows.size(), m - columns.size());       if (res % 2 == 0)         cout <<  Vivek  << endl;       else         cout <<  Ashish  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, cnt1, cnt2;     scanf( %d %d , &n, &m);     string str1, str2;     cin >> str1 >> str2;     if (str1 == str2) {       return !printf( YES n );     }     cnt1 = cnt2 = 0;     int l2;     for (i = 0; i < n && i < m; i++) {       if (str1[i] == str2[i]) {         cnt1++;       } else {         l2 = i;         break;       }     }     for (i = n - 1, j = m - 1; i >= 0 && j >= l2; i--, j--) {       if (str1[i] == str2[j]) {         cnt2++;       } else {         break;       }     }     bool ok = 0;     for (i = 0; i < n; i++)       if (str1[i] ==  * ) ok = 1;     if (cnt1 + cnt2 + 1 == n && ok)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     scanf( %d , &t);     while (t--) {       int a, b;       scanf( %d%d , &a, &b);       int k = min(max(2 * a, b), max(a, 2 * b));       printf( %d n , k * k);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int L = 30;   int n;   int a[N];   struct Trie {     Trie *l, *r;     Trie(Trie *l_, Trie *r_) {       l = l_;       r = r_;     }   };   struct Ans {     Trie *t;     long long ans;   };   int get(Trie *l, Trie *r, int i) {     if (i == -1) return 0;     if (l->l && r->l && l->r && r->r)       return min(get(l->l, r->l, i - 1), get(l->r, r->r, i - 1));     else if (l->l && r->l)       return get(l->l, r->l, i - 1);     else if (l->r && r->r)       return get(l->r, r->r, i - 1);     else if (l->l)       return get(l->l, r->r, i - 1) + (1 << i);     else       return get(l->r, r->l, i - 1) + (1 << i);   }   Ans solve(int i, int mn, int mx) {     if (i == -1) return {new Trie(NULL, NULL), 0};     int l = lower_bound(a, a + n, mn) - a;     int r = upper_bound(a, a + n, mx) - a - 1;     if (a[r] < mn + (1 << i)) {       auto t = solve(i - 1, mn, mn + (1 << i) - 1);       t.t = new Trie(t.t, NULL);       return t;     }     if (mn + (1 << i) <= a[l]) {       auto t = solve(i - 1, mn + (1 << i), mx);       t.t = new Trie(NULL, t.t);       return t;     }     {       auto l = solve(i - 1, mn, mn + (1 << i) - 1);       auto r = solve(i - 1, mn + (1 << i), mx);       Ans ans;       ans.ans = l.ans + r.ans + get(l.t, r.t, i - 1) + (1 << i);       ans.t = new Trie(l.t, r.t);       return ans;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     cout << solve(L - 1, 0, (1 << L) - 1).ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct _lap {     int p;     int qu;   } lap;   bool cmp(const lap &a, const lap &b) { return a.p < b.p; }   void remain() {     int n;     cin >> n;     vector<lap> laps;     for (int i = 0; i < n; ++i) {       lap x;       cin >> x.p >> x.qu;       laps.push_back(x);     }     sort(laps.begin(), laps.end(), cmp);     enum RE { HAPPY_ALEX, POOR_ALEX };     RE re = POOR_ALEX;     for (int i = 0; i < laps.size() - 1; ++i) {       if (!(laps[i].qu < laps[i + 1].qu)) {         re = HAPPY_ALEX;         break;       }     }     if (re == HAPPY_ALEX)       cout <<  Happy Alex ;     else       cout <<  Poor Alex ;   }   int main() {     remain();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, k;   int ans;   int f[1000001];   bool done[1000001];   vector<int> g[1000001];   void dfs(int u) {     done[u] = 1;     for (int &v : g[u])       if (done[v]) {         swap(v, g[u].back());         g[u].pop_back();         break;       }     for (int v : g[u]) dfs(v);     sort(g[u].begin(), g[u].end(), [](int x, int y) { return f[x] < f[y]; });     while ((g[u].size() >= 2) &&            (f[g[u].back()] + f[g[u][g[u].size() - 2]] + 2 > k)) {       ans++;       g[u].pop_back();     }     if (g[u].empty())       return;     else if (f[g[u].back()] > k) {       ans++;       f[u] = -1e9;     } else       f[u] = f[g[u].back()] + 1;   }   int main() {     read(n);     read(k);     {       int u, v;       for (int i = (1); i < (n); i++) {         read(u);         read(v);         g[u].push_back(v);         g[v].push_back(u);       }     }     int root = 1;     for (int i = (1); i <= (n); i++)       if (g[i].size() > 1) {         root = i;         break;       }     dfs(root);     if (f[root] >= 0) ans++;     writeln(ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, i, flag = 0, j;       cin >> n;       long long int a[n];       set<int> s;       for (i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       for (i = 1; i <= 1024; i++) {         set<int> temp;         for (j = 0; j < n; j++) {           temp.insert(i ^ a[j]);         }         if (temp == s) {           flag = 1;           cout << i << endl;           break;         }       }       if (flag == 0) cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main(void) {     unsigned short int m, n, c;     scanf( %hu%hu , &m, &n);     c = m * n;     int i = 1;     while (i) {       if (c >= 2 * i)         i++;       else         break;     }     printf( %d n , (i - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long c, hr, hb, wr, wb;   int main() {     cin >> c >> hr >> hb >> wr >> wb;     long long i, mx = 0, mxi;     for (i = 0; i <= c / wr; i += 1000)       if (i * hr + ((c - i * wr) / wb) * hb > mx) {         mx = i * hr + ((c - i * wr) / wb) * hb;         mxi = i;       }     for (i = max((long long)0, mxi - 20005); i <= min(c / wr, mxi + 20005); i++)       if (i * hr + ((c - i * wr) / wb) * hb > mx) {         mx = i * hr + ((c - i * wr) / wb) * hb;         mxi = i;       }     cout << mx << endl;     return 0;   }