malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> tree[500001];   bool intree[500001];   vector<int> tmp(0);   bool isleaf(int node) {     if (tree[node].size() == 1 && intree[(tree[node])[0]]) return true;     return false;   }   void DFS(int lvl, int node) {     intree[node] = true;     if (isleaf(node)) {       tmp.push_back(lvl);     }     for (int i = 0; i < tree[node].size(); i++) {       if (!intree[(tree[node])[i]]) {         DFS(lvl + 1, (tree[node])[i]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     int N;     cin >> N;     for (int i = 1; i <= N; i++) intree[i] = false;     int x, y;     for (int i = 0; i < N - 1; i++) {       cin >> x >> y;       tree[x].push_back(y);       tree[y].push_back(x);     }     intree[1] = true;     int ans = 0, c;     for (int i = 0; i < (tree[1]).size(); i++) {       tmp.clear();       DFS(0, (tree[1])[i]);       sort(tmp.begin(), tmp.end());       c = tmp.size();       for (int j = 0; j < c; j++) {         ans = max(ans, tmp[j] + c - j);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<string> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < n - 1; j++) {         if (v[i][j] ==  #  and v[i + 1][j] ==  #  and v[i][j + 1] ==  #  and             v[i][j - 1] ==  #  and v[i - 1][j] ==  # ) {           v[i][j] =  a ;           v[i + 1][j] =  a ;           v[i][j + 1] =  a ;           v[i][j - 1] =  a ;           v[i - 1][j] =  a ;         }       }     }     int c = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (v[i][j] ==  # ) {           c = 1;           break;         }     if (c)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long con = -1;     long long a[n + 5];     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     long long i = 1;     for (i = 1; i < n; i++) {       if (a[i + 1] == a[i]) {         con = i;         break;       }     }     if (con == -1) {       for (con = 1; con < n; con++) {         if (a[con] > a[con + 1]) {           break;         }       }     }     for (i = 1; i < con; i++) {       if (a[i + 1] < a[i]) {         cout <<  NO               <<   n ;         return 0;       }     }     while (a[con] == a[con + 1]) {       con++;     }     for (i = con; i < n; i++) {       if (a[i + 1] >= a[i]) {         cout <<  NO               <<   n ;         return 0;       }     }     cout <<  YES           <<   n ;   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     ios::sync_with_stdio(false);     int N, K;     cin >> N >> K;     ll total = N + 1;     total += N;     total += min(2 * (K - 1) + (N - K), 2 * (N - K) + K - 1);     cout << total <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k, n[20], a[20][5010], g[32768], f[32768], hsh[301781], ps[301781],       ans1[20], ans2[20], vis[20], TMS;   pair<int, int> md[32768];   long long sm[20];   int get(int x) {     int y = (x + 1000000001) % 301781;     while (hsh[y] && hsh[y] ^ x + 1000000001) y = (y + 1) % 301781;     return y;   }   void dg(int x, int s1, int s2) {     if (x == k) {       f[s2 + s1] |= f[s1] * g[s2];       return;     }     dg(x + 1, s1, s2);     dg(x + 1, s1, s2 + (1 << x));     dg(x + 1, s1 + (1 << x), s2);   }   int main() {     scanf( %d , &k);     long long S = 0;     for (int i = 0; i < k; ++i) {       scanf( %d , n + i);       for (int j = 0; j < n[i]; ++j) {         int x;         scanf( %d , &x);         a[i][j] = x;         sm[i] += x;         S += x;         int w = get(x);         ps[w] = i;         hsh[w] = x + 1000000001;       }     }     if (S % k != 0) {       printf( No );       return 0;     }     S /= k;     for (int i = 0; i < k; ++i)       for (int j = 0; j < n[i]; ++j) {         int st = 1 << i, nw = i;         long long c = S - (sm[i] - a[i][j]);         int P = 1;         ++TMS;         for (;;) {           vis[nw] = TMS;           if (abs(c) > 1000000000) {             P = 0;             break;           }           int w = get(c);           if (!hsh[w]) {             P = 0;             break;           }           st |= 1 << ps[w];           if (ps[w] == i) {             P = c == a[i][j];             break;           }           c = S - (sm[ps[w]] - c);           nw = ps[w];           if (vis[nw] == TMS) {             P = 0;             break;           }         }         if (P) {           md[st] = make_pair(i, j);           g[st] = 1;         }       }     f[0] = 1;     dg(0, 0, 0);     if (f[(1 << k) - 1]) {       printf( Yes n );       int ST = (1 << k) - 1;       while (ST) {         for (int _ = ST; _; _ = (_ - 1) & ST)           if (g[_] * f[ST - _]) {             int i = md[_].first, j = md[_].second, nw = i;             long long c = S - (sm[i] - a[i][j]), ls = a[i][j];             for (;;) {               int w = get(c);               ans1[ps[w]] = c;               ans2[ps[w]] = nw;               if (ps[w] == i) break;               ls = c;               nw = ps[w];               c = S - (sm[ps[w]] - c);             }             ST -= _;             break;           }       }       for (int i = 0; i < k; ++i) printf( %d %d n , ans1[i], ans2[i] + 1);     } else {       printf( No );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int test = 1;     for (; test > 0; --test) {       long long int n, a, b, c, d, c1 = 1, c2, c3, c4;       cin >> n >> a >> b >> c >> d;       c2 = c1 + b - c;       c3 = c2 + a - d;       c4 = c3 + c - b;       long long int m = 1 - min(min(c1, c2), min(c3, c4)),                     m1 = max(max(c1, c2), max(c3, c4));       if (m1 + abs(m) > n)         cout << 0 << endl;       else         cout << (n - (m1 + abs(m)) + 1) * n << endl;     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 1000000007;   const long long int MAXN = 100010;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       if (n % 2 == 0 && k % 2 == 1)         cout <<  NO  << endl;       else if (n % 2 == 1 && k % 2 == 0)         cout <<  NO  << endl;       else {         if (k * k <= n)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[250003];   int main() {     int i, j, k, n, m, t, a[501][501], b[501][501];     cin >> t;     while (t--) {       cin >> n >> m;       for (i = 0; i < n; i++)         for (j = 0; j < m; j++) cin >> a[i][j], d[a[i][j]] = i;       for (i = 0; i < m; i++)         for (j = 0; j < n; j++) cin >> b[i][j];       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           cout << a[d[b[0][i]]][j] <<    ;         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, pair<long long int, long long int> > > P;   int level[1007];   double ans = 0;   bool contains(pair<long long int, pair<long long int, long long int> > A,                 pair<long long int, pair<long long int, long long int> > B) {     return (A.second.first - B.second.first) * (A.second.first - B.second.first) +                (A.second.second - B.second.second) *                    (A.second.second - B.second.second) <            (A.first) * (A.first);   }   int main() {     long long int i, j, k, l, m, n, x, y, z, a, b, r;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &x);       scanf( %lld , &y);       scanf( %lld , &r);       P.push_back(make_pair(r, make_pair(x, y)));     }     sort(P.begin(), P.end());     for (i = n - 1; i >= 0; i--) {       for (j = n - 1; j > i; j--) {         if (contains(P[j], P[i])) {           level[i] = max(level[i], level[j] + 1);         }       }       if (level[i] == 0) level[i] = 1;     }     for (i = 0; i < n; i++) {       if (level[i] <= 2)         ans += (P[i].first * P[i].first);       else {         if (level[i] % 2 == 1)           ans -= (P[i].first * P[i].first);         else           ans += (P[i].first * P[i].first);       }     }     printf( %.10lf n , ans * 3.14159265358979);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long power(long long a, long long b) {     long long x = 1;     a = a % 1000000007ULL;     while (b) {       if (b & 1) x = (x * a) % 1000000007ULL;       a = (a * a) % 1000000007ULL;       b >>= 1;     }     return x;   }   inline long long inv(long long a) { return power(a, 1000000007ULL - 2); }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   const int N = 2e5 + 5;   vector<int> adj[N];   int n, dis[N];   bool vis[N];   int cnt[N], p[N];   int tdis[N];   vector<int> d[N];   void dfs(int u, int dd, int par) {     vis[u] = true;     if (dd < 3)       tdis[u] = dd;     else       tdis[u] = N;     dis[u] = dd;     d[dd].push_back(u);     p[u] = par;     for (auto v : adj[u]) {       if (!vis[v]) dfs(v, dd + 1, u);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     int u, v;     for (int i = 1; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0, 0);     int maxx = 0;     for (int i = 0; i < n; i++) {       if (d[i].size() == 0) break;       maxx = i;     }     int ans = 0;     for (int i = maxx; i > 1; i--) {       for (auto v : d[i]) {         if (dis[v] < 2 || tdis[v] == 2) continue;         ans++;         tdis[p[v]] = 2;         for (auto j : adj[p[v]]) tdis[j] = 2;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 998244353;   long long a[300001];   long long n, m, k;   int b[300001];   void solve() {     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       a[x]++;       b[a[x]] += a[x];       k = (b[a[x]] >= i && b[a[x]] != n) ? b[a[x]] : k;     }     cout << k + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char str[2020];     long l;     cin >> l;     cin >> str;     int i, j, hs = 0, ts = 0;     for (i = 0; i < l; i++) {       if (str[i] ==  H )         hs++;       else         ts++;       str[l + i] = str[i];     }     int res = 1000000000;     int t;     for (i = 0; i < l; i++) {       t = 0;       for (j = 0; j < hs; j++) {         if (str[i + j] ==  T ) t++;       }       if (t < res) res = t;       t = 0;       for (j = 0; j < ts; j++) {         if (str[i + j] ==  H ) t++;       }       if (t < res) res = t;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000000 + 100], f2, x1, x2, b[1000000 + 100], razl, sol, pok1, pok2;   double f1;   int main() {     for (int i = 1; i <= 4; i++) cin >> a[i];     f1 = sqrt(1 + 8 * a[1]) * 1.0;     f2 = sqrt(1 + 8 * a[1]);     if (f1 != f2) {       printf( Impossible n );       return 0;     }     f1 = sqrt(1 + 8 * a[4]) * 1.0;     f2 = sqrt(1 + 8 * a[4]);     if (f1 != f2) {       printf( Impossible n );       return 0;     }     x1 = 1 + sqrt(1 + 8 * a[1]);     x1 /= 2;     x2 = 1 + sqrt(1 + 8 * a[4]);     x2 /= 2;     if (a[1] == 0 && a[2] == 0 && a[3] == 0) x1 = 0;     if (a[4] == 0 && a[2] == 0 && a[3] == 0) x2 = 0;     if (a[2] + a[3] != x1 * x2) {       printf( Impossible n );       return 0;     }     for (int i = 1; i <= x1; i++) b[i] = 0;     for (int i = x1 + 1; i <= x1 + x2; i++) b[i] = 1;     sol = x1 * x2;     pok1 = x1;     pok2 = x1 + x2;     while (sol != a[2]) {       if (sol - x2 > a[2])         swap(b[pok1], b[pok2]), pok1--, pok2--, sol -= x2;       else {         swap(b[pok1], b[pok1 + sol - a[2]]);         break;       }     }     if (x1 + x2 == 0) printf( 0 );     for (int i = 1; i <= x1 + x2; i++) cout << b[i];     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void mohammed() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   int main() {     mohammed();     int n, x, y;     cin >> n;     map<int, int> mp;     map<int, int>::iterator it;     for (int i = 0; i < n; i++) {       cin >> x >> y;       mp[x]++;       mp[y + 1]--;     }     x = 0;     for (it = mp.begin(); it != mp.end(); it++) {       it->second += x;       if (it->second > 2) {         cout <<  NO ;         return 0;       }       x = it->second;     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   template <typename T, typename U>   inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   inline void amax(T &x, U y) {     if (x < y) x = y;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) n ;   }   template <class T>   ostream &operator<<(ostream &os, set<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  ,  ;     return os <<   b b] n ;   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  ,  ;     return os <<   b b] n ;   }   template <class K, class X>   ostream &operator<<(ostream &os, map<K, X> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  ,  ;     return os <<   b b] n ;   }   long int ceildiv(long int n, long int f) {     if (n % f) {       return n / f + 1;     } else       return n / f;   }   string checkTicket(vector<long> first, vector<long> second) {     int n = first.size();     if (first[0] < second[0]) {       for (int i = 0; i < n; i += 1) {         if (first[i] >= second[i]) {           return  NO n ;         }       }     } else if (first[0] > second[0]) {       for (int i = 0; i < n; i += 1) {         if (first[i] <= second[i]) {           return  NO n ;         }       }     } else {       return  NO n ;     }     return  YES n ;   }   int main() {     long int n;     cin >> n;     string s;     cin >> s;     vector<long> first, second;     for (int i = 0; i < n; i++) {       first.push_back(s[i] -  0 );     }     for (int i = n; i < 2 * n; i++) {       second.push_back(s[i] -  0 );     }     sort(first.begin(), first.end());     sort(second.begin(), second.end());     cerr << first << second;     cout << checkTicket(first, second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int t[N];   int p[N];   int p2[N];   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     long long sum = 0;     cin >> n;     for (int i = 0; i <= n; i++) {       cin >> t[i];       sum += t[i];     }     bool amb = 0;     for (int i = 1; i <= n; i++) {       if (t[i] > 1 && t[i - 1] > 1) amb = 1;     }     if (!amb) {       cout <<  perfect ;       return 0;     }     cout <<  ambiguous  <<   n ;     long long par = 1, k = 2;     p[1] = 0;     p2[1] = 0;     for (int i = 1; i <= n; i++) {       long long temp = k;       for (int j = 0; j < t[i]; j++) {         p[k] = par;         p2[k] = par;         k++;       }       par = temp;     }     k = 2;     for (int i = 1; i <= n; i++) {       if (t[i] > 1 && t[i - 1] > 1) {         p2[k]++;         break;       } else         k += t[i];     }     for (int i = 1; i <= sum; i++) cout << p[i] <<    ;     cout <<   n ;     for (int i = 1; i <= sum; i++) cout << p2[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long sum1 = 0, sum2 = 0;     long temp;     for (int i = 0; i < n; i++) {       cin >> temp;       sum1 += temp;     }     for (int i = 0; i < n - 1; i++) {       cin >> temp;       sum2 += temp;     }     cout << sum1 - sum2 <<   n ;     for (int i = 0; i < n - 2; i++) {       cin >> temp;       sum2 -= temp;     }     cout << sum2;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 20) + 15;   long long dp[N];   pair<int, int> id[100];   int bit[100], c[100], st[N];   int main() {     int u, a, mi, n, m, i, j, b, x, p = 0, idd;     long long k, temp;     long long ret = 4e18;     scanf( %d%d%d , &n, &m, &b);     for (i = 0; i < n; ++i) {       scanf( %d%d%d , &c[i], &id[i].first, &mi);       a = 0;       for (j = 0; j < mi; ++j) scanf( %d , &u), a |= 1 << (u - 1);       bit[i] = a;       id[i].second = i;     }     memset(dp, -1, sizeof(dp));     sort(id, id + n);     dp[0] = 0;     ++p;     for (i = 0; i < n; ++i) {       k = id[i].first, idd = id[i].second;       if (dp[bit[idd]] != -1 && dp[bit[idd]] <= c[idd]) continue;       x = p;       for (j = 0; j < p; ++j) {         u = st[j] | bit[idd];         if (dp[u] == -1 && u != (1 << m) - 1) st[x++] = u;         if (dp[u] == -1 || dp[u] > dp[st[j]] + c[idd]) dp[u] = dp[st[j]] + c[idd];       }       if (dp[(1 << m) - 1] != -1) ret = min(ret, k * b + dp[(1 << m) - 1]);       p = x;     }     if (ret == 4e18) ret = -1;     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[1000100], a[1000100];   int main() {     int n, k, ans;     scanf( %d , &n);     scanf( %d , &k);     for (long long i = 0; i < n; i++) scanf( %d , &a[i]);     int l = 0, r = 0, al, ar;     set<int> x;     cnt[a[0]]++;     x.insert(a[0]);     ans = 1;     al = 0, ar = 0;     while (l < n && r < n) {       r++;       x.insert(a[r]);       cnt[a[r]]++;       while ((long long)x.size() > k && l <= r) {         cnt[a[l]]--;         if (cnt[a[l]] == 0) x.erase(a[l]);         l++;       }       r = max(l, r);       if (r >= n) break;       if (r - l + 1 > ans) {         al = l;         ar = r;         ans = r - l + 1;       }     }     printf( %d %d n , al + 1, ar + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 105;   int l[M], r[M], t[M], c[M], res[M], p[M];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> l[i] >> r[i] >> t[i] >> c[i];     }     for (int i = 1; i <= n; ++i) p[i] = INT_MAX;     for (int i = 0; i < m; ++i)       for (int j = l[i]; j <= r[i]; ++j)         if (t[i] < p[j]) p[j] = t[i], res[j] = i;     int sum = 0;     for (int i = 1; i <= n; ++i)       if (p[i] != INT_MAX) sum += c[res[i]];     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9, pi = acos(-1);   const long long N = 1e5 + 5;   long long r[N], h[N], n, F[N], dp[N];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first == b.first) {       return a.second < b.second;     } else       return a.first < b.first;   }   void add(long long d, long long id) {     while (id <= n) {       F[id] = max(F[id], d);       id += (id & -id);     }   }   long long get(long long i) {     long long res = 0;     while (i) {       res = max(res, F[i]);       i -= (i & -i);     }     return res;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n; ++i) cin >> r[i] >> h[i];     vector<pair<long long, long long> > A;     A.clear();     for (long long i = 1; i <= n; ++i) {       A.push_back({r[i] * r[i] * h[i], i});     }     sort(A.begin(), A.end(), cmp);     long long res = 0, id = 0, prev = A[0].first;     for (long long i = 0; i < n; ++i) {       if (prev != A[i].first) {         while (id < i) {           add(dp[id], A[id].second);           id++;         }       }       dp[i] = get(A[i].second) + A[i].first;       res = max(res, dp[i]);       prev = A[i].first;     }     cout << fixed << setprecision(9) << pi * res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string str;     for (int i = 0; i < t; i++) {       cin >> str;       long long int res = 0;       long long int arr[str.size()];       if (str[0] ==  + ) {         arr[0] = 1;       } else {         arr[0] = -1;       }       for (int j = 1; j < str.size(); j++) {         if (str[j] ==  + ) {           arr[j] = arr[j - 1] + 1;         } else {           arr[j] = arr[j - 1] - 1;         }       }       int x = -1;       for (int j = 0; j < str.size(); j++) {         if (arr[j] == x) {           res = res + j + 1;           x--;         }       }       res = res + str.size();       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < k; i++) {       if (n % 10 != 0) {         n = n - 1;       } else if (n % 10 == 0) {         n = n / 10;       }     }     cout << n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 100;   template <class nmsl>   inline void read(nmsl &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;   }   long long n, f[N], size[N], root[N], hd[N], bianshu, ans;   struct abc {     int nxt, to;   } qwq[N * 2];   inline void addedg(int lai, int qu) {     qwq[++bianshu].nxt = hd[lai];     qwq[bianshu].to = qu;     hd[lai] = bianshu;   }   inline void first_dp(int u, int father) {     size[u] = 1;     for (register int i = hd[u]; i; i = qwq[i].nxt) {       int v = qwq[i].to;       if (v == father) continue;       first_dp(v, u);       size[u] += size[v];       f[u] += f[v];     }     f[u] += size[u];     return;   }   inline void dp(int u, int father) {     f[u] = 0;     for (register int i = hd[u]; i; i = qwq[i].nxt) {       int v = qwq[i].to;       f[u] += f[v];     }     long long tot = f[u] + n;     ans = max(ans, tot);     for (register int i = hd[u]; i; i = qwq[i].nxt) {       int v = qwq[i].to;       if (v == father) continue;       size[u] = n - size[v];       f[u] = tot - f[v] - size[v];       dp(v, u);     }   }   int main() {     read(n);     for (register int i = 1, qa, qb; i < n; i++)       read(qa), read(qb), addedg(qa, qb), addedg(qb, qa);     first_dp(1, 0);     ans = f[1];     dp(1, 0);     cout << ans;     return 0;   }