malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bitset<64> f1[3610], f2[3610];   int n, m;   map<int, vector<int>> mp1, mp2;   int y[66], y2[66];   set<int> s;   vector<int> res;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> y[i], y[i] *= 2, mp1[y[i]].push_back(i);     for (int i = 1; i <= m; i++)       cin >> y2[i], y2[i] *= 2, mp2[y2[i]].push_back(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) res.push_back((y[i] + y2[j]) / 2);     sort(res.begin(), res.end());     res.erase(unique(res.begin(), res.end()), res.end());     for (int i = 0; i < res.size(); i++) {       int k = res[i];       for (int j = 1; j <= m; j++) {         int d = 2 * k - y2[j];         if (mp1[d].size())           for (auto xx : mp1[d]) f1[i].set(xx, 1);       }     }     for (int i = 0; i < res.size(); i++) {       int k = res[i];       for (int j = 1; j <= n; j++) {         int d = 2 * k - y[j];         if (mp2[d].size())           for (auto xx : mp2[d]) f2[i].set(xx, 1);       }     }     int ans = 0;     for (int i = 0; i < res.size(); i++)       for (int j = 0; j < res.size(); j++) {         int tmp = (f1[i] | f1[j]).count() + (f2[i] | f2[j]).count();         ans = max(ans, tmp);       }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, m, i, j, zero = 0, neg = 0, tot = 0, val = INT_MIN,                                 val2 = INT_MAX;       cin >> n >> m;       long long int b[n][m];       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           cin >> b[i][j];           if (b[i][j] < 0) {             neg++;             if (neg == 1)               val = b[i][j];             else if (val < b[i][j])               val = b[i][j];           } else if (b[i][j] == 0)             zero++;           else             val2 = min(val2, b[i][j]);           tot += abs(b[i][j]);         }       }       if (neg % 2 == 0 || zero != 0)         cout << tot << endl;       else {         cout << tot + 2 * max(val, -val2) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 50 + 5;   int n, dp[N][N][N][N];   char g[N][N];   int dfs(int x, int y, int h, int w) {     if (dp[x][y][h][w] != -1) return dp[x][y][h][w];     if (h == 1 && w == 1) return dp[x][y][h][w] = g[x][y] ==  # ;     if (h == 0 || w == 0) return dp[x][y][h][w] = 0;     dp[x][y][h][w] = max(h, w);     for (int i = 0; i <= h; ++i) {       dp[x][y][h][w] =           min(dp[x][y][h][w], dfs(x, y, i, w) + dfs(x + i, y, h - i, w));     }     for (int j = 0; j <= w; ++j) {       dp[x][y][h][w] =           min(dp[x][y][h][w], dfs(x, y, h, j) + dfs(x, y + j, h, w - j));     }     return dp[x][y][h][w];   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         cin >> g[i][j];       }     }     printf( %d , dfs(1, 1, n, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const int inf = 0x3f3f3f3f;   int n, m;   int mi[maxn], cnt[maxn];   int main() {     cin >> n >> m;     memset(mi, 0x3f, sizeof(mi));     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       mi[x] = min(mi[x], (y - x + n) % n);       cnt[x]++;     }     for (int i = 1; i <= n; i++) {       long long ans = 0;       for (int j = 1; j <= n; j++)         if (cnt[j])           ans = max(ans, (j - i + n) % n + (long long)n * (cnt[j] - 1) + mi[j]);       cout << ans <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <class T>   void chmin(T &t, const T &f) {     if (t > f) t = f;   }   template <class T>   void chmax(T &t, const T &f) {     if (t < f) t = f;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   int N, M;   int X[1000010], Y[1000010];   int bitN;   int bit[2100010];   void bitAdd(int pos, int val) {     for (int x = pos; x <= bitN; x += x & -x) bit[x] += val;   }   int bitLowerBound(int w) {     if (w <= 0) return 0;     int x = 0;     for (int k = bitN; k > 0; k /= 2) {       if (x + k <= bitN && bit[x + k] < w) {         w -= bit[x + k];         x += k;       }     }     return x + 1;   }   int perm[1000010];   int ids[2000010];   bool used[1000010];   bool solve() {     for (bitN = 2; bitN < M + N + 5; bitN <<= 1)       ;     memset(bit, 0, sizeof(bit));     memset(perm, ~0, sizeof(perm));     memset(ids, ~0, sizeof(ids));     for (int j = 1; j <= N; ++j) {       bitAdd(M + j, +1);       ids[M + j] = j;     }     for (int i = 0; i < M; ++i) {       const int pos = bitLowerBound(Y[i]);       const int j = ids[pos];       if (!~perm[j]) {         perm[j] = X[i];       }       if (perm[j] != X[i]) {         return false;       }       bitAdd(pos, -1);       bitAdd(M - i, +1);       ids[pos] = -1;       ids[M - i] = j;     }     memset(used, 0, sizeof(used));     for (int j = 1; j <= N; ++j)       if (~perm[j]) {         if (used[perm[j]]) {           return false;         }         used[perm[j]] = true;       }     int k = 1;     for (int j = 1; j <= N; ++j)       if (!~perm[j]) {         for (; used[k]; ++k)           ;         perm[j] = k;         used[k] = true;       }     return true;   }   int main() {     for (; ~scanf( %d%d , &N, &M);) {       for (int i = 0; i < M; ++i) {         X[i] = in();         Y[i] = in();       }       bool res = solve();       if (res) {         for (int j = 1; j <= N; ++j) {           if (j > 1) printf(   );           printf( %d , perm[j]);         }         puts(  );       } else {         puts( -1 );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 70010;   vector<int> vs[MN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<string> vs(n);     for (int i = 0; i < n; i++) cin >> vs[i];     vector<string> ans(n);     for (int len = 1; len < 10; len++) {       map<string, set<int> > mapper;       for (int i = 0; i < n; i++)         for (int j = 0; j + len - 1 < 9; j++)           mapper[vs[i].substr(j, len)].insert(i);       for (auto &curr : mapper)         if (((int)curr.second.size()) == 1) {           int id = *curr.second.begin();           if (ans[id] ==   ) ans[id] = curr.first;         }     }     for (int i = 0; i < n; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void remax(T& A, T B) {     if (A < B) A = B;   }   template <class T>   inline void remin(T& A, T B) {     if (A > B) A = B;   }   string ToString(long long num) {     string ret;     do {       ret += ((num % 10) +  0 );       num /= 10;     } while (num);     reverse(ret.begin(), ret.end());     return ret;   }   long long ToNumber(string s) {     long long r = 0, p = 1;     for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10;     return r;   }   long long Gcd(long long a, long long b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   long long Power(long long base, long long power) {     long long ret = 1;     while (power) {       if (power & 1) ret *= base;       power >>= 1;       base *= base;     }     return ret;   }   long long PowerMod(long long base, long long power, long long mod) {     if (!power) return 1;     if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;     return PowerMod((base * base) % mod, power >> 1, mod);   }   int Log(long long num, long long base) {     int ret = 0;     while (num) {       ++ret;       num /= base;     }     return ret;   }   int Count(long long mask) {     int ret = 0;     while (mask) {       if (mask & 1) ++ret;       mask >>= 1;     }     return ret;   }   inline void run() {     int arr[2000];     int n, b, ans;     scanf( %d%d , &n, &b);     for (int i = 0; i < n;) scanf( %d , arr + i++);     ans = b;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j)         remax(ans, arr[j] * (b / arr[i]) + b % arr[i]);     printf( %d n , ans);   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long g = exgcd(b, a % b, x, y);     long long t;     t = x, x = y, y = t - (a / b) * y;     return g;   }   int main() {     long long a, b, c, x, y;     cin >> a >> b >> c;     long long t = exgcd(a, b, x, y);     if (c % t == 0)       printf( %lld %lld n , -x * c / t, -y * c / t);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 1010;   int dp[N][N][2];   int bits[N];   int t, k;   long long dfs(int len, int pos, int num, bool mark) {     int maxx;     long long sum;     if (!len) {       if (num == 1) {         return true;       } else {         return false;       }     }     if (!mark && dp[len][pos][num] != -1) {       return dp[len][pos][num];     }     if (mark) {       maxx = bits[len];     } else {       maxx = 9;     }     sum = 0;     for (int i = 0; i <= maxx; i++) {       if (i == 4 || i == 7) {         sum +=             dfs(len - 1, len, (pos && pos - len <= k) | num, mark && i == maxx);       } else {         sum += dfs(len - 1, pos, num, mark && i == maxx);       }     }     sum %= MOD;     if (!mark) {       dp[len][pos][num] = sum;     }     return sum;   }   long long f(string s) {     int len;     len = 0;     for (int i = s.size() - 1; i >= 0; i--) {       len++;       bits[len] = s[i] -  0 ;     }     return dfs(len, 0, 0, 1);   }   bool check(string &s) {     int p;     p = 0;     for (int i = 1; i <= s.size(); i++) {       if (s[i - 1] ==  4  || s[i - 1] ==  7 ) {         if (!p || i - p > k) {           p = i;         } else if (i - p <= k) {           return true;         }       }     }     return false;   }   int main() {     string l, r;     long long ans;     while (scanf( %d%d , &t, &k) == 2) {       memset(dp, -1, sizeof(dp));       for (int i = 0; i < t; i++) {         cin >> l >> r;         ans = f(r) - f(l) + (check(l) ? 1 : 0);         printf( %lld n , (ans % MOD + MOD) % MOD);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int vis[200005][3], n;   long long dp[200005][3], a[200005];   long long dfs(int x, int s) {     if (dp[x][s]) return dp[x][s];     if (vis[x][s]) return -1;     vis[x][s] = 1;     int k;     if (s)       k = x + a[x];     else       k = x - a[x];     if (k <= 0 || k > n)       dp[x][s] += a[x];     else {       dp[x][s] = dfs(k, s ^ 1);       if (dp[x][s] != -1) dp[x][s] += a[x];     }     return dp[x][s];   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(vis, 0, sizeof(vis));       memset(dp, 0, sizeof(dp));       for (int i = 2; i <= n; i++) scanf( %I64d , &a[i]);       for (int i = 2; i <= n; i++) dfs(i, 0);       for (int i = 1; i < n; i++) {         if (dp[i + 1][0] == -1)           printf( -1 n );         else           printf( %I64d n , i + dp[i + 1][0]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = acos(-1.0);   long long mod = 998244353;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long GCD(long long a, long long b) {     if (b == 0) return a;     return GCD(b, a % b);   }   long long prod(long long a, long long b) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1ll) res = (res + a) % mod;       a = (2ll * a) % mod;       b >>= 1ll;     }     return res;   }   long long power(long long a, long long b) {     long long res = 1ll;     while (b > 0) {       if (b % 2ll) res = (res * a) % mod;       a = (a * a) % mod;       b /= 2ll;     }     return res;   }   long long binaryExponentiation(long long a, long long b) {     long long result = 1ll;     while (b > 0) {       if (b % 2 == 1) result = (result * a) % mod;       a = (a * a) % mod;       b /= 2ll;     }     return result;   }   long long ModularInverse(long long a) {     return binaryExponentiation(a, mod - 2);   }   long long n, m;   void solve() {     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       if (a[i] >= 0) {         a[i] = -a[i] - 1;       }     }     long long x = INT_MAX, p = 0;     for (long long i = 0; i < n; i++) {       if (a[i] < x) {         x = a[i];         p = i;       }     }     if (n % 2) {       a[p] = -a[p] - 1;     }     for (auto &e : a) {       cout << e <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   #define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define testCase    int T; cin>>T; while(T--)   #define debug(P) cout<<#P<<   <<P<<endl   #define endl   n        using namespace std;       typedef long long ll;       int main() {     testCase {      int n;      cin>>n;      string s;      cin>>s;          bool poss = true;          int t = 0;          for(char x : s) {       if(x ==  T )++t;      }          if(2*(n-t) != t) {       poss = false;      }          t = 0;          for(int i = 0; i < n; ++i) {       if(s[i] ==  T ) ++t;       else {        --t;        if(t < 0) {         poss = false;         break;        }       }      }            t = 0;          for(int i = n-1; i >= 0; --i) {       if(s[i] ==  T ) ++t;       else {        --t;        if(t < 0) {         poss = false;         break;        }       }      }          if(poss) {       cout<<  YES n ;      } else {       cout<<  NO n ;      }         }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0)       cout << (n * n) / 2 << endl;     else       cout << (n / 2) * (n / 2) + (n / 2 + 1) * (n / 2 + 1) << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if ((i + j) % 2 == 0)           cout <<  C ;         else           cout <<  . ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e6 + 10;   vector<int> a[N];   vector<int> pos[N];   string ans;   int n;   string s[N];   int m;   vector<int> cur;   int cnt[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     memset(cnt, 0, sizeof(cnt));     m = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];       int len = s[i].length();       int k;       cin >> k;       while (k--) {         int p;         cin >> p;         p--;         m = max(m, p + len);         a[p].push_back(i);         a[p + len].push_back(-i);         pos[i].push_back(p);       }     }     ans.resize(m);     for (int i = 0; i < m; i++) {       for (int x : a[i]) {         if (x > 0) {           cur.push_back(x);           cnt[x]++;         } else {           cnt[-x]--;         }       }       while (!cur.empty() && cnt[cur.back()] == 0) cur.pop_back();       if (cur.empty())         ans[i] =  a ;       else {         int id = cur.back();         auto it = upper_bound(pos[id].begin(), pos[id].end(), i);         it--;         int p = *it;         if (i - p >= (int)s[id].length()) continue;         ans[i] = s[id][i - p];       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (cin >> a >> b >> c) {       long long l = 0, r = 100000000;       while (l <= r) {         long long t = (l + r) / 2;         long long w = b * t;         long long d = b * t;         bool ok = true;         while (d < a * c) {           if (w < a) {             ok = false;             break;           }           w -= a;           w += b;           d += b;         }         if (ok)           r = t - 1;         else           l = t + 1;       }       cout << l - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   vector<pair<int, int> > v[1000000 + 5];   int s[1000000 / 5], num = 0, last[1000000 + 5], vis[1000000 + 5],                       la[1000000 + 5], lastans = 0, n, q, mx, a[1000000 + 5],                       rt[1000000 + 5], cnt = 0, inv[1000000 + 5],                       Ans[1000000 + 5];   struct Tree {     int l, r, x;   } T[1000000 * 4 + 5];   bool b[1000000 + 5];   int Build(int l, int r) {     int x = ++cnt;     T[x].x = 1;     if (l != r) {       int mid = l + r >> 1;       T[x].l = Build(l, mid);       T[x].r = Build(mid + 1, r);     }     return x;   }   void Modify(int x, int l, int r, int lt, int rt, int v) {     if (l == lt && r == rt) {       T[x].x = 1LL * T[x].x * v % 1000000007;       return;     }     int mid = lt + rt >> 1;     if (r <= mid)       Modify(T[x].l, l, r, lt, mid, v);     else if (l > mid)       Modify(T[x].r, l, r, mid + 1, rt, v);     else       Modify(T[x].l, l, mid, lt, mid, v),           Modify(T[x].r, mid + 1, r, mid + 1, rt, v);   }   void Query(int x, int k, int lt, int rt) {     lastans = 1LL * lastans * T[x].x % 1000000007;     if (lt == rt) return;     int mid = lt + rt >> 1;     if (k <= mid)       Query(T[x].l, k, lt, mid);     else       Query(T[x].r, k, mid + 1, rt);   }   int main() {     n = read();     inv[0] = inv[1] = 1;     for (int i = 1; i <= n; ++i) mx = max(mx, a[i] = read());     q = read();     for (register int i = 2; i <= mx; ++i) {       inv[i] =           1LL * (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;       if (!b[i]) s[++num] = i, last[i] = i;       for (int j = 1; s[j] * i <= mx; ++j) {         b[s[j] * i] = 1;         last[s[j] * i] = s[j];         if (i % s[j] == 0) break;       }     }     rt[0] = Build(1, n);     for (int i = 1; i <= q; ++i) {       int l = read(), r = read();       v[r].push_back(make_pair(l, i));     }     for (register int i = 1; i <= n; ++i) {       Modify(rt[i] = rt[i - 1], 1, i, 1, n, a[i]);       for (int t = a[i]; t > 1; t /= last[t])         if (vis[last[t]] != i) {           vis[last[t]] = i;           Modify(rt[i], la[last[t]] + 1, i, 1, n,                  1LL * inv[last[t]] * (last[t] - 1) % 1000000007);           la[last[t]] = i;         }       for (int j = 0; j < v[i].size(); ++j)         lastans = 1, Query(rt[i], v[i][j].first, 1, n),         Ans[v[i][j].second] = lastans;     }     for (int i = 1; i <= q; ++i) printf( %d n , Ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const LL MOD = 998244353;   string s;   LL cal(int x) {     if (x < 10 || x > 18) return 0;     return 9 - (x - 10);   }   struct SegmentTree {     struct Node {       int L, R, l, r;       LL v[2][2];     };     vector<Node> N;     int p;     vector<int> rt;     int n;     inline void init(int _n) {       n = _n;       N.resize(n * 4);       p = 1;       rt.clear();       rt.push_back(build(0, n));     }     inline int copy(Node u) { return N[p] = u, p++; }     int build(int L, int R) {       int u = copy({L, R}), M = (L + R) >> 1;       ;       if (R - L == 1)         return N[u].v[0][0] = s[L] -  0  + 1, N[u].v[0][1] = 1, N[u].v[1][0] = 1,                N[u].v[1][1] = 0, u;       return pull(u, build(L, M), build(M, R));     }     inline int push(int u) { return u; }     inline int pull(int u, int l, int r) {       if (!l || !r) return l ? l : r;       push(N[u].l = l);       push(N[u].r = r);       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           N[u].v[i][j] =               (N[l].v[i][0] * N[r].v[0][j] +                N[l].v[i][1] * N[r].v[1][j] % MOD *                    cal((s[N[l].R - 1] -  0 ) * 10 + (s[N[r].L] -  0 ))) %               MOD;         }       }       return u;     }     int m(int L, int R, int u, int v) {       if (!u || R <= N[u].L || N[u].R <= L) return u;       push(u);       if (L <= N[u].L && N[u].R <= R) return N[u].v[0][0] = v + 1, u;       return pull(u, m(L, R, N[u].l, v), m(L, R, N[u].r, v));     }     int q(int L, int R, int u) {       if (!u || R <= N[u].L || N[u].R <= L) return 0;       if (L <= N[u].L && N[u].R <= R) return u;       push(u);       return pull(copy(N[u]), q(L, R, N[u].l), q(L, R, N[u].r));     }     inline void modify(int L, int R, int ver, int v) {       rt[ver] = m(L, R, rt[ver], v);     }     inline Node& query(int L, int R, int ver) {       p = 2 * n + 1;       return N[q(L, R, rt[ver])];     }   } solver;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> q;     cin >> s;     solver.init(n);     while (q--) {       int x, d;       cin >> x >> d;       x--;       s[x] =  0  + d;       solver.modify(x, x + 1, 0, d);       auto v = solver.query(0, n, 0).v;       cout << v[0][0] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> av;   int main() {     int n;     scanf( %d , &n);     for (int i = max(1, n - 100); i <= n; i++) {       int j = i, ans = i;       while (j) {         ans += j % 10;         j /= 10;       }       if (ans == n) av.push_back(i);     }     int avs = av.size();     printf( %d n , avs);     for (int i = 0; i < avs; i++) {       printf( %d n , av[i]);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   long long int n, res[200005], cnt = 0, ans[200005];   vector<long long int> g[200005];   vector<long long int> v[200005];   map<long long int, long long int> c;   queue<long long int> q;   void dfs1(long long int node, long long int color) {     c[node] = color;     for (auto it : g[node]) {       if (!c[it]) {         dfs1(it, color % 2 + 1);       }     }   }   void dfs2(long long int node, long long int p) {     for (auto it : g[node]) {       if (it != p) {         dfs2(it, node);       }     }     for (auto it : g[node]) {       if (c[it] != c[node] && res[it] == 0 && res[node] == 0) {         cnt++;         res[it] = cnt;         res[node] = cnt;         q.push(it);         q.push(node);       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long int i = 1; i < n; i++) {       long long int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs1(1, 1);     dfs2(1, 1);     while (!q.empty()) {       long long int x = q.front();       q.pop();       for (auto it : g[x]) {         if (res[it] == 0) {           res[it] = res[x];           q.push(it);         }       }     }     for (long long int i = 1; i <= n; i++) {       v[res[i]].push_back(i);     }     long long int mn = 0;     for (long long int i = 1; i <= cnt; i++) {       mn += (v[i].size() - 1) * 2;       for (long long int j = 0; j < v[i].size(); j++) {         ans[v[i][j]] = v[i][(j + 1) % v[i].size()];       }     }     cout << mn <<   n ;     for (long long int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }