malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 3;   bool dp[30][(1 << 14)][30];   int cnt[(1 << 14)], deg[(1 << 14)];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a;     int c = 0;     bool fail = 0;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 2) fail = 1;       if (x == 1)         c++;       else         a.push_back(x);     }     if (n == 1) {       if (c == 1) return cout <<  YES n , 0;       return cout <<  NO n , 0;     }     sort(a.begin(), a.end());     if (c < (n + 1) / 2 or fail) return cout <<  NO n , 0;     int m = n - c;     for (int mask = 0; mask < (1 << m); mask++) {       for (int i = 0; i < m; i++) {         if (mask & (1 << i)) {           deg[mask] = deg[mask ^ (1 << i)] + a[i];           cnt[mask] = cnt[mask ^ (1 << i)] + 1;         }       }     }     dp[0][0][c] = 1;     for (int i = 0; i < m; i++) {       for (int mask = 0; mask < (1 << i); mask++) {         for (int j = 0; j <= c; j++) {           if (dp[i][mask][j] == 0) continue;           for (int submask = mask; submask; submask = (submask - 1) & mask) {             if (deg[submask] > a[i] - 1 or deg[submask] + j < a[i] - 1) continue;             int t = a[i] - 1 - deg[submask];             if (cnt[submask] + t > 1)               dp[i + 1][(mask ^ submask) | (1 << i)][j - t] = 1;           }           if (j >= a[i] - 1) dp[i + 1][mask | (1 << i)][j - a[i] + 1] = 1;         }       }     }     cout << (dp[m][(1 << (m - 1))][0] == 1 ?  YES n  :  NO n );   }
#include <bits/stdc++.h>   using namespace std;   bool maxl(long long a, long long b) { return a > b; }   bool minl(long long a, long long b) { return a < b; }   bool cmp(int a, int b) { return a > b; }   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int main() {     int a[105], ji = 0, ou = 0, i, j, n, ans = 0;     n = read();     for (i = 0; i < n; i++) {       a[i] = read();       if (a[i] % 2 == 0) {         ou++;       } else {         ji++;       }       ans += a[i];     }     sort(a, a + n);     if (ans % 2 == 1) {       cout << ans << endl;     } else {       if (ji >= 1) {         for (i = 0; i < n; i++)           if (a[i] % 2 == 1) {             ans -= a[i];             break;           }         cout << ans << endl;       } else {         cout << 0 << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const int N = 2005;   int n, m, d;   string p, q;   int a[N], b[N];   int dp[N][N][2][2];   int calc(int id, int rem, int aflag, int bflag) {     if (id == n) {       return (rem == 0);     }     int& ans = dp[id][rem][aflag][bflag];     if (ans != -1) {       return ans;     }     ans = 0;     if (aflag && bflag) {       for (int x = 0; x < 10; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans = (ans + calc(id + 1, (10 * rem + x) % m, 1, 1)) % M;       }     } else if (aflag && bflag == 0) {       for (int x = 0; x < b[id] + 1; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans = (ans + calc(id + 1, (10 * rem + x) % m, 1, x != b[id])) % M;       }     } else if (aflag == 0 && bflag) {       for (int x = a[id]; x < 10; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans = (ans + calc(id + 1, (10 * rem + x) % m, x != a[id], 1)) % M;       }     } else {       for (int x = a[id]; x < b[id] + 1; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans =             (ans + calc(id + 1, (10 * rem + x) % m, x != a[id], x != b[id])) % M;       }     }     return ans;   }   void solve() {     memset(dp, -1, sizeof(dp));     cin >> m >> d >> p >> q;     n = (int)((p).size());     for (int i = 0; i < n; i++) {       a[i] = p[i] -  0 ;       b[i] = q[i] -  0 ;     }     cout << calc(0, 0, 0, 0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   string a[N];   int r[N], c[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       for (int i = 0; i <= n; i++) r[i] = 0;       for (int j = 0; j <= m; j++) c[j] = 0;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (a[i][j] ==  . ) r[i]++, c[j]++;       int ans = 1e9 + 7;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           int cur = r[i] + c[j];           if (a[i][j] ==  . ) cur--;           ans = min(ans, cur);         }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i, ans, mas[2000000], j;   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> mas[i];       while (m < mas[i] - mas[j]) j++;       if (i > j + 1) ans += (i - j - 1) * (i - j) / 2;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct _2DLL {     _2DLL *R, *D;     int val;     _2DLL() {       R = D = NULL;       val = 0;     }   };   int n, m, q;   _2DLL *grid[1005][1005];   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++) grid[i][j] = new _2DLL();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int x;         scanf( %d , &x);         grid[i][j]->val = x;       }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         if (j + 1 <= m) grid[i][j]->R = grid[i][j + 1];         if (i + 1 <= n) {           grid[i][j]->D = grid[i + 1][j];         }       }     }     int x1, y1, x2, y2, h, w;     while (q--) {       scanf( %d%d%d%d%d%d , &x1, &y1, &x2, &y2, &h, &w);       {         _2DLL *tp1 = grid[0][y1 - 1], *tp2 = grid[0][y2 - 1];         for (int i = 0; i < x1; tp1 = tp1->D, i++)           ;         for (int i = 0; i < x2; tp2 = tp2->D, i++)           ;         for (int i = 0; i < h; i++, tp1 = tp1->D, tp2 = tp2->D)           swap(tp1->R, tp2->R);       }       {         _2DLL *tp1 = grid[0][y1 + w - 1], *tp2 = grid[0][y2 + w - 1];         for (int i = 0; i < x1; tp1 = tp1->D, i++)           ;         for (int i = 0; i < x2; tp2 = tp2->D, i++)           ;         for (int i = 0; i < h; i++, tp1 = tp1->D, tp2 = tp2->D)           swap(tp1->R, tp2->R);       }       {         _2DLL *lft1 = grid[x1 - 1][0], *lft2 = grid[x2 - 1][0];         for (int i = 0; i < y1; lft1 = lft1->R, i++)           ;         for (int i = 0; i < y2; lft2 = lft2->R, i++)           ;         for (int i = 0; i < w; i++, lft1 = lft1->R, lft2 = lft2->R)           swap(lft1->D, lft2->D);       }       {         _2DLL *lft1 = grid[x1 + h - 1][0], *lft2 = grid[x2 + h - 1][0];         for (int i = 0; i < y1; lft1 = lft1->R, i++)           ;         for (int i = 0; i < y2; lft2 = lft2->R, i++)           ;         for (int i = 0; i < w; i++, lft1 = lft1->R, lft2 = lft2->R)           swap(lft1->D, lft2->D);       }     }     for (int i = 1; i <= n; i++) {       auto x = grid[i][0];       for (int j = 0; j < m; j++) {         x = x->R;         printf( %d  , x->val);       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   long int pos[100001] = {0}, neg[100001] = {0};   int main() {     long int n, count = 0, i;     scanf( %ld , &n);     long int arr[n];     for (i = 0; i < n; i++) {       scanf( %ld , arr + i);       if (arr[i] > 0)         pos[arr[i]]++;       else if (arr[i] < 0)         neg[-arr[i]]++;     }     for (i = 0; i < 100001; i++) {       if (pos[i] > 0) count++;       if (neg[i] > 0) count++;     }     printf( %ld , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[35], d[35], g[35], h[35], w[55], n, a, b, c, s, MOD;   bool f[35][35][50005], v[35][35][50005];   int main() {     int i, j, k, r = 0, x;     scanf( %d%d , &n, &MOD);     for (i = 0; i <= 40; i++) {       if (i < 10)         w[i] = 10 % MOD;       else         w[i] = 100 % MOD;     }     for (i = 1; i <= n; i++) {       scanf( %d , &x);       if (x < 32) {         s++;         d[s] = x;         g[s] = i;       }     }     n = min(n, 31);     for (i = 1; i <= n; i++) {       f[i][d[i]][d[i] % MOD] = 1;       v[i][d[i]][d[i] % MOD] = 1;       for (j = 0; j < 32; j++) {         for (k = 0; k < MOD; k++) {           if (f[i - 1][j][k]) {             f[i][j][k] = 1;             f[i][j ^ d[i]][(k * w[d[i]] + d[i]) % MOD] = true;             v[i][j ^ d[i]][(k * w[d[i]] + d[i]) % MOD] = true;           }         }       }     }     a = n;     if (!f[a][b][c]) {       puts( No );       return 0;     }     while (a) {       if (!v[a][b][c])         a--;       else {         r++;         p[r] = g[a];         b ^= d[a];         for (j = 0; j < MOD; j++) {           if (f[a - 1][b][j] && (j * w[d[a]] + d[a]) % MOD == c) {             c = j;             break;           }         }         a--;       }     }     puts( Yes );     printf( %d n , r);     for (i = r; i >= 1; i--) printf( %d  , p[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<pair<int, int>> dec;     vector<pair<int, int>> inc;     dec.push_back({1e7, 0});     inc.push_back({-1e7, 0});     for (int i = 0; i < n; i++) {       if (a[i] >= dec[dec.size() - 1].first and           a[i] <= inc[inc.size() - 1].first) {         cout <<  NO ;         return 0;       } else if (a[i] < dec[dec.size() - 1].first and                  a[i] <= inc[inc.size() - 1].first) {         dec.push_back({a[i], i});       } else if (a[i] >= dec[dec.size() - 1].first and                  a[i] > inc[inc.size() - 1].first) {         inc.push_back({a[i], i});       } else {         if (i < n - 1) {           if (a[i] > a[i + 1]) {             dec.push_back({a[i], i});           } else {             inc.push_back({a[i], i});           }         } else {           inc.push_back({a[i], i});         }       }     }     cout <<  YES n ;     vector<int> ans(n, 1);     for (int i = 1; i < inc.size(); i++) {       ans[inc[i].second] = 0;     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, j, a;   int c[11];   int main() {     cin >> n >> m >> k;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= m; ++j) {         char x;         cin >> x;         c[j] += (x ==  Y );       }     }     for (i = 1; i <= m; ++i) a += (c[i] >= k);     cout << a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int t2[2], t[2];   vector<int> type;   int main() {     cin >> s;     int n = s.length();     int c = 1;     while (c < n && s[c] == s[0]) c++;     if (c == n) {       cout <<  0 n ;       return 0;     }     int prev = 0;     for (int i = 1; i < n; i++) {       int ind = (c + i) % n;       if (s[(prev + c) % n] != s[ind]) {         if (i - prev <= 1)           type.push_back(0);         else           type.push_back(1);         prev = i;       }     }     if (n - prev <= 1)       type.push_back(0);     else       type.push_back(1);     c = 1;     while (c < type.size() && type[c] == type[0]) c++;     c %= n;     int ans = 0;     prev = 0;     for (int i = 1; i < type.size(); i++) {       int ind = (c + i) % type.size();       if (type[ind] != type[(prev + c) % type.size()]) {         if (type[(prev + c) % type.size()] == 0)           ans += (i - prev) / 2;         else           ans += i - prev;         prev = i;       }     }     if (type[(prev + c) % type.size()] == 0)       ans += (type.size() - prev) / 2;     else       ans += type.size() - prev;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void even() {     puts( YES );     printf( %d * %d = %d n , 1, 2, 2);     printf( %d * %d = %d n , 2, 3, 6);     printf( %d * %d = %d n , 6, 4, 24);     for (int i = 5; i + 1 <= n; i += 2) {       printf( %d - %d = 1 n , i + 1, i);       printf( 1 * 24 = 24 n );     }   }   void odd() {     puts( YES );     printf( 5 - 1 = 4 n );     printf( 4 - 2 = 2 n );     printf( 4 * 2 = 8 n );     printf( 8 * 3 = 24 n );     for (int i = 6; i + 1 <= n; i += 2) {       printf( %d - %d = 1 n , i + 1, i);       printf( 1 * 24 = 24 n );     }   }   int main() {     cin >> n;     if (n < 4) {       puts( NO );       return 0;     }     if (n % 2 == 0)       even();     else       odd();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mx[4005], need[4005];   int n, l[4005], r[4005], a[4005];   bool inter(int i, int j) {     if (l[i] >= l[j] && l[i] <= r[j]) return 1;     if (r[i] >= l[j] && r[i] <= r[j]) return 1;     if (l[j] >= l[i] && l[j] <= r[i]) return 1;     if (r[j] >= r[i] && r[j] <= r[i]) return 1;     return 0;   }   bool check(int d) {     int i, j, p, s;     r[0] = (1 << 30);     for (i = 1; i <= n; i++) need[i] = 0, mx[i] = n;     need[n] = n;     for (i = 1; i <= n; i++) {       for (j = i, s = 0; j <= n; j++)         if ((s += need[j]) > j - i + 1) return false;       for (j = i, s = 0; j <= n; j++)         if ((s += need[j]) == j - i + 1) break;       s = j;       for (j = 1, p = 0; j <= n; j++)         if (mx[j] > 0 && mx[j] <= s && r[j] < r[p]) p = j;       need[mx[p]]--, mx[p] = -1;       for (j = 1; j <= n; j++)         if (inter(p, j) && i + d < mx[j]) {           need[i + d]++, need[mx[j]]--;           mx[j] = i + d;         }       a[i] = p;     }     return 1;   }   int main() {     int i, ll, rr, mid;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d %d , &l[i], &r[i]);     ll = 0, rr = n - 1;     while (rr - ll > 1) {       mid = (ll + rr) >> 1;       if (check(mid))         rr = mid;       else         ll = mid;     }     check(rr);     for (i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3010;   int n;   struct edge {     int ne, to;     edge(int N = 0, int T = 0) : ne(N), to(T) {}   } e[MAXN << 1];   int fir[MAXN], num = 0;   inline void join(int a, int b) {     e[++num] = edge(fir[a], b);     fir[a] = num;   }   int pa[MAXN][MAXN], siz[MAXN][MAXN];   void pre(int u, int fa, const int rt) {     siz[rt][u] = 1;     pa[rt][u] = fa;     for (int i = fir[u]; i; i = e[i].ne) {       int v = e[i].to;       if (v == fa) continue;       pre(v, u, rt);       siz[rt][u] += siz[rt][v];     }   }   long long f[MAXN][MAXN];   long long dfs(int u, int v) {     if (u == v) return 0ll;     if (f[u][v]) return f[u][v];     return f[u][v] = max(dfs(u, pa[u][v]), dfs(pa[v][u], v)) +                      1ll * siz[v][u] * siz[u][v];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       join(u, v);       join(v, u);     }     for (int i = 1; i <= n; i++) pre(i, 0, i);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ans = max(ans, dfs(i, j));     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.141592653589793238463;   vector<vector<int> > g;   int parent[1009];   void dfs(int u, int prev) {     parent[u] = prev;     for (int v : g[u])       if (v != prev) dfs(v, u);   }   bool fme[1009], fhim[1009];   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       g = vector<vector<int> >(n + 9);       for (int i = 0; i < (n - 1); i++) {         int u, v;         cin >> u >> v;         g[u].push_back(v);         g[v].push_back(u);       }       int k1;       cin >> k1;       vector<int> me(k1);       memset((fme), (0), sizeof(fme));       for (int i = 0; i < (k1); i++) cin >> me[i], fme[me[i]] = 1;       int k2;       cin >> k2;       vector<int> him(k2);       memset((fhim), (0), sizeof(fhim));       for (int i = 0; i < (k2); i++) cin >> him[i], fhim[him[i]] = 1;       int root = me[0];       memset((parent), (0), sizeof(parent));       dfs(root, -1);       cout <<  B   << him[0] << endl;       int u;       cin >> u;       while (u != -1 && !fme[u]) u = parent[u];       if (u == -1)         cout <<  C -1  << endl;       else {         cout <<  A   << u << endl;         int v;         cin >> v;         if (fhim[v])           cout <<  C   << u << endl;         else           cout <<  C -1  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int INF = 0x3f3f3f3f;   int m, n, c[N], cnt[N];   vector<int> g[N];   int bit[N];   void add(int x, int t) {     for (; x <= n; x += x & -x) bit[x] += t;   }   int ask(int x) {     int ret = 0;     for (; x > 0; x -= x & -x) ret += bit[x];     return ret;   }   struct Que {     int p, c, ret;   } q[N];   vector<int> geet[N];   int st[N], ed[N], clk, sz[N], son[N], mat[N];   void predfs(int u, int f) {     st[u] = ++clk, mat[clk] = u, son[u] = -1, sz[u] = 1;     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i];       if (v == f) continue;       predfs(v, u);       sz[u] += sz[v];       if (son[u] == -1 || sz[v] > sz[son[u]]) son[u] = v;     }     ed[u] = clk;   }   void dfs(int u, int f, bool keep) {     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i];       if (v == f || v == son[u]) continue;       dfs(v, u, 0);     }     if (son[u] != -1) dfs(son[u], u, 1);     ++cnt[c[u]];     if (cnt[c[u]] - 1 > 0) add(cnt[c[u]] - 1, -1);     add(cnt[c[u]], 1);     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i];       if (v == f || v == son[u]) continue;       for (int j = st[v]; j <= ed[v]; ++j) {         ++cnt[c[mat[j]]];         if (cnt[c[mat[j]]] - 1 > 0) add(cnt[c[mat[j]]] - 1, -1);         add(cnt[c[mat[j]]], 1);       }     }     for (int i = 0; i < (int)geet[u].size(); ++i) {       int id = geet[u][i];       q[id].ret = ask(n) - ask(min(n, q[id].p - 1));     }     if (!keep) {       for (int i = st[u]; i <= ed[u]; ++i) {         add(cnt[c[mat[i]]], -1);         --cnt[c[mat[i]]];         if (cnt[c[mat[i]]]) add(cnt[c[mat[i]]], 1);       }     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &c[i]);       }       for (int i = 0; i < N; ++i) g[i].clear(), geet[i].clear();       memset(bit, 0, sizeof(bit));       memset(cnt, 0, sizeof(cnt));       clk = 0;       for (int i = 1; i < n; ++i) {         int u, v;         scanf( %d%d , &u, &v);         g[u].push_back(v);         g[v].push_back(u);       }       predfs(1, 0);       for (int i = 1; i <= m; ++i) {         int u;         scanf( %d%d , &u, &q[i].p);         geet[u].push_back(i);       }       dfs(1, 0, 1);       for (int i = 1; i <= m; ++i) {         printf( %d n , q[i].ret);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:1024000000,1024000000 )   const long double pi = acosl(-1.);   int T;   const long long mod = 258280327;   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   long long quickfind(long long x, long long y) {     long long result = 1;     while (y) {       if (y & 1) result = result * x % mod;       y >>= 1;       x = x * x % mod;     }     return result;   }   using namespace std;   int dfn[33333];   int cnt[33333];   struct master {     int x, y, z;     master(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}   };   int n;   int size[33333];   vector<master> cd[33333];   vector<int> ans;   int q[11111111] = {0};   int h = 5000000, t = 5000000 - 1;   void solve() {     for (int i = 1; i <= n; i++) q[++t] = i, size[i] = 4;     while (h <= t) {       int x = q[h++];       if ((int)cd[x].size() == 0) continue;       int y = cd[x][(int)cd[x].size() - 1].x;       int z = cd[x][(int)cd[x].size() - 1].y;       size[x]--, size[y]++, size[z]++;       if (size[y] > 9 || size[z] > 9) {         size[x]++;         size[y]--;         size[z]--;         q[++t] = x;         continue;       }       ans.push_back(cd[x][(int)cd[x].size() - 1].z);       cd[x].pop_back();       q[++t] = x;     }   }   int main() {     srand(time(NULL));     scanf( %d , &n);     for (int i = 1; i <= n << 2; i++) {       int a, b, c;       scanf( %d , &a);       scanf( %d , &b);       scanf( %d , &c);       cd[a].push_back(master(b, c, i));     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 16; j++) {         int x = rand() % 4;         int y = rand() % 4;         swap(cd[i][x], cd[i][y]);       }     }     solve();     if ((int)ans.size() == n * 4) {       printf( YES n );       printf( %d , ans[0]);       for (int i = 1; i <= (int)ans.size() - 1; i++) printf(  %d , ans[i]);       puts(  );     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int d[N], head[N], tot;   int to[N * N], nex[N * N], vis[N * N];   vector<pair<int, int> > ans;   void init() {     tot = 0;     memset(d, 0, sizeof(d));     memset(head, -1, sizeof(head));     ans.clear();   }   void add(int u, int v, int w) {     d[v]++;     to[tot] = v;     nex[tot] = head[u];     vis[tot] = w;     head[u] = tot++;   }   void dfs(int x) {     for (int& i = head[x]; ~i;) {       if (vis[i] == 1) {         i = nex[i];         continue;       }       if (vis[i] == 0) ans.push_back(make_pair(x, to[i]));       vis[i] = vis[i ^ 1] = 1;       dfs(to[i]);     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       init();       int n, m, u, v;       scanf( %d%d , &n, &m);       for (int i = 0; i < m; i++) {         scanf( %d%d , &u, &v);         add(u, v, 0);         add(v, u, 0);       }       vector<int> tmp;       int ret = n;       for (int i = 1; i <= n; i++)         if (d[i] & 1) tmp.push_back(i), ret--;       for (int i = 0; i < tmp.size(); i += 2) {         add(tmp[i], tmp[i + 1], -1);         add(tmp[i + 1], tmp[i], -1);       }       for (int i = 1; i <= n; i++) dfs(i);       printf( %d n , ret);       for (int i = 0; i < ans.size(); i++)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[(int)2e5][2];   int main() {     cin >> n;     if (n == 3) {       cout <<  1 2 3  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];       a[i][0]--;       a[i][1]--;     }     int next = 0;     for (int i = 0; i < n; i++) {       cout << (next + 1) <<    ;       int b = a[next][0];       int c = a[next][1];       if (a[b][0] == c || a[b][1] == c) {         next = b;       } else {         next = c;       }     }   }