malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char BUFFER[100000 + 5];   bool readn(int &n) { return scanf( %d , &n) == 1; }   bool readl(long long &n) { return scanf( %I64d , &n) == 1; }   bool readd(double &n) { return scanf( %lf , &n) == 1; }   bool reads(string &s) {     s =   ;     int n = scanf( %s , BUFFER);     if (n == 1) s = BUFFER;     return n == 1;   }   bool readln(string &s) {     char *valid = gets(BUFFER);     if (valid) s = BUFFER;     return ((bool)valid);   }   void Print(long long &n, bool printNewLine = true) {     printNewLine ? printf( %I64d n , n) : printf( %I64d , n);   }   const int maxn = 1e5 + 10;   int carry[maxn], f[maxn], d[maxn];   int anscnt = 0, ansfuel = 0;   int N, D, F;   vector<int> a, b;   void calc() {     int i, j, sum = 0;     for (i = 0; i < N; ++i)       if (d[i] >= D)         if (carry[i] > 0)           a.push_back(f[i]);         else           b.push_back(f[i]);     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (i = 0; i < ((int)b.size()); ++i) {       sum += b[i];       if (sum > F) break;       anscnt = i + 1;       ansfuel = sum;     }     if (0 == ((int)a.size()) || a[0] > F) return;     int C = 0;     for (i = 0; i < N; ++i) {       C += carry[i];       C = min(C, N);     }     sum = a[0];     i = 1;     j = 0;     while (1) {       if (sum > F) break;       int cnt = min(i + j + C, N);       if (cnt > anscnt || (cnt == anscnt && sum < ansfuel)) {         anscnt = cnt;         ansfuel = sum;       }       if (i == a.size() && j == b.size()) break;       if (i < a.size() && (j == b.size() || a[i] < b[j])) {         sum += a[i];         i++;       } else {         sum += b[j];         j++;       }     }   }   int main() {     int i;     cin >> N >> D >> F;     for (i = 0; i < N; ++i) cin >> carry[i] >> f[i] >> d[i];     calc();     cout << anscnt <<     << ansfuel << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, w, x, c;     cin >> a >> b >> w >> x >> c;     long long delta = c - a;     if (delta <= 0) {       cout << 0 << endl;     } else {       double k = (1.0 * delta * x - b) / (w - x);       long long t = ceil(delta + k);       cout << t << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline const T MAX(T a, T b) {     return ((a) > (b) ? (a) : (b));   }   template <typename T>   inline const T MIN(T a, T b) {     return ((a) > (b) ? (b) : (a));   }   template <typename T>   inline const T ABS(T a) {     return (((a) > 0) ? (a) : (-(a)));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int a, b, c;     cin >> a >> b >> c;     cout << (a * b) + (b * c) + (c * a) - (a + b + c) + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int size_n, size_m;   set<int> result;   vector<char> marks(0);   vector<string> mrk(0);   int main() {     int ii, jj;     string str;     cin >> size_n >> size_m;     marks.resize(size_m);     mrk.resize(size_n);     cin.ignore();     for (ii = 0; ii < size_m; ii++) marks[ii] =  n ;     for (ii = 0; ii < size_n; ii++) {       getline(cin, str);       mrk[ii] = str;       for (jj = 0; jj < size_m; jj++) {         if ((marks[jj] ==  n ) || (str[jj] >= marks[jj])) marks[jj] = str[jj];       }     }     for (ii = 0; ii < size_m; ii++) {       for (jj = 0; jj < size_n; jj++) {         if (mrk[jj][ii] == marks[ii]) result.insert(jj);       }     }     cout << result.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int key, priority;     int add = 0;     Node *left_child = nullptr, *right_child = nullptr;     Node(const int key) : key(key), priority(rand()) {}     void propagate() {       key += add;       if (left_child) left_child->add += add;       if (right_child) right_child->add += add;       add = 0;     }   };   int size(Node* const root) {     return root ? 1 + size(root->left_child) + size(root->right_child) : 0;   }   pair<Node*, Node*> split(Node* const root, const int key) {     if (!root)       return {nullptr, nullptr};     else       root->propagate();     Node *left, *right;     if (key <= root->key) {       right = root;       tie(left, right->left_child) = split(root->left_child, key);     } else {       left = root;       tie(left->right_child, right) = split(root->right_child, key);     }     return {left, right};   }   Node* merge(Node* const left, Node* const right) {     if (!left || !right)       return left ? left : right;     else       left->propagate(), right->propagate();     if (left->priority < right->priority) {       left->right_child = merge(left->right_child, right);       return left;     } else {       right->left_child = merge(left, right->left_child);       return right;     }   }   void erase_min(Node*& root) {     if (!root)       return;     else       root->propagate();     if (!root->left_child)       root = root->right_child;     else       erase_min(root->left_child);   }   int main() {     ios::sync_with_stdio(false);     Node* root = nullptr;     int n;     cin >> n;     while (n--) {       int l, r;       cin >> l >> r;       Node *t1, *t2, *t3;       tie(t1, t2) = split(root, l);       tie(t2, t3) = split(t2, r);       if (t2) t2->add++;       erase_min(t3);       root = merge(merge(t1, new Node(l)), merge(t2, t3));     }     cout << size(root) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e6 + 5;   vector<int> adj[mxN];   int n, m, sz[mxN], dp[mxN], dpb[mxN], mn[mxN];   bool bad[mxN];   int ans = 1e9 + 7, V;   void dfs1(int v, int par = -1) {     sz[v] += bad[v];     for (auto to : adj[v]) {       if (par != to) {         dfs1(to, v);         sz[v] += sz[to];         if (sz[to]) {           dpb[v] += dpb[to] + 2;           mn[v] = min(mn[v], (dp[to] + 1) - (dpb[to] + 2));         }       }     }     dp[v] = dpb[v] + mn[v];   }   void dfs2(int v, int par = -1) {     if (dp[v] < ans)       ans = dp[v], V = v;     else if (dp[v] == ans)       V = min(V, v);     multiset<pair<int, int> > mt;     for (auto to : adj[v]) {       if (sz[to]) mt.insert({min(0, (dp[to] + 1) - (dpb[to] + 2)), to});     }     for (auto to : adj[v]) {       if (to != par) {         int dpB = dp[v], dpbB = dpb[v];         int mnB = mn[to];         int subdpB = dp[to], subdpbB = dpb[to];         dp[v] -= mt.begin()->first;         if (sz[to]) mt.erase({min(0, (dp[to] + 1) - (dpb[to] + 2)), to});         if (!mt.empty()) dp[v] += mt.begin()->first;         if (sz[to]) {           dp[v] -= dpb[to] + 2;           dpb[v] -= dpb[to] + 2;         }         sz[v] -= sz[to];         sz[to] += sz[v];         if (sz[v]) {           dpb[to] += dpb[v] + 2;           dp[to] += dpb[v] + 2;           if (mn[to] > (dp[v] + 1) - (dpb[v] + 2)) {             dp[to] -= mn[to];             mn[to] = (dp[v] + 1) - (dpb[v] + 2);             dp[to] += mn[to];           }         }         dfs2(to, v);         sz[to] -= sz[v];         sz[v] += sz[to];         dp[v] = dpB, dpb[v] = dpbB;         mn[to] = mnB;         dp[to] = subdpB, dpb[to] = subdpbB;         if (sz[to]) mt.insert({min(0, (dp[to] + 1) - (dpb[to] + 2)), to});       }     }   }   int main() {     ios ::sync_with_stdio(false), cin.tie(nullptr);     cin >> n >> m;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= m; ++i) {       int v;       cin >> v;       bad[v] = 1;     }     dfs1(1);     dfs2(1);     cout << V <<   n  << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   bool isprime[MAX];   int a[MAX];   int ans[100005];   vector<int> factor[MAX];   void get_prime() {     memset(isprime, 1, sizeof(isprime));     for (int i = 2; i < MAX; i++) {       if (isprime[i]) {         factor[i].push_back(i);         for (int j = 2 * i; j < MAX; j += i) {           factor[j].push_back(i);           isprime[j] = 0;         }       }     }   }   int main() {     get_prime();     int n;     while (cin >> n) {       memset(ans, 0, sizeof(ans));       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         int m = 0;         for (int j = 0; j < factor[a[i]].size(); j++)           m = max(ans[factor[a[i]][j]] + 1, m);         for (int j = 0; j < factor[a[i]].size(); j++) ans[factor[a[i]][j]] = m;       }       int M = 1;       for (int i = 0; i < 10000; i++) M = max(M, ans[i]);       cout << M << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   const int MOD = 1e9 + 7;   bool mark[N];   vector<int> ps, corporator[N];   int primeMul[N], primeCnt[N], nthPower[N], b[N], n, k;   int _sum(int, int);   int _mul(int, int);   int _pow(int, int);   void _push(int&, int);   int main() {     cin >> n >> k;     fill(primeMul, primeMul + k + 1, 1);     for (int i = 1; i <= k; i++) {       nthPower[i] = _pow(i, n);       if (i > 1 && !mark[i]) {         for (int j = i; j <= k; j += i) {           mark[j] = true;           primeMul[j] *= i;           primeCnt[j]++;         }       }       if (primeMul[i] == i) ps.push_back(i);     }     for (int i : ps)       for (int j = i; j <= k; j += i) corporator[j].push_back(i);     b[1] = nthPower[1];     int ans = b[1] ^ 1;     for (int i = 2; i <= k; i++) {       b[i] = b[i - 1];       for (int c : corporator[i]) {         int v = _sum(MOD - nthPower[(i - 1) / c], nthPower[i / c]);         _push(b[i], primeCnt[c] & 1 ? MOD - v : v);       }       _push(ans, b[i] ^ i);     }     cout << ans << endl;   }   int _sum(int a, int b) { return a + b - (a + b >= MOD ? MOD : 0); }   int _mul(int a, int b) { return 1LL * a * b % MOD; }   int _pow(int a, int b) {     if (!b) return 1;     int res = _pow(a, b >> 1);     res = _mul(res, res);     if (b & 1) res = _mul(res, a);     return res;   }   void _push(int& a, int b) { a = _sum(a, b); }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, maxn = 100007, mod = 1e9 + 7;   const long long linf = 0x3f3f3f3f3f3f3f3fLL;   const long long P = 19260817;   string str;   string s;   bool flag;   int main() {     cin >> str;     for (int i = 1; i <= 5; i++) {       cin >> s;       if (s[0] == str[0] || s[1] == str[1]) flag = true;     }     if (flag) {       printf( YES );     } else {       printf( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int a[maxn];   int ans[maxn << 1];   int vis1[maxn], vis[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       scanf( %d , &n);       int res = n;       int p = 0;       int mex;       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         vis1[i] = 0;       }       while (res > 0) {         for (int i = 0; i <= n; i++) vis[i] = 0;         for (int i = 1; i <= n; i++) vis[a[i]] = 1;         for (int i = 0;; i++) {           if (!vis[i]) {             mex = i;             break;           }         }         if (mex == 0) {           for (int i = 1; i <= n; i++) {             if (!vis1[i]) {               a[i] = mex;               ans[++p] = i;               break;             }           }         } else {           ans[++p] = mex;           a[mex] = mex;           vis1[mex] = 1;           res--;         }       }       printf( %d n , p);       for (int i = 1; i <= p; i++) printf( %d  , ans[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 1e3 + 10, maxm = 1e6 + 5, maxc = 26;   long long sum = 0, mi = 0, ma = 0;   int main() {     int n, w, num;     scanf( %d%d , &n, &w);     for (int i = 0; i < n; i++) {       scanf( %d , &num);       sum += num;       mi = min(mi, sum);       ma = max(ma, sum);     }     printf( %I64d n , w - ma + mi + 1 <= 0 ? 0 : w - ma + mi + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long sum = 0;     for (int i = 0; i < n / 2; i++) {       sum += (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1]);     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   const int N = 1e5 + 1;   int r, a, b, m, las[N];   int main() {     cin >> a >> b >> m >> r;     memset(las, -1, sizeof las);     las[r] = 0;     for (int i = 1;; ++i) {       r = (a * r + b) % m;       if (~las[r]) {         cout << i - las[r];         return 0;       }       las[r] = i;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s[80000];   unordered_map<string, int> substrings;   int main(void) {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s[i];       unordered_map<string, bool> used;       for (int j = 1; j <= s[i].size(); ++j) {         for (int k = 0; k + j <= s[i].size(); ++k) {           string substring = s[i].substr(k, j);           if (used.find(substring) == used.end()) {             used[substring] = true;             if (substrings.find(substring) == substrings.end()) {               substrings[substring] = 1;             } else {               substrings[substring] += 1;             }           }         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 1; j <= s[i].size(); ++j) {         for (int k = 0; k + j <= s[i].size(); ++k) {           if (substrings[s[i].substr(k, j)] == 1) {             cout << s[i].substr(k, j) << endl;             goto van;           }         }       }     van:;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[3010];   bool maps[3010][3010];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       maps[u][v] = 1;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         int res = 0;         for (int k = 0; k < g[i].size(); k++) {           int v = g[i][k];           if (maps[v][j]) res++;         }         ans += res * (res - 1) / 2;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7, M = 1e6 + 7, fo = 1e6;   template <class T>   inline void read(T &re) {     char ch;     while ((ch = getchar()) <  0  || ch >  9 )       ;     re = ch - 48;     while ((ch = getchar()) >=  0  && ch <=  9 )       re = (re << 3) + (re << 1) + ch - 48;   }   int num[N], tim[N], fa[N], tot, hd[N];   long long f[N];   struct road {     int to, nxt, val;   } r[N];   struct TreeStructure {     long long sum[M];     inline void update(int x, long long ad) {       for (register int i = x; i <= fo; i += i & -i) sum[i] += ad;     }     inline long long query(int x) {       long long ret = 0;       for (register int i = x; i; i -= i & -i) ret += sum[i];       return ret;     }   } st, sc;   inline void ade(int x, int y, int z) {     r[++tot].to = y;     r[tot].nxt = hd[x];     r[tot].val = z;     hd[x] = tot;   }   inline void DpOnTree(int x, long long t) {     st.update(tim[x], 1ll * tim[x] * num[x]);     sc.update(tim[x], num[x]);     int L = 0, R = fo, mid, ans;     while (L <= R) {       mid = (L + R) >> 1;       if (st.query(mid) <= t) {         ans = mid;         L = mid + 1;       } else         R = mid - 1;     }     f[x] = sc.query(ans);     if (ans != fo) f[x] += (t - st.query(ans)) / (ans + 1);     long long mx = 0, mx2 = 0;     for (register int i = hd[x], u; i; i = r[i].nxt) {       u = r[i].to;       if (t - 2 * r[i].val < 0) continue;       DpOnTree(u, t - 2 * r[i].val);       if (f[u] >= mx)         mx2 = mx, mx = f[u];       else if (f[u] > mx2)         mx2 = f[u];     }     if (x != 1)       f[x] = max(f[x], mx2);     else       f[x] = max(f[x], mx);     st.update(tim[x], -1ll * tim[x] * num[x]);     sc.update(tim[x], -num[x]);   }   int main() {     int n, w;     long long T;     read(n);     read(T);     for (register int i = 1; i <= n; ++i) read(num[i]);     for (register int i = 1; i <= n; ++i) read(tim[i]);     for (register int i = 2; i <= n; ++i) {       read(fa[i]);       read(w);       ade(fa[i], i, w);     }     DpOnTree(1, T);     printf( %lld , f[1]);   }
#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   struct uz {     long long k, l, id, cnt;     long long x, y, m;     int i = 1;     void add() {       l = (l * x + y) % m;       i++;     }   } u[5035];   vector<pair<long long, long long>> ans;   int main() {     scanf( %d , &n);     long long aa = 0, sumk = 0;     for (int(i) = 0; (i) < (int)(n); (i)++) {       long long tmp = 0;       scanf( %lld%lld%lld%lld%lld , &u[i].k, &u[i].l, &u[i].x, &u[i].y, &u[i].m);       sumk += u[i].k;       long long last = u[i].l;       for (int j = 2; j <= u[i].k; j++) {         long long cur = (last * u[i].x + u[i].y) % u[i].m;         if (last > cur) tmp++;         last = cur;       }       aa = max(aa, tmp);     }     printf( %lld n , aa);     if (sumk > 200000) return 0;     while (1) {       long long start = ans.size();       for (int(i) = 0; (i) < (int)(n); (i)++) {         while (u[i].i <= u[i].k) {           ans.push_back({u[i].l, i});           u[i].add();           if (ans.back().first > u[i].l) break;         }       }       if (start == ans.size()) break;       sort(ans.begin() + start, ans.end());       if (start != 0) aa++;     }     for (auto p : ans) printf( %lld %lld n , p.first, p.second + 1);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     char arr[n + 1];     scanf( %s , arr);     int ans[26];     for (int m = 0; m < 26; m++) ans[m] = 0;     for (int j = 0; j < n; j++) {       int k = arr[j];       if (k > 64 && k < 91)         ans[k - 65] = 1;       else         ans[k - 97] = 1;     }     int sum = 0;     for (int g = 0; g < 26; g++) sum = sum + ans[g];     if (sum == 26)       printf( YES n );     else       printf( NO n );   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   constexpr int Dir4[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};   constexpr int Dir8[8][2] = {{-1, -1}, {-1, 1}, {0, -1},                               {0, 1},   {1, -1}, {1, 1}};   constexpr double EPS = 1e-8;   const double PI = acos(-1);   using int16 = short;   using uint16 = unsigned short;   using uint = unsigned int;   using int64 = long long;   using uint64 = unsigned long long;   using pii = pair<int, int>;   auto Equal = [](double a, double b) { return fabs(a - b) < EPS; };   constexpr int MAXN = 1500;   int n, k;   string s[MAXN + 1];   unordered_map<string, int64> UM;   unordered_map<char, int> convert;   int main() {     convert[ S ] = 1;     convert[ E ] = 2;     convert[ T ] = 4;     convert[1] =  S ;     convert[2] =  E ;     convert[4] =  T ;     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int64 ans = 0;     cin >> n >> k;     for (int i = (0); i < (n); ++i) {       cin >> s[i];       ++UM[s[i]];     }     for (int i = (0); i < (n); ++i) {       for (int j = (i + 1); j < (n); ++j) {         string tmp =   ;         for (int k = (0); k < (s[i].size()); ++k)           if (s[i][k] == s[j][k])             tmp += s[i][k];           else {             int x = convert[s[i][k]] | convert[s[j][k]];             tmp += convert[(~x) & 7];           }         ans += UM[tmp];       }     }     cout << ans / 3;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 1005;   int dp[N][2][N], n, T;   struct node {     int c, t;     node(int c = 0, int t = 0) : c(c), t(t) {}     void read() { scanf( %d%d , &t, &c); }     bool operator<(const node &b) const { return t > b.t; }   } a[N];   int main() {     int cur, nxt, ans, val;     scanf( %d%d , &n, &T);     ans = 0;     for (int i = 1; i <= n; i++) {       a[i].read();       ans = max(ans, a[i].c);     }     sort(a + 1, a + n + 1);     cur = 0;     nxt = 1;     memset(dp, 0xc0, sizeof(dp));     dp[1][0][0] = 0;     for (int j = 0; j <= T; j++) {       for (int i = 0; i <= n; i++)         for (int t = 0; t <= n; t++) dp[i][nxt][t] = -INF - 5;       for (int i = n; i >= 0; i--)         for (int t = 0; t <= n; t++) {           val = dp[i][cur][t];           if (val < -INF) continue;           ans = max(ans, val);           if (t < n) dp[i][cur][t + 1] = max(dp[i][cur][t + 1], val);           if (j < T)             dp[min(n, i * 2)][nxt][t] = max(dp[min(n, i * 2)][nxt][t], val);           if (i > 0 && a[t].t + j <= T) {             dp[i - 1][cur][t + 1] = max(dp[i - 1][cur][t + 1], val + a[t].c);             ans = max(ans, val + a[t].c);           }         }       swap(cur, nxt);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2000];   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; ++i) cin >> a[i];       s = string(60,  a );       cout << s <<   n ;       for (int i = 1; i <= n; ++i) {         s[a[i]] = s[a[i]] + 1;         if (s[a[i]] >  z ) s[a[i]] =  a ;         cout << s <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct cs {     int to, next;   } a[200001];   int aa[400001], head[100001], sum[100001];   bool vi[100001], c[100001];   int n, m, z, y, x, ans, ll, S;   void init(int x, int y) {     a[++ll].to = y;     a[ll].next = head[x];     head[x] = ll;   }   void dfs(int x, int y) {     vi[x] = 1;     aa[++ans] = x;     sum[x]++;     for (int k = head[x]; k; k = a[k].next)       if (!vi[a[k].to]) {         dfs(a[k].to, x);         aa[++ans] = x;         sum[x]++;       }     if (bool(sum[x] & 1) != c[x]) {       aa[++ans] = y;       sum[y]++;       aa[++ans] = x;       sum[x]++;     }   }   int main() {     scanf( %d%d , &n, &m);     while (m--) {       scanf( %d%d , &x, &y);       init(x, y);       init(y, x);     }     for (int i = 1; i <= n; i++) {       cin >> c[i];       if (c[i]) S = i;     }     if (S) {       dfs(S, -1);       for (int i = 1; i <= n; i++)         if (!vi[i] && c[i]) {           printf( -1 );           return 0;         }     }     if (ans > 1 && aa[ans - 1] == -1) ans -= 3;     printf( %d n , ans);     for (int i = 1; i <= ans; i++) printf( %d  , aa[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, i;     cin >> n;     long long a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     if (n < 3) {       cout <<  0  << endl;       for (i = 0; i < n; i++) cout << a[i] <<    ;     } else {       sort(a, a + n);       long l = 0, r = n - 1;       cout << n / 2 - (n % 2 == 0) << endl;       for (i = 0; i < n; i++) {         if (i % 2 == 0) {           cout << a[r] <<    ;           r--;         } else {           cout << a[l] <<    ;           l++;         }       }     }   }