malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int head[10010], cnt = 1, cur[10010], dis[N], s, t;   struct edge {     int next, to, w;   } e[N << 1];   struct query {     int u, t;   } q[N];   int main() {     auto add = [&](int u, int v, int w) {       e[++cnt] = {head[u], v, w};       head[u] = cnt;     };     auto add_edge = [&](int u, int v, int w) {       add(u, v, w);       add(v, u, 0);     };     auto bfs = [&]() {       for (int i = 1; i <= t; i++) dis[i] = -1;       dis[s] = 0;       queue<int> q;       q.push(s);       while (!q.empty()) {         int u = q.front();         q.pop();         for (int i = head[u]; i; i = e[i].next) {           int v = e[i].to;           if (e[i].w && dis[v] == -1) {             dis[v] = dis[u] + 1;             q.push(v);           }         }       }       return dis[t] != -1;     };     function<int(int, int)> dfs = [&](int u, int flo) {       if (u == t) return flo;       int detla = flo;       for (int &i = cur[u]; i; i = e[i].next) {         int v = e[i].to;         if (e[i].w && dis[v] == dis[u] + 1) {           int d = dfs(v, min(detla, e[i].w));           e[i].w -= d;           e[i ^ 1].w += d;           detla -= d;           if (detla == 0) break;         }       }       return flo - detla;     };     auto dini = [&]() {       int ans = 0;       while (bfs()) memcpy(cur, head, sizeof cur), ans += dfs(s, INF);       return ans;     };     auto cal = [&](int l, int r, int k) {       int L = l - k + 5, R = r - k + 5;       return R / 5 - L / 5;     };     int n, b, Q;     scanf( %d %d %d , &n, &b, &Q);     for (int i = 1; i <= Q; i++) scanf( %d %d , &q[i].u, &q[i].t);     q[++Q] = query{0, 0};     q[++Q] = query{b, n};     sort(q + 1, q + Q + 1, [](const query a, const query b) {       return a.u == b.u ? a.t < b.t : a.u < b.u;     });     for (int i = 2; i <= Q; i++)       if ((q[i - 1].u == q[i].u && q[i - 1].t < q[i].t) || q[i - 1].t > q[i].t)         return puts( unfair );     int p = 0;     s = Q + 5 + 1, t = s + 1;     for (int i = 1; i <= Q; i++) {       add_edge(s, i, q[i].t - q[i - 1].t);       p += q[i].t - q[i - 1].t;       for (int j = 0; j < 5; j++) {         add_edge(i, Q + j + 1, cal(q[i - 1].u, q[i].u, j));       }     }     for (int i = 0; i < 5; i++) add_edge(Q + i + 1, t, n / 5);     puts(dini() == n ?  fair  :  unfair );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, string> a[3005];   int h[3005];   vector<pair<string, int> > ans;   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i].second >> a[i].first;     sort(a, a + n);     for (int i = 0; i < n; i++)       if (a[i].first > i) {         cout <<  -1 n ;         return 0;       }     m = h[0] = 0;     for (int i = 1; i < n; i++)       m = max(m, h[i] = h[i - 1] + (a[i].first > a[i - 1].first));     for (int i = 0; i < n; i++)       ans.insert(ans.begin() + a[i].first, make_pair(a[i].second, h[i]));     for (int i = 0; i < n; i++)       cout << ans[i].first <<     << m - ans[i].second + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int a[3];       cin >> a[0] >> a[1] >> a[2];       sort(a, a + 3, greater<long long int>());       if (a[0] != a[1]) {         cout <<  NO               <<   n ;       } else {         cout <<  YES               <<   n ;         cout << a[0] <<     << a[2] <<     << a[2] <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int p, pre, k, cnt;   vector<long long int> ans;   int main() {     scanf( %lld %lld , &p, &k);     if (p < k) {       printf( 1 n%lld n , p);       return 0;     }     pre = p;     while (1) {       cnt = (k - pre);       if (cnt <= 0) {         cnt = cnt / k;         cnt -= 1;       } else {         cnt = cnt / k;         if (cnt * k == (k - pre)) {           cnt -= 1;         }       }       pre = cnt;       if (pre == 0) {         printf( -1 n );         return 0;       }       ans.push_back(pre);       if (pre > 0 && pre < k) {         break;       }     }     reverse(ans.begin(), ans.end());     pre = p;     for (int i = ans.size() - 1; i >= 0; i--) {       long long int temp = ans[i] * k + pre;       pre = ans[i];       ans[i] = temp;     }     reverse(ans.begin(), ans.end());     ans.push_back(pre);     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long v1, v2;   vector<int> sz;   vector<vector<pair<int, int>>> g;   void dfs(int u, int p, int c) {     sz[u] = 1;     for (auto &e : g[u]) {       int v = e.first;       if (v == p) continue;       dfs(v, u, e.second);       sz[u] += sz[v];     }     v1 += 1LL * (sz[u] & 1) * c;     v2 += 1LL * min(sz[u], 2 * n - sz[u]) * c;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       cin >> n;       g.assign(2 * n + 1, vector<pair<int, int>>());       for (int i = 1, a, b, c; i <= 2 * n - 1; ++i) {         cin >> a >> b >> c;         g[a].push_back({b, c});         g[b].push_back({a, c});       }       v1 = v2 = 0;       sz.assign(2 * n + 1, 0);       dfs(1, 0, 0);       cout << v1 <<     << v2 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[205], b[205];   long long dp[205][205], k;   int n, m;   char ans[205];   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     scanf( %d%d , &n, &m);     cin >> k;     int t = n + m - 1;     for (int i = 0; i < t; i++) {       a[i] = n * m;       b[i] = i;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int tmp;         scanf( %d , &tmp);         if (tmp < a[i + j]) a[i + j] = tmp;       }     sort(b, b + t, cmp);     for (int q = 0; q < t; q++) {       ans[b[q]] =  ( ;       dp[0][0] = 1;       for (int i = 0; i < t; i++)         for (int j = i & 1; j <= i && j <= t - i; j += 2)           if (dp[i][j]) {             if (dp[i][j] > k) dp[i][j] = k;             if (ans[i] !=  ) ) dp[i + 1][j + 1] += dp[i][j];             if (ans[i] !=  (  && j) dp[i + 1][j - 1] += dp[i][j];             dp[i][j] = 0;           }       if (dp[t][0] < k) {         k -= dp[t][0];         ans[b[q]] =  ) ;       }       dp[t][0] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout.put(ans[i + j]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nmax = 16, MX = 16 * 2000 + 42;   int n, k, inp[nmax];   int outp[nmax];   void print() {     vector<pair<int, int> > active;     cout <<  YES  << endl;     for (int i = 0; i < n; i++) active.push_back({inp[i], outp[i]});     for (int t = 1; t < n; t++) {       for (int i = 0; i < active.size(); i++)         for (int j = i + 1; j < active.size(); j++)           if (active[i].second == active[j].second) {             cout << active[i].first <<     << active[j].first << endl;             active[i].first += active[j].first;             while (active[i].first % k == 0) {               active[i].first = active[i].first / k;               active[i].second--;             }             active.erase(active.begin() + j, active.begin() + j + 1);             i = n;             j = n;           }     }     exit(0);   }   bitset<MX> on[1 << nmax];   int sum[1 << nmax];   void go(int aim, int deg, int mask) {     if (aim == 0 && mask == 0) print();     if (aim > sum[mask] || aim < 0) return;     if (on[mask][aim]) return;     on[mask][aim] = 1;     go(aim * k, deg + 1, mask);     for (int i = 0; i < n; i++)       if ((mask & (1 << i))) {         outp[i] = deg;         go(aim - inp[i], deg, mask - (1 << i));       }   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> inp[i];     for (int mask = 0; mask < (1 << n); mask++)       for (int i = 0; i < n; i++)         if ((mask & (1 << i))) sum[mask] += inp[i];     go(1, 0, (1 << n) - 1);     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v[2000006], pp[2000006];   long long first[2000006], cur = 0, w[2000006], n, m, i, xx, second, d, h, ans,                             w1, p, tt, o, temp, t;   void dfs(long long node, long long l) {     if (node > n) return;     long long i, j;     first[node] = l;     v[node].push_back(l);     dfs(2 * node, l + w[2 * node]);     dfs(2 * node + 1, l + w[2 * node + 1]);     for (j = 0; j < v[2 * node].size(); ++j) v[node].push_back(v[2 * node][j]);     for (j = 0; j < v[2 * node + 1].size(); ++j)       v[node].push_back(v[2 * node + 1][j]);     sort(v[node].begin(), v[node].end());     pp[node].resize(v[node].size());     pp[node][0] = v[node][0];     for (i = 1; i < v[node].size(); ++i)       pp[node][i] = v[node][i] + pp[node][i - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (i = 2; i <= n; ++i) cin >> w[i];     dfs(1, 0);     for (i = 0; i < m; ++i) {       ans = 0;       cin >> d >> h;       t = upper_bound(v[d].begin(), v[d].end(), h + first[d]) - v[d].begin();       if (t) ans = (h + first[d]) * t - pp[d][t - 1];       while (d != 1) {         w1 = w[d];         p = d / 2;         if (h > w1) ans += h - w1;         o = d - (d % 2) + !(d % 2);         if (o <= n) {           temp = h - (w[o] + w1) + first[o];           tt = upper_bound(v[o].begin(), v[o].end(), temp) - v[o].begin();           if (tt) ans += tt * temp - pp[o][tt - 1];         }         h -= w[d];         d >>= 1;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   map<int, long long> ans;   inline long long go(int n) {     if (ans.find(n) != ans.end()) return ans[n];     long long cur = n + 1;     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         cur = max(cur, n + go(i));         cur = max(cur, n + go(n / i));       }     }     return ans[n] = cur;   }   int main() {     cin >> n;     ans[1] = 1;     cout << go(n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, d;   bool ck[100005];   vector<int> adj[100005];   int dep[100005], ans;   void dfs(int u, int p) {     dep[u] = (ck[u] ? 0 : -(1 << 20));     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       dfs(v, u);       if (dep[v] != -(1 << 20)) dep[u] = max(dep[u], dep[v] + 1);     }   }   void get(int u, int p, int bef) {     if (ck[u]) bef = max(0, bef);     ans += (bef <= d && dep[u] <= d);     int m1 = -1, m2 = -1, c1 = 0;     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       int dd = dep[v] + 1;       if (dd > m1)         m2 = m1, m1 = dd;       else if (dd > m2)         m2 = dd;     }     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       int dd = dep[v] + 1;       if (dd == m1) c1++;     }     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       int dd = dep[v] + 1;       if (dd == m1) {         if (c1 > 1)           get(v, u, max(bef + 1, m1 + 1));         else if (m2 != -1)           get(v, u, max(bef + 1, m2 + 1));         else           get(v, u, bef + 1);       } else         get(v, u, max(bef + 1, m1 + 1));     }   }   int main() {     scanf( %d%d%d , &n, &m, &d);     for (int i = 0; i < m; ++i) {       int u;       scanf( %d , &u), u--;       ck[u] = 1;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v), u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(0, -1), get(0, -1, ck[0] ? 0 : -(1 << 20));     printf( %d , ans);   }
#include<bits/stdc++.h>   #define ll long long   using namespace std;      int x[100005];   int idx=0;   int d[100005];   int main()   {       int t;       cin>>t;       while(t--){           int n;           cin>>n;           idx=0;           for(int i=1;i<=n;i++){               scanf( %d ,&x[i]);           }           for(int i=n;i>=1;i--){               if(idx==0){                   d[++idx]=i;               }               else{                   while(idx>0&&x[i]>x[d[idx]]){                       idx--;                   }                   d[++idx]=i;               }           }           for(int i=1;i<=idx;i++){               int ma;               if(i==1) ma=n+1;               else ma=d[i-1];               for(int j=d[i];j<ma;j++){                   cout<<x[j]<<   ;               }           }           cout<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (T i : v) os << i <<  ,  ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T, class second>   ostream &operator<<(ostream &os, const pair<T, second> &v) {     os << v.first <<     << v.second;     return os;   }   template <class T, class second>   ostream &operator<<(ostream &os, const map<T, second> &v) {     for (auto i : v) os <<  (  << i.first <<   =>   << i.second <<  )  <<    ;     return os;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void f1(string &s) {     int n = s.length() + 1;     vector<int> ans(n);     int pos = 0, c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  > ) pos = i + 1;     }     ans[pos] = ++c;     if (pos > 1) {       for (int i = pos - 2; i >= 0; i--) {         if (s[i] ==  > ) {           ans[i + 1] = ++c;           if (i == 0) ans[i] = ++c;         }       }     }     set<int> to_do;     while (c < n) to_do.insert(++c);     for (int i = 1; i < n; i++) {       if (s[i - 1] ==  >  || ans[i] != 0) continue;       int c = i;       while (c < n && s[c - 1] ==  < ) c++;       c--;       while (c >= i) {         ans[c] = *to_do.rbegin();         to_do.erase(--to_do.end());         c--;       }     }     for (int i = 0; i < n; i++)       if (ans[i] == 0) {         ans[i] = *to_do.rbegin();         to_do.erase(--to_do.end());       }     for (int i : ans) cout << i <<    ;     cout <<   n ;   }   void f2(string &s) {     int n = s.length() + 1;     vector<int> ans(n);     reverse(s.begin(), s.end());     int pos = 0, c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  < ) pos = i + 1;     }     ans[pos] = ++c;     if (pos > 1) {       for (int i = pos - 2; i >= 0; i--) {         if (s[i] ==  < ) {           ans[i + 1] = ++c;         }       }     }     c = n;     for (int i = n - 1; i >= 0; i--)       if (ans[i] == 0) ans[i] = c--;     reverse(ans.begin(), ans.end());     for (int i : ans) cout << i <<    ;     cout <<   n ;   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     f1(s);     f2(s);   }   int main() {     fast();     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const int maxm = 100 + 10;   const int inf = 0x3f;   long long f[maxm][maxn], D[maxn], H[maxn], T[maxn], q[maxn];   long long g[maxn];   int N, M, P;   long long A[maxn], S[maxn];   void init() {     sort(A + 1, A + 1 + M);     for (int i = (1); i <= (M); i++) {       S[i] = S[i - 1] + A[i];     }     memset(f, inf, sizeof(f));     memset(g, 0, sizeof(g));     memset(q, 0, sizeof(q));     f[0][0] = 0;   }   void solve() {     for (int i = (1); i <= (P); i++) {       for (int k = (1); k <= (M); k++) g[k] = f[i - 1][k] + S[k];       int l = 1, r = 1;       q[1] = 0;       for (int j = (1); j <= (M); j++) {         while (l < r && (g[q[l + 1]] - g[q[l]]) <= (A[j] * (q[l + 1] - q[l])))           l++;         f[i][j] = min(f[i - 1][j], g[q[l]] + A[j] * (j - q[l]) - S[j]);         while (l < r && ((g[q[r]] - g[q[r - 1]]) * (j - q[r]) >=                          (g[j] - g[q[r]]) * (q[r] - q[r - 1])))           r--;         q[++r] = j;       }     }     cout << f[P][M] << endl;   }   int main() {     cin >> N >> M >> P;     for (int i = (2); i <= (N); i++) {       int x;       scanf( %d , &x);       D[i] = D[i - 1] + x;     }     for (int i = (1); i <= (M); i++) {       int h, t;       scanf( %d%d , &h, &t);       A[i] = t - D[h];     }     init();     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, M = 1e9 + 7;   const unsigned long long base = 13331;   const double Pi = acos(-1.0);   const long long C = 299792458;   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 * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   char a[505][505];   int n, m;   bool check() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  * ) {           if (i - 1 < 1 || i + 1 > n || j - 1 < 1 || j + 1 > m) continue;           if (a[i - 1][j] ==  *  && a[i + 1][j] ==  *  && a[i][j - 1] ==  *  &&               a[i][j + 1] ==  * ) {             a[i][j] =  . ;             for (int k = i - 1; k >= 1; k--) {               if (a[k][j] ==  * )                 a[k][j] =  . ;               else                 break;             }             for (int k = i + 1; k <= n; k++) {               if (a[k][j] ==  * )                 a[k][j] =  . ;               else                 break;             }             for (int k = j - 1; k >= 1; k--) {               if (a[i][k] ==  * )                 a[i][k] =  . ;               else                 break;             }             for (int k = j + 1; k <= m; k++) {               if (a[i][k] ==  * )                 a[i][k] =  . ;               else                 break;             }             return true;           }         }       }     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     if (!check()) {       cout <<  NO  << endl;     } else {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (a[i][j] ==  * ) {             cout <<  NO  << endl;             return 0;           }         }       }       cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 25;   inline int getDis(pair<int, int> a, pair<int, int> b) {     return (b.first - a.first) * (b.first - a.first) +            (b.second - a.second) * (b.second - a.second);   }   pair<int, int> G[maxn];   int dp[1 << maxn];   int dis[maxn][maxn], route[1 << maxn];   int n;   int main() {     scanf( %d%d , &G[0].first, &G[0].second);     scanf( %d , &n);     for (register int i = 1; i <= n; i++)       scanf( %d%d , &G[i].first, &G[i].second);     for (register int i = 0; i <= n; i++)       for (register int j = i; j <= n; j++)         dis[i][j] = dis[j][i] = getDis(G[i], G[j]);     memset(route, -1, sizeof route);     for (register int i = 0; i < (1 << maxn); i++) dp[i] = 0x3f3f3f3f;     dp[0] = 0;     for (register int i = 0; i < (1ll << n); i++) {       if (dp[i] == 0x3f3f3f3f) continue;       for (register int j = 1; j <= n; j++) {         if (i & (1ll << (j - 1))) continue;         for (register int k = 1; k <= n; k++) {           if (i & (1ll << (k - 1))) continue;           if (dp[i] + dis[0][j] + dis[j][k] + dis[k][0] <               dp[i | (1ll << (j - 1)) | (1ll << (k - 1))]) {             route[i | (1ll << (j - 1) | (1ll << (k - 1)))] = i;             dp[i | (1ll << (j - 1)) | (1ll << (k - 1))] =                 min(dp[i | (1ll << (j - 1)) | (1ll << (k - 1))],                     dp[i] + dis[0][j] + dis[j][k] + dis[k][0]);           }         }         break;       }     }     printf( %d n , dp[(1 << n) - 1]);     int now = (1 << n) - 1, last = -1;     printf( 0  );     while (true) {       if (last == -1) {         last = now;         now = route[now];         continue;       } else {         int change = now ^ last;         for (register int i = 1; i <= n; i++) {           if (change & (1ll << (i - 1))) {             printf( %d  , i);           }         }         last = now;         now = route[now];         if (now == -1) {           for (register int i = 1; i <= n; i++) {             if (last & (1 << (i - 1))) {               printf( %d  , i);             }           }           break;         }       }       printf( 0  );     }     printf( 0 );     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4786)   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int maxn = 2e5 + 5;   int isu[maxn], sz[maxn], dis[maxn], kk;   long long ans;   vector<int> G[maxn];   void dfs1(int root, int fa, long long depth) {     int siz = G[root].size(), nt;     dis[root] = depth;     if (isu[root]) {       sz[root] = 1;       ans += depth;     }     for (int i = 0; i < siz; i++) {       nt = G[root][i];       if (nt == fa) continue;       dfs1(nt, root, depth + 1LL);       sz[root] += sz[nt];     }   }   void solve(int root, int fa) {     if (kk <= 0) return;     priority_queue<pair<int, int> > Q;     int siz = G[root].size(), nt;     for (int i = 0; i < siz; i++) {       nt = G[root][i];       if (nt == fa) continue;       if (sz[nt] > 0) {         Q.push(make_pair(sz[nt], nt));       }     }     if (isu[root]) {       Q.push(make_pair(1, root));     }     pair<int, int> f1 = Q.top(), f2;     int fir = f1.first, sec = f1.second, sum = 0;     if (Q.size() == 1) {       solve(sec, root);     } else {       Q.pop();       while (!Q.empty()) {         f2 = Q.top();         Q.pop();         sum += f2.first;       }       sum = min(sum, kk);       kk -= sum;       ans -= 2LL * dis[root] * sum;       if (kk > 0) solve(sec, root);     }   }   int main() {     int n, k, x, y;     scanf( %d %d , &n, &k);     kk = k;     for (int i = 1; i <= 2 * k; i++) {       scanf( %d , &x);       isu[x] = 1;     }     for (int i = 1; i < n; i++) {       scanf( %d %d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     ans = 0;     dfs1(1, 0, 0);     solve(1, 0);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i;     cin >> n;     long long int arr1[n];     for (i = 0; i < n; i++) cin >> arr1[i];     cin >> m;     long long int arr2[m];     for (i = 0; i < m; i++) cin >> arr2[i];     sort(arr1, arr1 + n);     sort(arr2, arr2 + m);     cout << arr1[n - 1] <<     << arr2[m - 1];   }
#include <bits/stdc++.h>   using namespace std;   int sg[100005], sgp[100005];   int main() {     int n;     cin >> n;     if (n <= 2) {       cout <<  -1 ;       return 0;     }     sg[0] = sg[1] = sg[2] = 0;     for (int i = 3; i <= n; ++i) {       int cnt[105] = {0};       for (int d = 2; d <= i; ++d) {         int fr, ls;         if (d % 2 == 0) {           fr = i / d - d / 2 + 1, ls = i / d + d / 2;           if (ls >= i || fr <= 0) break;           if ((fr + ls) * d / 2 != i) continue;         }         if (d % 2 == 1) {           fr = i / d - (d - 1) / 2, ls = i / d + (d - 1) / 2;           if (ls >= i || fr <= 0) break;           if (i % d != 0) continue;         }         cnt[sgp[fr - 1] ^ sgp[ls]] = 1;         if (i == n && (sgp[fr - 1] ^ sgp[ls]) == 0) {           cout << d;           return 0;         }       }       for (int j = 0; j < 100000; ++j)         if (cnt[j] == 0) {           sg[i] = j;           sgp[i] = sgp[i - 1] ^ sg[i];           break;         }     }     cout <<  -1 ;   }