malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-10;   template <typename T, typename S>   vector<T>& operator<<(vector<T>& a, S b) {     a.push_back(b);     return a;   }   template <typename T>   void operator>>(vector<T>& a, int b) {     while (b--)       if (!a.empty()) a.pop_back();   }   bool isprime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long b_pow(long long x, long long n) {     return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;   }   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   int main() {     int n, m;     cin >> n >> m;     vector<int> atk, def, ciel;     for (int i = 0; i < n; i++) {       string x;       int y;       cin >> x >> y;       if (x ==  DEF )         def.push_back(y);       else         atk.push_back(y);     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       ciel.push_back(x);     }     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(ciel.rbegin(), ciel.rend());     int answer1 = 0;     for (int i = 0; i < min(atk.size(), ciel.size()); i++) {       if (atk[i] < ciel[i]) {         answer1 += ciel[i] - atk[i];       }     }     int bad = 0;     int answer2 = 0;     sort(ciel.begin(), ciel.end());     int u[100] = {};     for (int j = 0; j < def.size(); j++) {       int ok = 0;       for (int i = 0; i < ciel.size(); i++) {         if (!u[i] && def[j] < ciel[i]) {           ok = 1;           u[i] = true;           break;         }       }       if (!ok) bad = true;     }     for (int j = 0; j < atk.size(); j++) {       int ok = 0;       for (int i = 0; i < ciel.size(); i++) {         if (!u[i] && atk[j] <= ciel[i]) {           answer2 += ciel[i] - atk[j];           ok = 1;           u[i] = true;           break;         }       }       if (!ok) bad = true;     }     for (int i = 0; i < m; i++) {       if (!u[i]) {         answer2 += ciel[i];       }     }     if (!bad) answer1 = max(answer1, answer2);     cout << answer1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, step[1000000];   long long a[2 * 1000000], pref[2 * 1000000 + 1];   int calcLen(int strt) {     int curr = strt, res = 0;     while (curr < strt + n) curr += step[curr % n], res++;     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < (n); i++) cin >> a[i];     for (int i = 0; i < (n); i++) a[n + i] = a[i];     for (int i = 0; i < (2 * n); i++) pref[i + 1] = pref[i] + a[i];     for (int query = 0; query < (q); query++) {       long long b;       cin >> b;       int lo = 0, hi = 0;       while (lo < n) {         while (lo < n && (hi == lo + n + 1 || pref[hi] > pref[lo] + b)) {           step[lo] = hi - lo - 1;           lo++;         }         hi++;       }       int res = INT_MAX;       pair<int, int> mn = make_pair(INT_MAX, -1);       for (int i = 0; i < (n); i++)         if (step[(i + n - 1) % n] <= step[i]) mn = min(mn, make_pair(step[i], i));       for (int i = 0; i < (mn.first); i++)         res = min(res, calcLen((mn.second + i) % n));       cout << res <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[60][60];   bool check[60];   int main() {     int n, x;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       int t = 0;       for (int j = 0; j < n; j++) check[a[i][j]] = true;       for (int j = 1; j <= n; j++)         if (check[j] == true) t++;       if (t == n - 1) {         x = i;         break;       }     }     for (int i = 0; i < n; i++) {       if (a[x][i] == 0)         cout << n <<    ;       else         cout << a[x][i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long int mod = 1e9 + 7;   const long long int mod1 = 998244353;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int rand(long long int l, long long int r) {     uniform_int_distribution<long long int> uid(l, r);     return uid(rng);   }   const long long int N = 2e5 + 5;   vector<pair<long long int, long long int> > v;   long long int dsu[N], sz[N], a[N];   bool active[N];   long long int odd = 0;   long long int root(long long int u) {     return (dsu[u] == u) ? u : (dsu[u] = root(dsu[u]));   }   long long int n;   void uni(long long int u, long long int v) {     if (u < 1 || u > n) return;     u = root(u), v = root(v);     if (u == v) return;     odd -= (sz[u] & 1);     odd -= (sz[v] & 1);     sz[v] += sz[u];     odd += (sz[v] & 1);     dsu[u] = v;   }   void solve() {     cin >> n;     for (long long int i = 1; i <= n; i++) dsu[i] = i, sz[i] = 1;     for (long long int i = 1; i <= n; i++) cin >> a[i], v.push_back({a[i], i});     sort(v.begin(), v.end());     long long int pt = 0;     while (1) {       long long int val = v[pt].first;       while (pt < n && v[pt].first == val) {         active[v[pt].second] = 1;         odd++;         if (active[v[pt].second - 1]) {           uni(v[pt].second - 1, v[pt].second);         }         if (active[v[pt].second + 1]) {           uni(v[pt].second, v[pt].second + 1);         }         pt++;       }       if (odd && pt != n) {         cout <<  NO  <<   n ;         return;       }       if (pt == n) break;     }     cout <<  YES  <<   n ;   }   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     clock_t clk = clock();     long long int t = 1;     while (t--) {       solve();     }     cerr <<   n  << (double)(clock() - clk) / CLOCKS_PER_SEC;     return 0;   }
#include<iostream>   using namespace std;      int main(){    int w,h,n,t;    cin>>t;    while(t--){     int s=1;     cin>>w>>h>>n;     int size=w*h;     while(size>s){      if(w%2==0 && h%2!=0){       w=w/2;       s=s*2;      }      else if(h%2==0 && w%2!=0){       h=h/2;       s=s*2;      }      else if(w%2==0 && h%2==0){       w=w/2;       s=s*2;      }      else {       break;      }     }     if(s>=n){      cout<< Yes <<  n ;     }     else{      cout<< No <<  n ;     }    }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int xa, ya;     int xb, yb;     int xc, yc;     double k, b, y;     scanf( %d %d , &xa, &ya);     scanf( %d %d , &xb, &yb);     scanf( %d %d , &xc, &yc);     if (xa != xb) {       k = (double)(yb - ya) / (xb - xa);       b = ya - (double)(yb - ya) / (xb - xa) * xa;       y = k * xc + b;     }     if (xa < xb) puts(y < yc ?  LEFT  : (yc < y ?  RIGHT  :  TOWARDS ));     if (xa == xb)       puts(xc == xa ?  TOWARDS  : ((xc < xa) != (yb < ya) ?  LEFT  :  RIGHT ));     if (xa > xb) puts(y < yc ?  RIGHT  : (yc < y ?  LEFT  :  TOWARDS ));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, inf = 1e9;   int n;   int a[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     sort(a + 1, a + 1 + n);     long long lsum = 0, rsum = 0;     for (int i = 1; i <= n / 2; ++i) lsum += a[i];     for (int i = n / 2 + 1; i <= n; ++i) rsum += a[i];     long long ans = lsum * lsum + rsum * rsum;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool prime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int main() {     long long n, ans;     cin >> n;     if (prime(n))       ans = 1;     else if (n % 2 == 0)       ans = 2;     else if (prime(n - 2))       ans = 2;     else       ans = 3;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, n, c[123456], a[1111234], b[1125678], d[123456], l, ll, s, t, k,       m, xh, x, x1, y, z;   string p, r, w;   map<string, long long> q;   int main() {     cin >> n >> k >> m;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     cout << a[m] - a[m - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, s, bigx[11], bigy[11], smlx[11], smly[11];   int main() {     scanf( %d%d%d%d , &n, &m, &k, &s);     for (int i = 1; i <= k; i++)       bigx[i] = bigy[i] = -2020, smlx[i] = smly[i] = 2 * 2020;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++) {         int t;         scanf( %d , &t);         bigx[t] = max(bigx[t], i + j);         bigy[t] = max(bigy[t], i - j);         smlx[t] = min(smlx[t], i + j);         smly[t] = min(smly[t], i - j);       }     int a, b, ans = -1;     scanf( %d , &a);     for (int i = 1; i < s; i++) {       scanf( %d , &b);       ans = max(ans, max(abs(bigx[a] - smlx[b]), abs(bigx[b] - smlx[a])));       ans = max(ans, max(abs(bigy[a] - smly[b]), abs(bigy[b] - smly[a])));       a = b;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:500000000 )   using namespace std;   int A[105];   int f[105];   int main() {     int n, i, p, x, y;     cin >> n;     for (i = 0; i < n; i++) cin >> A[i], f[A[i]] = i;     int q;     cin >> q;     while (q--) {       scanf( %d %d %d , &p, &x, &y);       if (p == 1) {         int res = 0;         while (x <= y) {           while (x < y && f[x + 1] > f[x]) x++;           x++;           res++;         }         printf( %d n , res);       } else {         x--;         y--;         int L = A[x], R = A[y];         swap(A[x], A[y]);         f[L] = y;         f[R] = x;       }     }   }
#include <bits/stdc++.h>   #include<limits>   using namespace std;   #define ll long long   #define vi vector<int>   #define vll vector<long long>   #define pi pair<int,int>   #define pll pair<ll,ll>   #define FASTIO   ios_base::sync_with_stdio(false);cin.tie(NULL);   #define unmap unordered_map   #define pb push_back   ll max2(ll x, ll y) {    if (x > y)     return x;    else     return y;   }   ll min2(ll x, ll y) {    if (x < y)     return x;    else     return y;   }   ll gcd(ll a, ll b) {    if (b == 0)     return a;    return gcd(b, a % b);   }   void solve(){          unsigned ll n;       cin>>n;       unsigned ll p=1,sum=0;          while(n>1){           sum+=p;           p*=2;           n>>=1;       }       cout<<sum<<endl;   }      int main() {    FASTIO    ll t = 1;    int q = 0;          cin >> t;       while (t--) {               solve();    }       return 0;      }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10 * 1000 + 10, maxm = (1 << 17), mod = (int)1e9 + 7,             hash = 701, inf = (1 << 29) + 3;   const double pi = 3.14159265359, ee = 2.71828;   int dis[30][30], d[(1 << 21)], dd[maxn], l[110], n, m, k, u;   vector<int> q, bf;   void bfs(int v) {     dd[v] = 0, bf.push_back(v);     for (int i = 0; i < bf.size(); i++) {       v = bf[i];       for (int j = 0; j < m; j++) {         if (v + l[j] <= n)           if (dd[v + l[j]] > dd[v] + 1)             dd[l[j] + v] = dd[v] + 1, bf.push_back(v + l[j]);         if (v - l[j] >= 0)           if (dd[v - l[j]] > dd[v] + 1)             dd[v - l[j]] = dd[v] + 1, bf.push_back(v - l[j]);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> k >> m;     for (int i = 0; i < k; i++) cin >> u, q.push_back(u), q.push_back(u - 1);     for (int i = 0; i < m; i++) cin >> l[i];     for (int i = 0; i < q.size(); i++) {       for (int j = 0; j <= n; j++) dd[j] = inf;       bfs(q[i]);       for (int j = 0; j < q.size(); j++) dis[i][j] = dd[q[j]];     }     for (int i = 1; i < (1 << q.size()); i++) d[i] = inf, u = 0;     for (int i = 1; i < (1 << q.size()); i++, u = 0) {       while (!(i & (1 << u))) u++;       for (int j = 0; j < q.size(); j++)         if (j != u && (i & (1 << j)))           d[i] = min(d[i], d[i ^ (1 << u) ^ (1 << j)] + dis[u][j]);     }     cout << (d[(1 << q.size()) - 1] == inf ? -1 : d[(1 << q.size()) - 1]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long> pos, neg, a;       for (int i = 0; i < n; i++) {         long long x;         cin >> x;         a.push_back(x);         if (x >= 0)           pos.push_back(x);         else           neg.push_back(x);       }       sort((pos).begin(), (pos).end());       reverse((pos).begin(), (pos).end());       sort((neg).begin(), (neg).end());       long long ans = 1;       for (int i = 0; i < 5; i++) {         ans *= a[i];       }       for (int m = 0; m <= 4 and m <= neg.size(); m += 2) {         int p = 5 - m;         if (p > pos.size()) continue;         long long pro = 1;         for (int i = 0; i < p; i++) pro *= pos[i];         for (int i = 0; i < m; i++) pro *= neg[i];         ans = max(ans, pro);       }       if (neg.size() >= 5) {         reverse((neg).begin(), (neg).end());         long long temp = 1;         for (int i = 0; i < 5; i++) {           temp *= neg[i];         }         ans = max(ans, temp);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int tree[4 * N];   int n, m;   void update(int root, int lo, int hi, int u, int v) {     if (v < lo || u > hi) return;     if (u <= lo && hi <= v) {       tree[root]++;       return;     }     int mid = (lo + hi) / 2, left = root * 2, right = left + 1;     update(left, lo, mid, u, v);     update(right, mid + 1, hi, u, v);     tree[root] = tree[left] + tree[right];   }   int query(int root, int lo, int hi, int u, int v) {     if (v < lo || u > hi) return 0;     if (u <= lo && hi <= v) return tree[root];     int mid = (lo + hi) / 2, left = root * 2, right = left + 1;     return query(left, lo, mid, u, v) + query(right, mid + 1, hi, u, v);   }   int main() {     scanf( %d%d , &n, &m);     int i, cur = 0, next, start, end, p1, p2;     long long ans = 1;     for (i = 1; i <= n; ++i) {       next = (cur + m) % n;       start = min(cur, next) + 1;       end = max(cur, next) + 1;       p1 = query(1, 1, n, start + 1, end - 1);       p2 = 2 * (i - 1) - query(1, 1, n, start, start) - query(1, 1, n, end, end) -            p1;       ans += min(p1, p2) + 1;       update(1, 1, n, start, start);       update(1, 1, n, end, end);       cur = next;       printf( %lld  , ans);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   double ed(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     double ax, ay, bx, by, tx, ty;     int n;     cin >> ax >> ay >> bx >> by >> tx >> ty >> n;     double td = 0;     vector<pair<double, int>> p1(n), p2(n);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       td += 2 * ed(x, y, tx, ty);       p1[i] = {ed(x, y, ax, ay) - ed(x, y, tx, ty), i};       p2[i] = {ed(x, y, bx, by) - ed(x, y, tx, ty), i};     }     sort(p1.begin(), p1.end());     sort(p2.begin(), p2.end());     double ans = min(td + p1[0].first, td + p2[0].first);     if (n == 1) {       cout << setprecision(12) << ans;       return 0;     }     if (p1[0].second != p2[0].second) {       ans = min(ans, td + p1[0].first + p2[0].first);     } else {       ans = min(ans, min(td + p1[0].first + p2[1].first,                          td + p1[1].first + p2[0].first));     }     cout << setprecision(12) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> tree[4 * 100005 + 10];   int a[100005];   int dp[100005];   int n, s, l;   int f[4 * 100005 + 10];   void init(int node, int b, int e) {     if (b == e) {       tree[node].first = tree[node].second = a[b];       return;     }     int mid = (b + e) / 2;     int lft = node * 2;     int rght = lft + 1;     init(lft, b, mid);     init(rght, mid + 1, e);     tree[node].first = min(tree[lft].first, tree[rght].first);     tree[node].second = max(tree[lft].second, tree[rght].second);     return;   }   pair<int, int> query(int node, int b, int e, int i, int j) {     if (i <= b && j >= e) return tree[node];     int mid = (b + e) / 2;     int lft = node * 2;     int rght = lft + 1;     if (j <= mid)       return query(lft, b, mid, i, j);     else if (mid < i)       return query(rght, mid + 1, e, i, j);     else {       pair<int, int> c, d, ans;       c = query(lft, b, mid, i, j);       d = query(rght, mid + 1, e, i, j);       ans.first = min(c.first, d.first);       ans.second = max(c.second, d.second);       return ans;     }   }   void update_(int node, int b, int e, int indx) {     if (b == e) {       f[node] = dp[indx];       return;     }     int mid = (b + e) / 2;     if (indx <= mid)       update_(node * 2, b, mid, indx);     else       update_(node * 2 + 1, mid + 1, e, indx);     f[node] = min(f[node * 2], f[node * 2 + 1]);   }   int get(int node, int b, int e, int i, int j) {     if (b >= i && j >= e) return f[node];     int mid = (b + e) / 2;     int c, d;     if (j <= mid)       return get(node * 2, b, mid, i, j);     else if (mid < i)       return get(node * 2 + 1, mid + 1, e, i, j);     else {       c = get(node * 2, b, mid, i, j);       d = get(node * 2 + 1, mid + 1, e, i, j);       return min(c, d);     }   }   int solve() {     pair<int, int> tmp;     if (l > n) return 20000000;     tmp = query(1, 1, n, 1, l);     if (tmp.second - tmp.first <= s)       dp[l] = 1;     else       return 20000000;     int j = 1;     update_(1, 1, n, l);     for (int i = l + 1; i <= n; i++) {       while (j <= i) {         tmp = query(1, 1, n, j, i);         if (tmp.second - tmp.first <= s) break;         j++;       }       if (i - j + 1 >= l) {         if (j == 1)           dp[i] = 1;         else           dp[i] = get(1, 1, n, j - 1, i - l) + 1;       } else         dp[i] = 20000000;       update_(1, 1, n, i);     }     return dp[n];   }   int main() {     cin >> n >> s >> l;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     init(1, 1, n);     for (int i = 0; i <= 4 * n; i++) f[i] = 20000000;     int res = solve();     if (res >= 20000000)       cout << -1;     else       cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   const long long int mod = 1000000007;   long long int f(long long int x, long long int k) {     long long int res = 1;     while (k) {       if (k & 1) res = res * x % mod;       x = x * x % mod;       k >>= 1;     }     return res;   }   int main() {     cin >> n;     n++;     if (n == 1)       cout <<  1 ;     else {       long long int a = f(4, n - 2);       long long int b = f(2, n - 2);       a = a * 2 % mod;       cout << (a + b) % mod;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int long long> fact(1000001);   int long long sm, a, b, n;   bool check() {     int long long m = sm;     while (m) {       if (m % 10 != b && m % 10 != a) return 0;       m /= 10;     }     return 1;   }   int long long inc(int long long t, int long long p) {     if (p == 0) return 1;     if (p % 2 == 0) {       int long long e = inc(t, p / 2);       return (e * e) % 1000003;     } else {       return (inc(t, p - 1) * t) % 1000003;     }   }   int long long comb(int long long i, int long long m) {     return (fact[m] *             (inc(((fact[m - i] * fact[i]) % 1000003), 1000003 - 2) % 1000003)) %            1000003;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     int long long a, b;     cin >> a >> b;     fact[0] = fact[1] = 1;     for (long long i = 2; i <= 1000000; i++)       fact[i] = i * fact[i - 1], fact[i] %= 1000003;     cout << comb(b, a + b) - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double net, res;     int d, h, vel, e;     cin >> d >> h >> vel >> e;     net = e - (vel / (3.14159265358979323846 * d * d / 4.0));     res = -h / net;     if (res <= 0 || res > 10000)       cout <<  NO n ;     else       cout <<  YES n  << fixed << setprecision(12) << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, comp_num;   vector<vector<int> > g;   vector<bool> used;   vector<vector<int> > comp;   vector<long long int> dv;   vector<long long int> dv_in_comp;   vector<int> components;   void dfs(int v) {     used[v] = true;     comp[comp.size() - 1].push_back(v);     dv_in_comp[dv_in_comp.size() - 1] += dv[v];     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (!used[to]) dfs(to);     }   }   void find_comps() {     for (int i = 0; i < n; i++) {       if (!used[i]) {         comp.push_back(vector<int>());         dv_in_comp.push_back(0);         dfs(i);       }     }   }   int main() {     cin >> n >> m;     g.resize(n);     dv.resize(n, 0);     used.resize(n, false);     components.resize(n, -1);     int ui, vi;     for (int i = 0; i < m; i++) {       scanf( %d%d , &ui, &vi);       ui--;       vi--;       g[ui].push_back(vi);       g[vi].push_back(ui);       dv[ui]++;       dv[vi]++;     }     find_comps();     int total = 0;     for (int i = 0; i < comp.size(); i++) {       if (dv_in_comp[i] > 2 * (comp[i].size() - 1)) {         total += 0;       } else         total++;     }     cout << total;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long sl = s.length();     long long one = 0;     long long two = 0;     long long three = 0;     long long i;     for (i = 0; i < sl; i = i + 2) {       if (s[i] -  0  == 1) {         one++;       } else if (s[i] -  0  == 2) {         two++;       } else {         three++;       }     }     vector<char> v;     for (i = 0; i < one; i++) {       v.push_back( 1 );       v.push_back( + );     }     for (i = 0; i < two; i++) {       v.push_back( 2 );       v.push_back( + );     }     for (i = 0; i < three; i++) {       v.push_back( 3 );       v.push_back( + );     }     if (v[v.size() - 1] ==  + ) {       for (i = 0; i < v.size() - 1; i++) {         cout << v[i];       }     } else {       for (i = 0; i < v.size(); i++) {         cout << v[i];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   int h[N], ne[N], e[N], idx;   int n;   long long sz[N], dp[N], ans;   void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }   void dfs(int u, int fa) {     sz[u] = 1;     for (int i = h[u]; ~i; i = ne[i]) {       int j = e[i];       if (j == fa) continue;       dfs(j, u);       sz[u] += sz[j];     }   }   void dfs2(int u, int fa) {     for (int i = h[u]; ~i; i = ne[i]) {       int j = e[i];       if (j == fa) continue;       dp[j] = dp[u] + n - 2 * sz[j];       dfs2(j, u);     }   }   void init(int u, int fa) {     ans += sz[u];     for (int i = h[u]; ~i; i = ne[i]) {       int j = e[i];       if (j == fa) continue;       init(j, u);     }   }   int main() {     cin >> n;     memset(h, -1, sizeof h);     for (int i = 1; i < n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       add(a, b), add(b, a);     }     dfs(1, 1);     init(1, 1);     dp[1] = ans;     dfs2(1, 1);     long long maxx = 0;     for (int i = 1; i <= n; ++i) maxx = max(maxx, dp[i]);     cout << maxx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b, long long& x, long long& y) {     cerr <<  a ==   << a <<   b ==   << b << endl;     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     cerr <<  x1 ==   << x1 <<   y1 ==   << y1 << endl;     x = y1 - (b / a) * x1;     y = x1;     cerr <<  x ==   << x <<   y ==   << y << endl;     return d;   }   long long fact(long long a) {     long long ans = 1;     for (int i = 2; i <= a; ++i) ans = (ans * i) % 1000000007;     return ans;   }   int main() {     int n;     cin >> n;     long long ans = fact(2 * n - 1) % 1000000007;     long long tmp = (fact(n) * fact((2 * n - 1) - n)) % 1000000007;     long long x, y;     cerr << tmp <<     << ans << endl;     gcd(tmp, 1000000007, x, y);     cerr << x << endl;     while (x < 0) x += 1000000007;     ans = (ans * (x % 1000000007)) % 1000000007;     if (n == 2)       cout << 4 << endl;     else       cout << (ans * 2 - n) % 1000000007;     return 0;   }