malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> orig[3];     int a, b, x1, y1, t = 0;     for (int i = 0; i < 3; i++) {       cin >> orig[i].first >> orig[i].second;     }     cout <<  3  << endl;     a = (orig[0].first + orig[1].first) / 2;     b = (orig[0].second + orig[1].second) / 2;     cout << (orig[0].first + orig[1].first - orig[2].first) <<              << (orig[0].second + orig[1].second - orig[2].second) << endl;     a = (orig[1].first + orig[2].first);     b = (orig[1].second + orig[2].second);     cout << (a - orig[0].first) <<     << (b - orig[0].second) << endl;     a = (orig[0].first + orig[2].first);     b = (orig[0].second + orig[2].second);     cout << (a - orig[1].first) <<     << (b - orig[1].second) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, L, cnt, sum[1000005];   char s[1000005], x[1000005];   struct Node {     Node *par, *go[26];     int val, sum, flag, num;     void Clear(int _val) {       par = NULL;       for (int i = 0; i < 26; i++) go[i] = NULL;       sum = flag = 0;       val = _val;     }   } * root, *last, *a[1000005 * 2], *b[1000005 * 2];   void Extend(int w) {     Node *p = last, *np = new Node;     a[++cnt] = np;     np->num = cnt;     np->Clear(p->val + 1);     for (; p && (!(p->go[w])); p = p->par) p->go[w] = np;     if (!p)       np->par = root;     else {       Node *q = p->go[w];       if (q->val == p->val + 1)         np->par = q;       else {         Node *nq = new Node;         a[++cnt] = nq;         nq->num = cnt;         nq->Clear(p->val + 1);         for (int i = 0; i < 26; i++) nq->go[i] = q->go[i];         nq->par = q->par;         q->par = np->par = nq;         for (; p && (p->go[w] == q); p = p->par) p->go[w] = nq;       }     }     last = np;   }   void BuildSAM() {     scanf( %s , &s);     m = strlen(s);     cnt = 0;     root = new Node;     root->Clear(0);     root->num = 0;     last = root;     for (int i = 0; i < m; i++) Extend(s[i] -  a );   }   void DP() {     for (Node *p = last; p; p = p->par) p->sum = 1;     for (int i = 0; i <= m; i++) sum[i] = 0;     for (int i = 1; i <= cnt; i++) sum[a[i]->val]++;     for (int i = 1; i <= m; i++) sum[i] += sum[i - 1];     for (int i = 1; i <= cnt; i++) b[sum[a[i]->val]--] = a[i];     for (int i = cnt; i >= 1; i--) {       Node *p = b[i];       for (int j = 0; j < 26; j++)         if (p->go[j]) {           p->sum += p->go[j]->sum;         }     }   }   int main() {     BuildSAM();     DP();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , &x);       L = strlen(x);       Node *p = root;       int len = 0;       for (int j = 0; j < L; j++) {         int w = x[j] -  a ;         while (p && (!p->go[w])) p = p->par;         if (!p) p = root;         len = min(len, p->val);         if (p->go[w]) {           p = p->go[w];           len++;         }       }       int ans = 0;       for (int j = 0; j < L; j++) {         int w = x[j] -  a ;         while (p && (!p->go[w])) p = p->par;         if (!p) {           p = root;           continue;         }         len = min(len + 1, p->val + 1);         p = p->go[w];         while (p->par && (p->par->val >= L)) p = p->par;         if (p->flag == i) continue;         if (len >= L) {           ans += p->sum;           p->flag = i;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, m;   int f[5001][5001];   char c[5001][5001];   inline int sum(int x, int y, int u, int v) {     return f[u][v] - f[u][y - 1] - f[x - 1][v] + f[x - 1][y - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c[i][j];         c[i][j] -=  0 ;       }     for (int i = 1; i <= 5000; i++)       for (int j = 1; j <= 5000; j++)         f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + c[i][j];     int ans = m * n;     for (int k = 2500; k >= 2; k--) {       int i = 1;       int res = 0;       int sq = k * k;       int t = 0;       do {         int j = 1;         do {           t = sum(i, j, i + k - 1, j + k - 1);           res += min(t, sq - t);           j += k;         } while (j <= m);         i += k;       } while (i <= n);       ans = min(ans, res);     }     writeln(ans);   }
#include <bits/stdc++.h>   using namespace std;   int pos = -1;   void Go(vector<string> &t) {     if (t[++pos] ==  int ) {       cout <<  int ;     } else {       cout <<  pair< ;       Go(t);       cout <<  , ;       Go(t);       cout <<  > ;     }   }   int main() {     int n, i = 0;     bool check = true;     cin >> n;     string t, t1 =   ;     int bal = 0;     int k = 0;     std::vector<std::string> s;     char c;     std::getline(std::cin, t);     std::getline(std::cin, t);     for (int j = 0; j < t.length(); j++) {       if (t[j] !=    ) {         t1 += t[j];       } else {         s.push_back(t1);         t1 =   ;       }     }     s.push_back(t1);     k = s.size();     {       for (int i = 0; i < k - 1; i++) {         if (s[i] ==  pair )           bal++;         else {           bal--;         }         if (bal < 0) {           check = false;         }       }       if (s[k - 1] ==  pair )         bal++;       else {         bal--;       }       if (bal != -1) {         check = false;       }       if (!check) {         cout <<  Error occurred ;         return 0;       }     }     Go(s);   }
#include <bits/stdc++.h>   using namespace std;   void pr(char c, int t) {     while (t--) printf( %c , c);   }   int main() {     int n, i, co(0), s;     map<char, int> c;     char ch;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf(  %c , &ch);       ++c[ch];     }     for (const auto &e : c)       if (e.second & 1) ++co;     if (co < 2) {       printf( 1 n );       for (auto it = c.begin(); it != c.end(); ++it)         if (~it->second & 1) pr(it->first, it->second / 2);       for (auto it = c.begin(); it != c.end(); ++it)         if (it->second & 1) {           pr(it->first, it->second);           c.erase(it);           break;         }       for (auto it = c.rbegin(); it != c.rend(); ++it)         if (~it->second & 1) pr(it->first, it->second / 2);       printf(  n );       return 0;     }     for (s = co; n % s || !(n / s & 1); ++s)       ;     printf( %d n , s);     vector<set<pair<int, char>>> str;     vector<int> tot;     for (auto &e : c)       if (e.second & 1) {         set<pair<int, char>> tmp;         tmp.insert({1, e.first});         str.push_back(tmp);         tot.push_back(1);         --e.second;       }     for (auto &e : c)       while (co < s && e.second) {         set<pair<int, char>> tmp;         tmp.insert({1, e.first});         str.push_back(tmp);         tot.push_back(1);         --e.second;         ++co;       }     map<char, int>::iterator it(c.begin());     for (i = 0; i < s; ++i)       while (tot[i] < n / s) {         while (!it->second) ++it;         int tmp(min(it->second, n / s - tot[i]));         str[i].insert({tmp, it->first});         it->second -= tmp;         tot[i] += tmp;       }     for (i = 0; i < s; ++i) {       if (i) printf(   );       for (auto it = str[i].rbegin(); it != str[i].rend(); ++it)         pr(it->second, it->first / 2);       for (auto it = str[i].begin(); it != str[i].end(); ++it)         pr(it->second, (it->first + 1) / 2);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   using dd = double;   using ldd = long double;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ll n, r;     cin >> n >> r;     vector<ll> arr((ll(1)) << n);     ll sum = 0;     n = ((ll)1) << n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       sum += arr[i];     }     cout.precision(10);     cout << ((dd)sum) / (dd(n)) <<   n ;     for (int i = 0; i < r; ++i) {       ll a, b;       cin >> a >> b;       sum -= arr[a];       sum += b;       arr[a] = b;       cout << ((dd)sum) / (dd(n)) <<   n ;     }   }
#include <bits/stdc++.h>   const int intINF = 999999999;   const long long i64INF = 99999999999999999ll;   const double doubleINF = 9999999999.;   using namespace std;   int abs(int a) {     if (a < 0) a *= -1;     return a;   }   int max(int a, int b) {     if (a < b) a = b;     return a;   }   int main() {     int x1, y1, x2, y2, px, py;     scanf( %d%d%d%d%d%d , &px, &py, &x1, &y1, &x2, &y2);     int m;     int p1, p2;     p1 = abs(y1 - y2);     p2 = abs(x1 - x2);     if ((p1 >= 3 && p2 >= 4) || (p1 >= 4 && p2 >= 3) || p1 > 4 || p2 > 4)       printf( Second n );     else       printf( First n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long dp[100004][2];   int n;   vector<int> g[100004];   int v[100004];   void dfs(int x) {     dp[x][v[x]] = 1;     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i];       dfs(y);       dp[x][1] = dp[x][1] * (dp[y][0] + dp[y][1]) % MOD;       dp[x][1] = (dp[x][1] + dp[y][1] * dp[x][0]) % MOD;       dp[x][0] = dp[x][0] * (dp[y][0] + dp[y][1]) % MOD;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x;       scanf( %d , &x);       g[x].push_back(i);     }     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     dfs(0);     cout << dp[0][1];   }
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }   long long lcm(long long a, long long b) { return a * b / GCD(a, b); }   int lb(int x) { return x & (-x); }   const long long N = 3e5 + 7;   const long long inf = 1e18 + 1;   const long long mod2 = 998244353;   const long long mod1 = 1e9 + 7;   const int P1 = 13331;   const int P2 = 131;   const double eps = 1e-6;   const double dbinf = 1e13 + 7;   const long long mod3 = 10000 + 7;   int n, m;   string s;   struct node {     int v, nxt;   };   node e[N];   int tot;   int head[N];   int ing[N];   int ans;   int dp[N][26];   void add(int u, int v) {     e[++tot] = {v, head[u]};     head[u] = tot;   }   void topsort(void) {     queue<int> q;     for (int i = 1; i <= n; i++) {       if (ing[i] == 0) {         q.push(i);         dp[i][s[i] -  a ] = 1;       }     }     int cnt = 0;     while (!q.empty()) {       int x = q.front();       cnt++;       q.pop();       for (int i = head[x]; i; i = e[i].nxt) {         int v = e[i].v;         if (--ing[v] == 0) q.push(v);         for (int j = 0; j <= 25; j++) {           dp[v][j] = max(dp[v][j], dp[x][j] + (s[v] -  a  == j));         }       }     }     if (cnt != n) {       cout <<  -1 n ;     } else {       int maxn = 0;       for (int i = 1; i <= n; i++) {         for (int j = 0; j <= 25; j++) {           maxn = max(maxn, dp[i][j]);         }       }       cout << maxn <<   n ;     }   }   int main() {     memset(head, 0, sizeof head);     memset(ing, 0, sizeof ing);     cin >> n >> m;     cin >> s;     s =  *  + s;     tot = 0;     for (int i = 1, u = 1, v = 1; i <= m; i++) {       cin >> u >> v;       add(u, v);       ing[v]++;     }     topsort();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long N = 2e5 + 7;   const int mod = 1e9 + 7;   bool cmp(const pair<long long, long long>& a,            const pair<long long, long long>& b) {     return a.first < b.first;   }   long long median(long long a, long long b, long long c, long long d) {     vector<long long> v(4);     v[0] = a;     v[1] = b;     v[2] = c;     v[3] = d;     sort(v.begin(), v.end());     return ((v[1] + v[2]) / 2);   }   void solve() {     long long n, m;     cin >> n >> m;     long long a[n][m];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];       }     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         long long k = median(a[i][j], a[i][m - 1 - j], a[n - 1 - i][j],                              a[n - 1 - i][m - 1 - j]);         ans += abs(k - a[i][j]);       }     }     cout << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, p;   int dp[111][555555], cur[111], a[555555], ld[111], sum[555555], dpp[555555],       bit[1111], sz;   void update(int x, int p) {     while (x <= sz) {       bit[x] = max(bit[x], p);       x += x & (-x);     }   }   int query(int x) {     int res = 0;     while (x >= 1) {       res = max(res, bit[x]);       x -= x & (-x);     }     return res;   }   int main() {     scanf( %d%d%d , &n, &k, &p);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] %= p;     }     if (k * p >= n) {       for (int i = 0; i <= k; i++) {         for (int j = 0; j <= n; j++) dp[i][j] = 1e9;       }       dp[0][0] = 0;       for (int i = 1; i <= k; i++) {         for (int j = 0; j < p; j++) cur[j] = 1e9;         for (int j = 1; j <= n; j++) {           for (int h = 0; h < p; h++) ld[(h + a[j]) % p] = cur[h];           for (int h = 0; h < p; h++) cur[h] = ld[h];           cur[a[j]] = min(cur[a[j]], dp[i - 1][j - 1]);           for (int h = 0; h < p; h++) dp[i][j] = min(dp[i][j], cur[h] + h);         }       }       cout << dp[k][n] << endl;     } else {       for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + a[i]) % p;       sz = 1;       while (sz < p) sz *= 2;       for (int i = 1; i <= n; i++) {         dpp[i] = query(sum[i] + 1) + 1;         update(sum[i] + 1, dpp[i]);       }       if (dpp[n] >= k)         cout << sum[n] << endl;       else         cout << sum[n] + p << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long int n, c = 0;     int x;     cin >> n;     unsigned long long int pos[11] = {}, neg[11] = {}, z = 0, i;     for (i = 0; i < n; i++) {       cin >> x;       if (x == 0)         z++;       else if (x < 0)         neg[(-1) * x]++;       else {         pos[x]++;       }     }     for (int i = 1; i < 11; i++) {       c = c + pos[i] * neg[i];     }     if (z > 1)       z = (z * (z - 1)) / 2;     else {       z = 0;     }     cout << c + z;   }
#include <bits/stdc++.h>   using namespace std;   class union_find {    public:     vector<int> arr;     union_find(int n) {       arr.resize(n);       fill(arr.begin(), arr.end(), -1);     }     int find(int x) { return arr[x] < 0 ? x : arr[x] = find(arr[x]); }     void unite(int x, int y) {       x = find(x), y = find(y);       if (x == y) return;       if (arr[x] > arr[y]) swap(x, y);       arr[x] += arr[y];       arr[y] = x;     }     bool connected(int x, int y) { return find(x) == find(y); }     int size(int x) { return -arr[find(x)]; }   };   template <typename T>   vector<int> coordinate_compression(const T &a, int cur = 0) {     int n = a.size();     T b = a;     sort(b.begin(), b.end());     b.erase(unique(b.begin(), b.end()), b.end());     vector<int> res(n);     for (int i = 0; i < n; i++)       res[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + cur;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<long long> a(2 * n);     for (int i = 0; i < a.size(); i++) cin >> a[i];     vector<int> b = coordinate_compression(a);     union_find uf(2 * n);     vector<int> mx0(2 * n), mx1(2 * n, -1);     for (int i = 0; i < 2 * n; i++) mx0[i] = i;     vector<bool> ju(2 * n);     for (int i = 0; i < n; i++) {       int u = b[2 * i], v = b[2 * i + 1];       if (uf.connected(u, v)) {         if (ju[uf.find(u)]) {           cout << -1 <<   n ;           return 0;         }         ju[uf.find(u)] = true;       } else {         int ru = uf.find(u), rv = uf.find(v);         uf.unite(u, v);         mx1[uf.find(u)] = max(max(mx1[ru], mx1[rv]), min(mx0[ru], mx0[rv]));         mx0[uf.find(u)] = max(mx0[ru], mx0[rv]);       }     }     int res = 0;     for (int i = 0; i < 2 * n; i++) {       if (ju[uf.find(i)]) {         res = max(res, mx0[uf.find(i)]);       } else {         res = max(res, mx1[uf.find(i)]);       }     }     for (int i = 0; i < 2 * n; i++) {       if (res == b[i]) {         cout << a[i] <<   n ;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double x, y, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x >> y;       ans = (ans * (i - 1) + y) / i;     }     ans += 5;     printf( %.3lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n;     cin >> n;     char str[n + 2];     cin >> str;     if (n == 1) {       cout << 0 << endl;       return 0;     }     int current = 0;     int previous = 0;     if (str[0] ==  U )       current++;     else       current--;     int count = 0;     int sign = (current > 0 ? 1 : -1);     for (int i = 1; i < n; i++) {       previous = current;       if (str[i] ==  U )         current++;       else         current--;       if (previous == 0 && sign != current) {         count++;         sign = current;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000;   const int maxn = 1e5 + 100;   long long dp[maxn][2], c[maxn];   string reverse(string s) {     string t =   ;     for (int i = s.size() - 1; i >= 0; i--) t += s[i];     return t;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) cin >> c[i];     string last;     cin >> last;     dp[0][0] = 0;     dp[0][1] = c[0];     for (int i = 1; i < n; i++) {       string now;       cin >> now;       dp[i][0] = dp[i][1] = INF;       if (last <= now) dp[i][0] = min(dp[i][0], dp[i - 1][0]);       if (reverse(last) <= now) dp[i][0] = min(dp[i][0], dp[i - 1][1]);       if (last <= reverse(now)) dp[i][1] = min(dp[i][1], dp[i - 1][0] + c[i]);       if (reverse(last) <= reverse(now))         dp[i][1] = min(dp[i][1], dp[i - 1][1] + c[i]);       last = now;     }     long long ans = min(dp[n - 1][0], dp[n - 1][1]);     if (ans >= INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   vector<int> w[400001];   int check[400001];   int ans;   void input() {     scanf( %d %d %d , &n, &m, &q);     int x, y;     for (int i = (0); i < (q); i++) {       scanf( %d %d , &y, &x);       x--;       y--;       x += n;       w[x].push_back(y);       w[y].push_back(x);     }     n = n + m;   }   void dfs(int node) {     check[node] = 1;     for (int i = (0); i < (w[node].size()); i++) {       int next = w[node][i];       if (check[next] == 0) {         dfs(next);       }     }   }   void process() {     for (int i = (0); i < (n); i++) {       if (check[i] == 0) {         dfs(i);         ans++;       }     }   }   void output() { printf( %d , ans - 1); }   int main() {     input();     process();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, a, b, c, num = 0;     scanf( %d%d , &x, &y);     a = b = c = y;     while (a < x || b < x || c < x) {       if (a <= b && a <= c)         a = b + c - 1;       else if (b <= a && b <= c)         b = a + c - 1;       else         c = a + b - 1;       num++;     }     printf( %d , num);   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long f[107][10007], C[107][10007];   long long ksm(long long a, long long b) {     long long res = 1;     for (; b; b >>= 1) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.precision(6);     cout << fixed;     long long n, m, K;     cin >> n >> m >> K;     for (int i = 0; i <= n; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = C[i - 1][j - 1] + C[i - 1][j];         C[i][j] %= MOD;       }     }     f[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= min(n, K); j++) {         long long res = ksm(C[n][j], (m - i) / n + 1);         for (int k = 0; k <= K - j; k++) {           f[i][j + k] += f[i - 1][k] * res;           f[i][j + k] %= MOD;         }       }     }     cout << f[n][K] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string str;   set<string> vis;   int main() {     int n;     scanf( %d , &n);     vis.clear();     for (int i = 0; i < n; ++i) {       cin >> str;       if (vis.find(str) != vis.end())         cout <<  YES  << endl;       else         cout <<  NO  << endl;       vis.insert(str);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s[n];       unordered_map<string, int> mp;       int count = 0;       for (int i = 0; i < n; i++) {         cin >> s[i];         mp[s[i]] += 1;       }       for (int i = 0; i < n; i++) {         if (mp[s[i]] > 1) {           count += 1;           mp[s[i]] -= 1;           for (int j = 0; j < 10; j++) {             string s1 = s[i];             s1[3] =  0  + j;             if (mp[s1] == 0) {               mp[s1] += 1;               s[i] = s1;               break;             }           }         }       }       cout << count << endl;       for (int i = 0; i < n; i++) {         cout << s[i] << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void prn(T first) {     cout << first <<   n ;   }   template <typename T, typename... Args>   void prn(T first, Args... args) {     cout << first <<    ;     prn(args...);   }   vector<long long> adj[200004];   vector<long long> parent(200004, 0), dist(200004, 0);   void dfs(long long u, long long p = 0, long long d = 0) {     parent[u] = p;     dist[u] = d;     for (long long v : adj[u]) {       if (v == p) continue;       dfs(v, u, dist[u] + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long i, j, t, n, u, v;     cin >> n;     for (i = 0; i < n - 1; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     set<pair<long long, long long> > st;     for (i = 1; i < n + 1; i++) {       if (dist[i] > 2) {         st.insert({-dist[i], i});       }     }     long long res = 0;     while (!st.empty()) {       u = st.begin()->second;       u = parent[u];       res++;       auto it = st.find({-dist[u], u});       if (it != st.end()) {         st.erase(it);       }       for (long long child : adj[u]) {         it = st.find({-dist[child], child});         if (it != st.end()) {           st.erase(it);         }       }     }     cout << res;     return 0;   }