malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool vouel(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u );   }   int main() {     string s;     cin >> s;     string new_s =   ;     bool same = false;     int streak = 0;     char c =  0 ;     for (int i = 0; i < s.length(); ++i) {       if (vouel(s[i])) {         new_s += s[i];         same = false;         streak = 0;         c =  0 ;       } else {         if (streak == 2) {           if (same) {             if (s[i] == c) {               new_s += s[i];               continue;             } else {               new_s +=    ;               new_s += s[i];               same = true;               streak = 1;               c = s[i];             }           } else {             new_s +=    ;             new_s += s[i];             same = true;             streak = 1;             c = s[i];           }         } else if (streak == 1) {           if (s[i] == c) {             streak += 1;             same = true;             new_s += s[i];           } else {             streak += 1;             same = false;             c = s[i];             new_s += s[i];           }         } else if (streak == 0) {           new_s += s[i];           c = s[i];           same = true;           streak += 1;         }       }     }     cout << new_s <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long INF = 1e18;   const long long NEG_INF = -1 * (1e18);   using namespace std;   void usaco(string prob) {     freopen((prob +  .in ).c_str(),  r , stdin);     freopen((prob +  .out ).c_str(),  w , stdout);   }   bool prime(int n) {     if (n < 2) return false;     for (int x = 2; x * x <= n; x++) {       if (n % x == 0) return false;     }     return true;   }   vector<int> getFactors(int n) {     vector<int> f;     for (int x = 2; x * x <= n; x++) {       while (n % x == 0) {         f.push_back(x);         n /= x;       }     }     if (n > 1) f.push_back(n);     return f;   }   const long long MOD = 1e9 + 7;   vector<long long> fact(1005, 1), inv(1005, 1);   long long binPow(long long x, long long n) {     int res = 1;     while (n) {       if (n & 1) res = (1LL * res * x) % MOD;       x = (1LL * x * x) % MOD;       n >>= 1;     }     return res;   }   void binSearch(long long n, long long pos, long long &cntBig,                  long long &cntLess) {     long long l = 0, r = n;     while (l < r) {       long long mid = (l + r) / 2;       if (mid > pos) {         cntBig++;         r = mid;       } else {         if (mid != pos) {           cntLess++;         }         l = mid + 1;       }     }   }   long long C(long long n, long long k) {     if (k > n) {       return 0;     }     long long mult = (fact[n] * inv[k]) % MOD;     mult = (mult * inv[n - k]) % MOD;     return mult;   }   void solve() {     long long n, x, pos;     cin >> n >> x >> pos;     fact[0] = 1;     for (long long i = 1; i <= n; i++) {       fact[i] = (fact[i - 1] * i) % MOD;       inv[i] = (binPow(fact[i], MOD - 2LL)) % MOD;     }     long long cntBig = 0, cntLess = 0;     binSearch(n, pos, cntBig, cntLess);     long long hasLess = 0, hasBig = 0;     hasLess = x - 1;     hasBig = n - x;     long long rem = n - cntBig - cntLess - 1;     long long ans = 1;     long long cBig = C(hasBig, cntBig);     long long cLess = C(hasLess, cntLess);     cBig = (cBig * fact[cntBig]) % MOD;     cLess = (cLess * fact[cntLess]) % MOD;     ans = (ans * cBig) % MOD;     ans = (ans * cLess) % MOD;     ans = (ans * fact[rem]) % MOD;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long TC = 1;     for (long long tt = 1; tt <= (long long)(TC); ++tt) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000001;   const int MAXN = 251;   struct Person {     int cnt, last;     int id;     Person(int id = -1) : id(id) {       cnt = 0;       last = 0;     }     bool operator<(const Person& p) const {       if (cnt != p.cnt) return cnt > p.cnt;       return last < p.last;     }   };   int n, k, m, a;   vector<Person> score;   vector<int> res;   bool can_win(int id) {     vector<Person> tmp(score);     if (m - a > 0) {       tmp[id].cnt += m - a;       tmp[id].last = m - 1;     }     if (tmp[id].cnt == 0) return false;     sort(tmp.begin(), tmp.end());     for (int i = 0; i < k; i++)       if (tmp[i].id == score[id].id) return true;     return false;   }   bool can_lose(int id) {     if (score[id].cnt == 0) return true;     int ptop = a;     int better = id;     for (int j = id + 1; j < n; j++) {       Person cur(score[j]);       while (ptop < m && score[id] < cur) {         cur.cnt++;         cur.last = ptop++;       }       if (cur < score[id]) better++;     }     return better >= k;   }   int main() {     scanf( %d%d%d%d , &n, &k, &m, &a);     score.resize(n);     res.resize(n);     for (int i = 0; i < n; i++) score[i].id = i;     for (int i = 0; i < a; i++) {       int id;       scanf( %d , &id);       id--;       score[id].cnt++;       score[id].last = i;     }     sort(score.begin(), score.end());     for (int i = 0; i < n; i++) {       int val = 0;       bool w = can_win(i);       bool l = can_lose(i);       if (w && l)         val = 2;       else if (w && !l)         val = 1;       else if (!w && l)         val = 3;       else         throw;       res[score[i].id] = val;     }     for (int i = 0; i < n; i++) printf( %d  , res[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1505;   int n, a[maxn], sum[maxn], ans, val, ID;   int d[maxn * maxn], cnt;   vector<int> v[maxn * maxn];   vector<int> vv[maxn];   unordered_map<int, int> mp, L[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum[i] = sum[i - 1] + a[i];     for (int i = 1; i <= n; i++) {       for (int j = i - 1; ~j; j--) {         int t = sum[i] - sum[j];         d[++cnt] = t;         if (!L[i][t]) L[i][t] = j + 1, vv[i].push_back(t);       }     }     sort(d + 1, d + 1 + cnt);     cnt = unique(d + 1, d + 1 + cnt) - d - 1;     for (int i = 1; i <= cnt; i++) mp[d[i]] = i;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < vv[i].size(); j++) {         int t = vv[i][j], id = mp[t];         if (v[id].empty() || v[id].back() < L[i][t]) {           v[id].push_back(i);         }         if (ans < v[id].size()) {           ans = v[id].size();           val = t;           ID = id;         }       }     }     printf( %d n , ans);     for (int i : v[ID]) {       printf( %d %d n , L[i][val], i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 51123987;   int len, n;   char s[4000010], tmp[2000010];   long long p[4000010];   long long sum, ans;   long long le[4000010], ri[4000010];   int main() {     scanf( %d%s , &len, tmp + 1);     s[++n] =  @ ;     for (int i = 1; i <= len; i++) {       s[++n] =  # ;       s[++n] = tmp[i];     }     s[++n] =  # ;     long long id = 0, mx = 0;     for (long long i = 1; i <= n; i++) {       p[i] = ((mx > i) ? min(p[id * 2 - i], mx - i) : 1);       while (s[i + p[i]] == s[i - p[i]]) p[i]++;       if (i + p[i] > mx) {         mx = i + p[i];         id = i;       }       sum += 1ll * p[i] / 2;       sum %= mod;       le[i - p[i]]++;       le[i]--;       ri[i - 1]++;       ri[i + p[i] - 1]--;     }     sum = sum * (sum - 1) / 2;     sum %= mod;     for (int i = 1; i <= n; i++) {       le[i] += le[i - 1];       ri[i] += ri[i - 1];       if (i % 2 == 0) {         sum -= 1ll * ans * le[i] % mod;         sum = (sum + mod) % mod;         ans = (ans + ri[i]) % mod;       }     }     cout << (sum + mod) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const int dx[4] = {0, 0, -1, 1};   const int dy[4] = {-1, 1, 0, 0};   int n, m, cnt, cur;   char a[N][N], s[N][N];   bool vis[N][N];   inline void dfs(int x, int y) {     vis[x][y] = 1;     ++cur;     for (int xx, yy, k = 0; k < 4; k++) {       xx = x + dx[k], yy = y + dy[k];       if (!(0 <= xx && xx < n && 0 <= yy && yy < m)) continue;       if (!vis[xx][yy] && s[xx][yy] ==  # ) dfs(xx, yy);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  # ) cnt++;     if (cnt <= 2) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  # ) {           for (int u = 0; u < n; u++)             for (int v = 0; v < m; v++) s[u][v] = a[u][v];           s[i][j] =  . ;           cur = 0;           memset(vis, 0, sizeof vis);           try {             for (int u = 0; u < n; u++)               for (int v = 0; v < m; v++)                 if (s[u][v] ==  # ) {                   dfs(u, v);                   if (cur == cnt - 1)                     throw -1;                   else {                     throw 1;                   }                 }           } catch (int res) {             if (res == 1) {               printf( 1 n );               return 0;             }           }         }     printf( 2 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const bool debug = 0;   int main() {     if (!debug) {       cin.tie(0);       cout.tie(0);       ios::sync_with_stdio(0);     }     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       reverse(a.begin(), a.end());       for (int i = 0; i * 2 < n; i++) a[i] *= -1;       for (int i = 0; i < n; i++) cout << a[i] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> a(n);     long long i;     for (i = 0; i < n; i++) cin >> a[i];     map<long long, long long> m;     long long add = 0;     for (i = 0; i < n; i++) {       auto it = m.find(a[i]);       if (it != m.end()) {         pair<long long, long long> p = *it;         long long val = p.second;         m.erase(a[i]);         m.insert(make_pair(a[i], val + 1));       } else {         m.insert(make_pair(a[i], 1));       }       auto itneg = m.find(a[i] - 1);       auto itpos = m.find(a[i] + 1);       if (itneg != m.end()) {         pair<long long, long long> p = *itneg;         add -= p.second;       }       if (itpos != m.end()) {         pair<long long, long long> p = *itpos;         add += p.second;       }     }     long long ans = add;     long long ch = 0;     for (i = 0; i < n; i++) {       ans += a[i] * (i * 2 - (n - 1));       while (ans >= 1000000000000000000) {         ch++;         ans -= 1000000000000000000;       }       while (ans < 0) {         ch--;         ans += 1000000000000000000;       }     }     if (ch >= 0) {       if (ch == 0)         cout << ans << endl;       else {         cout << ch;         vector<int> nums(18);         for (i = 17; i >= 0; i--) {           nums[i] = ans % 10;           ans /= 10;         }         for (i = 0; i < 18; i++) {           cout << nums[i];         }         cout << endl;       }     } else {       ch++;       ans -= 1000000000000000000;       if (ch == 0) {         cout << ans << endl;       } else {         ans = abs(ans);         cout <<  - ;         if (ch < 0) cout << abs(ch);         vector<int> nums(18);         for (i = 17; i >= 0; i--) {           nums[i] = ans % 10;           ans /= 10;         }         for (i = 0; i < 18; i++) {           cout << nums[i];         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long min(long long x, long long y) {     if (x < y) {       return x;     }     return y;   }   int main() {     long long a, b, c;     cin >> a >> b >> c;     cout << min(min(a + b + c, 2 * a + 2 * b), min(2 * a + 2 * c, 2 * b + 2 * c));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long const mod = 1e9 + 7;   long long const inf = 2e18;   inline long long add(long long a, long long b) {     return (a % mod + b % mod + mod) % mod;   }   inline long long mul(long long a, long long b) {     return (a % mod * b % mod + mod) % mod;   }   inline long long sub(long long a, long long b) {     return (a % mod - b % mod + mod) % mod;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long modexp(long long x, long long n) {     if (n == 0) {       return 1;     } else if (n & 1) {       return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;     } else {       return (modexp((x * x) % mod, n / 2) % mod);     }   }   long long modinv(long long n) { return modexp(n, mod - 2); }   long long const MAX = 200001;   long long n;   vector<long long> gr[MAX];   int shortest_cycle(int n) {     int ans = INT_MAX;     for (int i = 0; i < n; i++) {       if (gr[i].size() == 0) continue;       vector<int> dist(n, (int)(1e9));       vector<int> par(n, -1);       dist[i] = 0;       queue<int> q;       q.push(i);       while (!q.empty()) {         int x = q.front();         q.pop();         for (int child : gr[x]) {           if (dist[child] == (int)(1e9)) {             dist[child] = 1 + dist[x];             par[child] = x;             q.push(child);           } else if (par[x] != child and par[child] != x)             ans = min(ans, dist[x] + dist[child] + 1);         }       }     }     if (ans == INT_MAX)       return -1;     else       return ans;   }   void solve() {     cin >> n;     long long a[MAX];     for (int i = 0; i < (n); i++) cin >> a[i];     vector<long long> dp[64];     for (int b = 0; b < (64); b++) {       long long c = 0;       vector<long long> v;       for (int i = 0; i < (n); i++) {         if (a[i] & (1LL << b)) {           c++;           v.push_back(i);         }       }       if (c >= 3) {         cout <<  3 n ;         return;       }       if (v.size() == 2) {         gr[v[0]].push_back(v[1]);         gr[v[1]].push_back(v[0]);       }     }     cout << shortest_cycle(n);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T = 1;     for (int t = 1; t <= T; t++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void p(double t) {     cout << fixed << setprecision(13) << t << endl;     exit(0);   }   struct tank {     int hp, time, lo, hi, prob;     void scan() {       cin >> hp >> time >> lo >> hi >> prob;       prob = 100 - prob;     }   };   int moven;   vector<int> moves;   tank tanks[2];   double dp[201][201][70];   double curdp[70];   int main() {     for (int i = 0; i < 2; i++) {       tanks[i].scan();     }     if (tanks[0].prob == 0) {       p(0);     }     if (tanks[1].prob == 0) {       p(1);     }     for (int movet = 0; movet < tanks[0].time * tanks[1].time; movet++) {       for (int i = 0; i < 2; i++) {         if (movet % tanks[i].time == 0) {           moves.push_back(i);           moven++;         }       }     }     dp[tanks[0].hp][tanks[1].hp][0] = 1.;     for (int i = tanks[0].hp; i > 0; i--) {       for (int j = tanks[1].hp; j > 0; j--) {         memset(curdp, 0, sizeof(curdp));         double cursum = 0;         double ratio = 1;         for (int k = 0; k < moven; k++) {           int cur = moves[k];           cursum += dp[i][j][k];           dp[i][j][k] = 0;           curdp[k] += cursum;           cursum *= ((100 - tanks[cur].prob) * 0.01);           ratio *= ((100 - tanks[cur].prob) * 0.01);         }         for (int k = 0; k < moven; k++) {           int cur = moves[k];           curdp[k] += cursum / (1 - ratio);           cursum *= ((100 - tanks[cur].prob) * 0.01);         }         for (int k = 0; k < moven; k++) {           int nk = (k + 1) % moven;           int cur = moves[k];           double p = curdp[k] * (tanks[cur].prob * 0.01 /                                  (tanks[cur].hi - tanks[cur].lo + 1));           if (cur == 0) {             for (int amt = tanks[cur].lo; amt <= tanks[cur].hi; amt++) {               dp[i][max(0, j - amt)][nk] += p;             }           } else {             for (int amt = tanks[cur].lo; amt <= tanks[cur].hi; amt++) {               dp[max(0, i - amt)][j][nk] += p;             }           }         }       }     }     double ans = 0;     for (int i = 1; i <= tanks[0].hp; i++) {       for (int k = 0; k < moven; k++) {         ans += dp[i][0][k];       }     }     p(ans);   }
#include <bits/stdc++.h>   using namespace std;   const int L = 21;   const int N = 1 << L;   int n, ans, a[N], best[N][3];   void add(int mask, int value) {     auto &b = best[mask];     b[2] = value;     if (b[2] > b[1]) swap(b[2], b[1]);     if (b[1] > b[0]) swap(b[1], b[0]);   }   bool possible() {     for (int i = 0; i < (int)(n); i++) {       auto target = ans & ~a[i];       auto &b = best[target];       if (b[0] > i && b[1] > i) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(best, -1, sizeof best);     cin >> n;     for (int i = 0; i < (int)(n); i++) {       cin >> a[i];       add(a[i], i);     }     for (int bit = 0; bit < (int)(L); bit++)       for (int mask = 0; mask < (int)(N); mask++)         if ((mask >> bit) & 1) {           add(mask - (1 << bit), best[mask][0]);           add(mask - (1 << bit), best[mask][1]);         }     for (int bit = (int)(L)-1; bit >= ((int)0); bit--) {       ans |= 1 << bit;       if (!possible()) ans -= 1 << bit;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const int N = (int)(5e5) + 7;   int cnt[N];   int last[N];   int slast[N];   int pcnt[N];   long long psum[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       cnt[x]++;       pcnt[x]++;       psum[x] += x;     }     for (int i = 0; i < N; i++) {       if (i) pcnt[i] += pcnt[i - 1];       if (i) psum[i] += psum[i - 1];     }     int mda = -1;     int tmda = -1;     for (int i = 0; i < N; i++) {       if (cnt[i]) {         tmda = mda;         mda = i;       }       if (cnt[i] >= 2) {         tmda = i;       }       last[i] = mda;       slast[i] = tmda;     }     auto as = [&](int x, int y) {       long long value = (long long)(1e18) + 7;       for (int i = 0; i < N; i += y) {         int l = i, r = min(N - 1, i + y - 1);         if (last[r] >= x) {           value = min(value, (long long)(last[r] / y - (last[r] - x) / y));         }       }       return value;     };     auto ans_two = [&](int x, int y) {       long long best_a = (long long)(1e18) + 7;       long long best_b = (long long)(1e18) + 7;       for (int i = 0; i < N; i += y) {         int l = i, r = min(N - 1, i + y - 1);         if (last[r] >= l && last[r] >= x) {           long long value = last[r] / y - (last[r] - x) / y;           if (value < best_a) {             swap(value, best_a);           }           if (value < best_b) {             swap(value, best_b);           }         }         if (slast[r] >= l && slast[r] >= x) {           long long value = slast[r] / y - (slast[r] - x) / y;           if (value < best_a) {             swap(value, best_a);           }           if (value < best_b) {             swap(value, best_b);           }         }       }       return best_a + best_b;     };     auto check = [&](long long x, int y, long long s) {       if (x >= N) {         return false;       }       if (s - as(2 * x, y) >= x) {         return true;       }       if (s - ans_two(x, y) >= x) {         return true;       }       return false;     };     long long ans = 4;     vector<int> ord_y;     for (int y = 2; y < N; y++) {       ord_y.push_back(y);     }     shuffle(ord_y.begin(), ord_y.end(), rnd);     auto seg_sum = [&](int l, int r) { return psum[r] - (l ? psum[l - 1] : 0); };     auto seg_cnt = [&](int l, int r) { return pcnt[r] - (l ? pcnt[l - 1] : 0); };     auto get_sum = [&](int y) {       long long sum = 0;       for (int i = 0; i < N; i += y) {         int l = i, r = min(N - 1, i + y - 1);         sum += seg_cnt(l, r) * (long long)(i / y);       }       return sum;     };     for (int y : ord_y) {       long long s = get_sum(y);       long long vl = max(2ll, ans / y + 1);       if (check(vl, y, s)) {         int vr = N;         while (vl < vr - 1) {           int vm = (vl + vr) / 2;           if (check(vm, y, s)) {             vl = vm;           } else {             vr = vm;           }         }         ans = vl * (long long)y;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, z, k, w, a, b, res, dist;   vector<int> edge[200005], new_edge[200005];   int deg[200005], depth[200005], far[200005], far_dist[200005];   pair<int, int> dp[200005];   bool has_crit_point[200005];   void DFS(int x, int y, int pre) {     if (y == 0)       depth[x] = 0;     else       depth[x] = depth[y] + 1;     int nxt_pre = pre;     if (deg[x] >= 3) {       has_crit_point[x] = 1;       nxt_pre = x;       if (pre != 0) {         new_edge[pre].push_back(x);         new_edge[x].push_back(pre);       }     }     for (int i : edge[x])       if (i != y) DFS(i, x, nxt_pre), has_crit_point[x] |= has_crit_point[i];     if (!has_crit_point[x]) dp[x].first = x;     for (int i : edge[x])       if (!has_crit_point[i]) {         if (dp[x].first == 0 || depth[dp[i].first] >= depth[dp[x].first])           dp[x].second = dp[x].first, dp[x].first = dp[i].first;         else if (dp[x].second == 0 || depth[dp[i].first] > depth[dp[x].second])           dp[x].second = dp[i].first;       }   }   void solve(int x, int y) {     for (int i : new_edge[x])       if (i != y) solve(i, x);     int p = -1, q = -1, distp = 0, distq = 0;     if (dp[x].second > 0) {       far[x] = x;       far_dist[x] = depth[dp[x].first] + depth[dp[x].second] - 2 * depth[x];     }     for (int i : new_edge[x]) {       int v = i;       int distv =           depth[dp[far[v]].first] + depth[dp[far[v]].second] - depth[far[v]] * 2;       if (p == -1 || depth[far[v]] > depth[p])         q = p, distq = distp, p = far[v], distp = distv;       else if (depth[far[v]] == depth[p] && distv > distp)         q = p, distq = distp, p = far[v], distp = distv;       else if (q == -1 || depth[far[v]] > depth[q])         distq = distv, q = far[v];       else if (depth[far[v]] == depth[q] && distv > distq)         distq = distv, q = far[v];       if (depth[far[v]] > depth[far[x]])         far[x] = far[v], far_dist[x] = far_dist[v];       else if (depth[far[v]] == depth[far[x]] && far_dist[v] > far_dist[x])         far[x] = far[v], far_dist[x] = far_dist[v];     }     if (dp[x].second > 0 && q == -1)       q = x, distq = depth[dp[x].first] + depth[dp[x].second] - 2 * depth[x];     if (p == -1 || q == -1) return;     if (depth[p] + depth[q] - 2 * depth[x] > res) {       res = depth[p] + depth[q] - 2 * depth[x];       dist = distp + distq;       a = p, b = q;     } else if (depth[p] + depth[q] - 2 * depth[x] == res &&                distp + distq > dist) {       dist = distp + distq;       a = p, b = q;     }   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n - 1); i++)       scanf( %d %d , &x, &y), edge[x].push_back(y), edge[y].push_back(x),           deg[x]++, deg[y]++;     for (int i = (1); i <= (n); i++)       if (deg[i] >= 3) x = i;     DFS(x, 0, 0);     a = b = -1;     res = dist = 0;     solve(x, 0);     printf( %d %d n%d %d n , dp[a].first, dp[b].first, dp[a].second,            dp[b].second);     return 0;   }