malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     const int MAX = 1e6;     vector<bool> t(MAX + 1);     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       t[x] = true;     }     int d = 0;     vector<int> sol;     for (int i = 1; i <= MAX / 2; ++i) {       if (t[i] ^ t[MAX - i + 1]) {         sol.push_back(t[i] ? MAX - i + 1 : i);         t[i] = t[MAX - i + 1] = true;       } else if (t[i]) {         ++d;       }     }     for (int i = 1; i <= MAX / 2 && d; ++i) {       if (!t[i]) {         sol.push_back(MAX - i + 1);         sol.push_back(i);         --d;       }     }     cout << sol.size() <<   n ;     for (int i : sol) {       cout << i <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long INF64 = 2000000000000000007;   const int eps = 10e-6;   long long solve(vector<int> one, vector<int> two, vector<int> three) {     long long min_w = INF64;     for (auto x : one) {       long long b = x;       auto a = lower_bound(two.begin(), two.end(), b);       auto c = upper_bound(three.begin(), three.end(), b);       if (a == two.end() || c == three.begin()) continue;       long long aa = two[a - two.begin()];       long long cc = three[c - three.begin() - 1];       min_w = min(min_w, (aa - b) * (aa - b) + (b - cc) * (b - cc) +                              (cc - aa) * (cc - aa));     }     return min_w;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int k, l, m;       cin >> k >> l >> m;       vector<int> red(k);       vector<int> green(l);       vector<int> blue(m);       for (int i = 0; i < k; i++) cin >> red[i];       for (int i = 0; i < l; i++) cin >> green[i];       for (int i = 0; i < m; i++) cin >> blue[i];       sort(red.begin(), red.end());       sort(blue.begin(), blue.end());       sort(green.begin(), green.end());       long long ans = INF64;       ans = min(ans, solve(red, green, blue));       ans = min(ans, solve(red, blue, green));       ans = min(ans, solve(green, red, blue));       ans = min(ans, solve(green, blue, red));       ans = min(ans, solve(blue, green, red));       ans = min(ans, solve(blue, red, green));       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100001];   long long s[100001], ans[100001];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];     cin >> m;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       if (!ans[k]) {         long long res = 0;         long long koef = 1, cnt = k, j0 = 2, j1;         while (j0 <= n) {           j1 = min((long long)n, j0 + cnt - 1);           res += (s[j1] - s[j0 - 1]) * koef;           j0 = j0 + cnt;           koef++;           cnt *= k;         }         ans[k] = res;       }       cout << ans[k] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[101];     cin >> s;     int k = 1;     for (int i = 1; s[i] !=   0 ; ++i) {       if (s[i] == s[i - 1])         k++;       else         k = 1;       if (k == 7) break;     }     if (k >= 7)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > AdjList;   vector<int> dist;   vector<int> unused;   void update() {     queue<int> now;     for (int i = 0; i < unused.size(); i++) {       dist[unused[i]] = 0;       now.push(unused[i]);     }     while (!now.empty()) {       int u = now.front();       now.pop();       for (int i = 0; i < AdjList[u].size(); i++) {         int v = AdjList[u][i];         if (dist[u] + 1 < dist[v]) {           dist[v] = dist[u] + 1;           now.push(v);         }       }     }     unused.clear();   }   int main() {     int V, q;     cin >> V >> q;     AdjList.assign(V + 1, vector<int>());     dist.assign(V + 1, -1);     for (int x, y, i = 0; i < V - 1; i++) {       cin >> x >> y;       AdjList[x].push_back(y);       AdjList[y].push_back(x);     }     dist[1] = 0;     queue<int> now;     now.push(1);     while (!now.empty()) {       int u = now.front();       now.pop();       for (int i = 0; i < AdjList[u].size(); i++) {         int v = AdjList[u][i];         if (dist[v] == -1) {           dist[v] = dist[u] + 1;           now.push(v);         }       }     }     for (int t, from, i = 0; i < q; i++) {       cin >> t >> from;       if (t == 1) {         unused.push_back(from);       } else {         update();         cout << dist[from] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[20005];   int y[20005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int xx, yy;       scanf( %d %d , &xx, &yy);       x[xx + 10000]++;       y[yy + 10000]++;     }     long long ret = 0, sumx = 0, sumy = 0, tx = 0, ty = 0, dx = 0, dy = 0;     for (int i = 0; i <= 20000; i++) {       ret += (long long)x[i] * tx;       ret += (long long)y[i] * ty;       dx += sumx;       dy += sumy;       sumx += x[i];       sumy += y[i];       dx += sumx;       dy += sumy;       tx += dx;       ty += dy;     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool maze[3][100001];   int judge(int r, int c) {     if (r == 1) {       if (c == 100000) return maze[2][99999] + maze[2][100000];       return maze[2][c - 1] + maze[2][c] + maze[2][c + 1];     } else {       if (c == 1) return maze[1][1] + maze[1][2];       if (c == 100000) return maze[1][c - 1] + maze[1][c];       return maze[1][c - 1] + maze[1][c] + maze[1][c + 1];     }   }   int main() {     memset(maze, 0, sizeof(maze));     int n, q, cont = 0, r, c;     cin >> n >> q;     for (int i = 1; i <= q; i++) {       cin >> r >> c;       if (maze[r][c] == 0) {         maze[r][c] = 1;         cont += judge(r, c);       } else {         maze[r][c] = 0;         cont -= judge(r, c);       }       cout << (cont == 0 ?  Yes  :  No ) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int ESP = 1e18;   long long int FCB = 1e9 + 7;   long long int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const long long int N = 5005;   long long int l[N], r[N];   vector<pair<long long int, long long int>> vv;   bool fly(long long int x, long long int y) {     if (l[x] >= r[y]) return false;     if (r[x] <= l[y]) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n;     cin >> n;     for (long long int i = 1; i < n + 1; i++) cin >> l[i] >> r[i];     for (long long int i = 1; i < n + 1; i++) {       for (long long int j = 1; j < n + 1; j++) {         if (i != j && fly(i, j)) vv.push_back(make_pair(i, j));       }     }     map<long long int, long long int> mp;     long long int zz = vv.size();     for (long long int i = 0; i < zz; i++) {       mp[vv[i].first]++;       mp[vv[i].second]++;     }     vector<long long int> ans;     for (long long int i = 1; i <= n; i++) {       if (mp[i] == zz) ans.push_back(i);     }     long long int dd = ans.size();     cout << dd <<   n ;     for (long long int i = 0; i < dd; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[111111];   int main() {     cin >> n >> m >> k;     if (n % 2 == 0) {       cout << 0 << endl;       return 0;     }     for (int i = 0; i < n; i++) cin >> a[i];     int maxans = (int)2e9;     for (int i = 0; i < n; i += 2)       if (a[i] < maxans) maxans = a[i];     cout << min((long long)maxans, ((long long)m / ((n + 1) / 2)) * k) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[222], b[222];   int main() {     int n, ans = 0;     cin >> n;     int p, q, r, s;     for (int i = 0; i < n; i++) cin >> a[i] >> b[i];     for (int i = 0; i < n; i++) {       p = q = r = s = 0;       for (int j = 0; j < n; j++) {         if (j == i) continue;         if (a[j] > a[i] && b[j] == b[i]) p++;         if (a[j] < a[i] && b[j] == b[i]) q++;         if (a[j] == a[i] && b[j] > b[i]) r++;         if (a[j] == a[i] && b[j] < b[i]) s++;       }       if (p && q && r && s) ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int i, temp, temp2, a[n + 1];     for (int i = 0; i < n + 1; i++) a[i] = 0;     for (int i = 0; i < n - 1; i++) {       cin >> temp >> temp2;       a[temp]++;       a[temp2]++;     }     int s = 0;     for (int i = 0; i < n + 1; i++) {       if (a[i] < 2) s++;     }     cout << s - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, num[30], ans;   char s[100005];   int main() {     cin >> t;     while (t--) {       ans = 0;       memset(num, 0, sizeof(num));       scanf( %s , s + 1);       int len = strlen(s + 1);       for (int i = 1; i <= len; i++) {         num[s[i] -  A  + 1]++;       }       if (num[ L  -  A  + 1] != 0 && num[ R  -  A  + 1] != 0 &&           (num[ U  -  A  + 1] == 0 || num[ D  -  A  + 1] == 0)) {         printf( 2 n );         printf( LR n );       } else if (num[ U  -  A  + 1] != 0 && num[ D  -  A  + 1] != 0 &&                  (num[ L  -  A  + 1] == 0 || num[ R  -  A  + 1] == 0)) {         printf( 2 n );         printf( UD n );       } else if (num[ L  -  A  + 1] != 0 && num[ R  -  A  + 1] != 0 &&                  num[ U  -  A  + 1] != 0 && num[ D  -  A  + 1] != 0) {         ans += min(num[ L  -  A  + 1], num[ R  -  A  + 1]) * 2;         ans += min(num[ U  -  A  + 1], num[ D  -  A  + 1]) * 2;         printf( %d n , ans);         for (int i = 1; i <= min(num[ L  -  A  + 1], num[ R  -  A  + 1]); i++) {           printf( L );         }         for (int i = 1; i <= min(num[ U  -  A  + 1], num[ D  -  A  + 1]); i++) {           printf( U );         }         for (int i = 1; i <= min(num[ L  -  A  + 1], num[ R  -  A  + 1]); i++) {           printf( R );         }         for (int i = 1; i <= min(num[ U  -  A  + 1], num[ D  -  A  + 1]); i++) {           printf( D );         }         printf(  n );       } else {         printf( 0 n n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long mod = 1e9 + 7;   const int inf = 1e9;   string s;   long long expMod(long long base, long long ex, long long mod) {     if (ex == 0) return 1;     long long temp = expMod(base, ex / 2, mod);     temp = (temp * temp) % mod;     if (ex % 2) temp = (temp * base) % mod;     return temp;   }   long long solve(string x) {     long long n = x.size();     if (n == 1) {       if (x[0] ==  1 )         return 1;       else         return 0;     }     string temp = x.substr(1);     long long sz = temp.size();     long long ret = 0;     if (x[0] ==  0 ) {       ret = (1LL * 2 * solve(temp)) % mod;     } else {       ret = (expMod(2, 2 * sz, mod) + 2 * solve(temp)) % mod;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> s;     cout << solve(s) <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int64_t sum1 = 0;     int64_t sum2 = 0;     int to_double = 0;     int zero = 0;     std::set<std::pair<int, int>> doubled;     std::set<std::pair<int, int>> pend;     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (y > 0) {         if (x == 1) to_double++;         sum1 += y;         pend.insert({y, x});       } else {         y = -y;         sum1 -= y;         auto it = pend.find({y, x});         if (it != pend.end()) {           pend.erase(it);         } else {           it = doubled.find({y, x});           doubled.erase(it);           if (x == 0) zero--;           sum2 -= y;         }         if (x == 1) {           to_double--;           if (doubled.size() > 0) {             auto it = doubled.begin();             std::pair<int, int> now = *it;             if (now.second == 0) zero--;             doubled.erase(it);             sum2 -= now.first;             pend.insert(now);           }         }       }       if (doubled.size() < to_double && pend.size() > 0) {         auto it = --pend.end();         std::pair<int, int> max = *it;         doubled.insert(max);         if (max.second == 0) zero++;         sum2 += max.first;         pend.erase(it);       }       if (doubled.size() > 0 && pend.size() > 0) {         auto it = doubled.begin();         auto it2 = --pend.end();         doubled.erase(it);         pend.erase(it2);         std::pair<int, int> now1 = *it;         std::pair<int, int> now2 = *it2;         if (now2.first > now1.first) {           sum2 += now2.first - now1.first;           if (now2.second == 0) zero++;           if (now1.second == 0) zero--;           doubled.insert(now2);           pend.insert(now1);         } else {           doubled.insert(now1);           pend.insert(now2);         }       }       if (doubled.size() > 0 && zero == 0 && doubled.size() == to_double) {         auto it1 = doubled.begin();         std::pair<int, int> now = *it1;         doubled.erase(it1);         sum2 -= now.first;         if (pend.size() > 0) {           auto it2 = --pend.end();           std::pair<int, int> now2 = *it2;           pend.erase(it2);           doubled.insert(now2);           zero++;           sum2 += now2.first;         }         pend.insert(now);       }       printf( %lld n , sum1 + sum2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       if (k % (n - 1) == 0) {         cout << (k / (n - 1) * n) - 1 << endl;       } else {         cout << k / (n - 1) * n + k % (n - 1) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   bool isSeparator(char ch) { return (ch ==  ,  || ch ==     || ch ==  ; ); }   int main() {     int i, j;     bool isNumber;     string s, ss;     vector<string> words[2];     cin >> s;     s +=    ;     ss =   , isNumber = true;     for (i = 0; i < s.length(); i++) {       if (isSeparator(s[i])) {         if (ss.empty() || (isNumber && ss.length() > 1 && ss[0] ==  0 ))           isNumber = false;         words[isNumber].push_back(ss);         ss =   ;         isNumber = true;       } else {         ss += s[i];         if (!isdigit(s[i])) isNumber = false;       }     }     for (j = 1; j >= 0; j--) {       if (words[j].size()) {         cout <<    ;         for (i = 0; i < words[j].size(); i++) {           if (i) cout <<  , ;           cout << words[j][i];         }         cout <<     << endl;       } else         cout <<  -  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mN = 222222;   int n;   int a[mN], outa[mN], outb[mN], ge[mN];   vector<int> ans;   struct Bit {     int c[mN];     void clear() { memset(c, 0, sizeof(c)); }     int lob(int x) { return x & (-x); }     void add(int x, int dt) {       while (x <= n) {         c[x] += dt;         x += lob(x);       }     }     int sum(int x) {       int re = 0;       while (x > 0) {         re += c[x];         x -= lob(x);       }       return re;     }   } bit;   void calc(int o[]) {     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     bit.clear();     for (int i = n; i >= 1; i--) {       o[i] = bit.sum(a[i] + 1);       bit.add(a[i] + 1, 1);     }   }   int bins(int key) {     int l = 1, r = n;     key++;     while (l < r) {       int mid = (l + r) / 2;       if ((mid)-bit.sum(mid) >= key)         r = mid;       else         l = mid + 1;     }     return l - 1;   }   void out(int o[]) {     bit.clear();     for (int i = 1; i <= n; i++) {       int x = bins(o[i]);       ans.push_back(x);       bit.add(x + 1, 1);     }   }   int main() {     cin >> n;     calc(outa);     calc(outb);     for (int i = n - 1; i >= 1; i--) {       ge[i] += outa[i] + outb[i];       int mod = (n + 1) - i;       if (ge[i] >= mod) {         ge[i - 1] += ge[i] / mod;         ge[i] %= mod;       }     }     out(ge);     for (int i = 0, n_ = (ans.size()); i < n_; i++)       cout << ans[i] << ((i == ans.size() - 1) ?   n  :    );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e6 + 7, M = 2e6;   const long long mod = 1e9 + 7;   inline int read() {     int ret = 0;     char ch = getchar();     bool f = 1;     for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^  - );     for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - 48;     return f ? ret : -ret;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ksm(long long a, long long b, long long mod) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   int head[N], NEXT[M], ver[M], tot;   void link(int u, int v) {     ver[++tot] = v;     NEXT[tot] = head[u];     head[u] = tot;   }   int indeg[N], in[N], out[N], lazy[N], a[N];   int ant;   struct node {     int l, r, mid;     int val;     int maxn;   } tree[N];   void dfs(int x) {     in[x] = ++ant;     for (int i = head[x]; i; i = NEXT[i]) {       int y = ver[i];       dfs(y);     }     out[x] = ant;   }   void build(int x, int l, int r) {     tree[x].l = l;     tree[x].r = r;     lazy[x] = 0;     if (l == r) {       tree[x].maxn = 0;       return;     }     int mi = tree[x].mid = l + r >> 1;     build(x << 1, l, mi);     build(x << 1 | 1, mi + 1, r);     tree[x].maxn = max(tree[x << 1].maxn, tree[x << 1 | 1].maxn);   }   void down(int x) {     if (lazy[x] != 0) {       lazy[x << 1] += lazy[x];       lazy[x << 1 | 1] += lazy[x];       tree[x << 1].maxn += lazy[x];       tree[x << 1 | 1].maxn += lazy[x];       lazy[x] = 0;     }   }   void change(int x, int l, int r, int num) {     if (l > tree[x].r || r < tree[x].l) return;     if (l <= tree[x].l && r >= tree[x].r) {       tree[x].maxn += num;       lazy[x] += num;       return;     } else {       down(x);       if (l <= tree[x].mid) change(x << 1, l, r, num);       if (r > tree[x].mid) change(x << 1 | 1, l, r, num);       tree[x].maxn = max(tree[x << 1].maxn, tree[x << 1 | 1].maxn);     }   }   int ask(int x, int l, int r) { return tree[x].maxn; }   int main() {     int n, k;     int ant = 0;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     stack<int> s;     for (int i = 1; i <= n; i++) {       if (s.empty())         s.push(i);       else {         while (!s.empty() && a[s.top()] < a[i]) {           link(i, s.top());           indeg[s.top()]++;           s.pop();         }         s.push(i);       }     }     for (int i = 1; i <= n; i++) {       if (indeg[i]) continue;       link(n + 1, i);     }     dfs(n + 1);     build(1, in[n + 1], out[n + 1]);     for (int i = 1; i <= n; i++) {       if (i > k) {         change(1, in[i - k], out[i - k], -1);         change(1, in[i], out[i], 1);         printf(  %d , ask(1, in[n + 1], out[n + 1]));       } else {         change(1, in[i], out[i], 1);         if (i == k) printf( %d , ask(1, in[n + 1], out[n + 1]));       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, W, i, j, k;     cin >> n >> m >> W;     long long w[n], b[n];     for (i = 0; i < n; i++) cin >> w[i];     for (i = 0; i < n; i++) cin >> b[i];     vector<long long> G[n];     for (i = 0; i < m; i++) {       cin >> j >> k;       j--;       k--;       G[j].push_back(k);       G[k].push_back(j);     }     bool u[n];     memset(u, 0, sizeof(u));     vector<pair<long long, long long> > v;     vector<vector<long long> > vl;     for (i = 0; i < n; i++) {       if (u[i]) continue;       queue<long long> q;       vector<long long> l;       q.push(i);       pair<long long, long long> p = pair<long long, long long>(0, 0);       while (!q.empty()) {         k = q.front();         q.pop();         if (u[k]) continue;         u[k] = 1;         l.push_back(k);         p.first += b[k];         p.second += w[k];         for (j = 0; j < G[k].size(); j++) q.push(G[k][j]);       }       v.push_back(p);       vl.push_back(l);     }     long long V = v.size(), ans = 0;     long long dp[V + 1][W + 1];     memset(dp, 0, sizeof(dp));     for (i = 0; i < V; i++) {       for (j = 0; j < W; j++) {         dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);         for (k = 0; k < vl[i].size(); k++) {           if (j + w[vl[i][k]] > W) continue;           dp[i + 1][j + w[vl[i][k]]] =               max(dp[i + 1][j + w[vl[i][k]]], dp[i][j] + b[vl[i][k]]);         }         if (j + v[i].second > W) continue;         dp[i + 1][j + v[i].second] =             max(dp[i + 1][j + v[i].second], dp[i][j] + v[i].first);       }     }     for (i = 0; i <= V; i++)       for (j = 0; j <= W; j++) ans = max(ans, dp[i][j]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   int n;   const int N = 300005;   vector<int> v[N];   bool vis[N];   int val[N];   int dp[N][2], ans = 0;   void dfs(int s) {     vis[s] = true;     for (auto j : v[s]) {       if (!vis[j]) {         dfs(j);         dp[s][0] += dp[j][0];         dp[s][1] += dp[j][1];       }     }     if (val[s]) ++dp[s][val[s] - 1];   }   void dfs2(int s = 1) {     vis[s] = true;     for (auto j : v[s]) {       if (!vis[j]) {         int k = (dp[j][0] > 0);         if ((k > 0 && dp[j][1] == 0) || (k == 0 && dp[j][1] >= 0)) {           int z = ((dp[1][0] - dp[j][0]) > 0);           if ((z > 0 && dp[1][1] - dp[j][1] == 0) ||               (z == 0 && dp[1][1] - dp[j][1] >= 0))             ++ans;         }         dfs2(j);       }     }   }   int _runtimeTerror_() {     int i;     cin >> n;     for (i = 1; i <= n; ++i) cin >> val[i];     for (i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1);     memset(vis, false, sizeof(vis));     dfs2();     cout << ans <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     cerr <<   n  << 1.0 * clock() / CLOCKS_PER_SEC;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr.begin(), arr.end());     int i = 0, j = n - 1;     vector<int> left;     vector<int> right;     while (i <= j) {       right.push_back(arr[j--]);       left.push_back(arr[i++]);     }     if ((arr.size() & 1) == 1) left.erase(left.begin() + left.size() - 1);     int k = right.size() - 1;     cout << k <<   n ;     int p = 0;     for (int i = 0; i < right.size(); i++) {       cout << right[i] <<    ;       if (p < left.size()) cout << left[p++] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int p, x, ans = 0;     bool b;     cin >> p;     for (int i = 1; i < p; i++) {       b = 1;       x = 1;       for (int j = 1; j < p - 1; j++) {         x = (x * i) % p;         if ((x - 1) % p == 0) b = 0;       }       if (((x * i) - 1) % p != 0) b = 0;       if (b) ans++;     }     cout << ans << endl;     return 0;   }