malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double pi = acos((double)(-1));   const int maxn = 100010;   const int mod = 1e9 + 7;   int moven2[10][5] = {{1, 0, 0},  {-1, 0, 0}, {0, 1, 0},                        {0, -1, 0}, {0, 0, 1},  {0, 0, -1}};   int moven1[10][5] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   int n, m, q, f[2 * maxn];   map<string, int> mp;   string a, b;   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   void Union(int x, int y) {     int fx = find(x);     int fy = find(y);     f[fx] = fy;   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       cin >> a;       mp[a] = i;     }     for (int i = 1; i <= 2 * n; i++) f[i] = i;     for (int i = 1, t; i <= m; i++) {       cin >> t >> a >> b;       int x = mp[a];       int y = mp[b];       if (t == 1) {         if (find(x) == find(y + n) || find(y) == find(x + n))           cout <<  NO                 <<   n ;         else {           cout <<  YES                 <<   n ;           Union(x, y);           Union(x + n, y + n);         }       } else {         if (find(x) == find(y) || find(x + n) == find(y + n))           cout <<  NO                 <<   n ;         else {           cout <<  YES                 <<   n ;           Union(x + n, y);           Union(x, y + n);         }       }     }     for (int i = 1; i <= q; i++) {       cin >> a >> b;       int x = mp[a];       int y = mp[b];       if (find(x) == find(y) || find(x + n) == find(y + n))         cout << 1 <<   n ;       else if (find(x + n) == find(y) || find(x) == find(y + n))         cout << 2 <<   n ;       else         cout << 3 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int res = 0, cur = 0, tmp;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> tmp;       res = (cur + tmp) / m;       cur = (cur + tmp) % m;       cout << res <<    ;     }   }
#include <bits/stdc++.h>   int main() {     int n, count = 0, i = 0, ans, flag = 1;     char s[201];     scanf( %d %s , &n, s);     while (s[i] !=   0 ) {       if (s[i] ==  x ) count++;       i++;     }     if (n / 2 > count) {       ans = n / 2 - count;       flag = 0;     } else       ans = count - n / 2;     printf( %d n , ans);     i = 0;     while (n-- && ans) {       if (s[i] ==  x  && flag) {         s[i] =  X ;         ans--;       } else if (s[i] ==  X  && !flag) {         s[i] =  x ;         ans--;       }       i++;     }     printf( %s n , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const int maxn = 5e1 + 10;   const int maxq = 1e3 + 10;   const int alf = 26;   const long long dlm = 1e9 + 7;   const int del = 998244353;   const int eps = 1e-7;   char t[maxn][maxn];   char g[maxn][maxn];   char t2[maxn][maxn];   int n;   void rot() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         t2[j][n + 1 - i] = t[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         t[i][j] = t2[i][j];       }     }   }   int flh() {     for (int i1 = 1, i2 = n; i1 < i2; i1++, i2--) {       for (int j = 1; j <= n; j++) {         swap(t[i1][j], t[i2][j]);       }     }   }   int flv() {     for (int i = 1; i <= n; i++) {       for (int j1 = 1, j2 = n; j1 < j2; j1++, j2--) {         swap(t[i][j1], t[i][j2]);       }     }   }   int same() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (t[i][j] != g[i][j]) return 0;       }     }     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       string st;       cin >> st;       for (int j = 1; j <= n; j++) {         t[i][j] = st[j - 1];       }     }     for (int i = 1; i <= n; i++) {       string st;       cin >> st;       for (int j = 1; j <= n; j++) {         g[i][j] = st[j - 1];       }     }     for (int vaf = 0; vaf < 2; vaf++) {       for (int haf = 0; haf < 2; haf++) {         for (int r = 0; r < 4; r++) {           if (same() == 1) {             return cout <<  Yes , 0;           }           rot();         }         flh();       }       flv();     }     cout <<  No ;   }
#include <bits/stdc++.h>   using namespace std;   int ntest = 0, test = 0;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main() {     init();     while (++test <= ntest) {       run();     }     return 0;   }   const int INF = (int)1E9 + 5;   const double EPS = 1E-11;   const long long MOD = (long long)1E9 + 7;   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   inline void init() { ntest = 1; }   int cnt[(int)(1e6 + 5)];   inline void run() {     int n, m, a, b;     cin >> n >> m;     for (int i = 0; i < (m); i++) {       scanf( %d%d , &a, &b);       cnt[a]++;       cnt[b]++;     }     long long x = 0;     for (int i = (1); i <= (n); i++) x += (n - 1 - cnt[i]) * cnt[i];     x /= 2;     cout << (n - 1ll) * n * (n - 2ll) / 6 - x;   }
#include <bits/stdc++.h>   using namespace std;   struct ring {     int c1;     int c2;     int r1;     int r2;   };   int contour(struct ring a, struct ring b, double dist) {     int cnt = 0;     if (dist >= a.r2 + b.r2 || dist <= b.r1 - a.r2 || dist <= a.r2 - b.r2) cnt++;     if (dist >= a.r1 + b.r2 || dist <= b.r1 - a.r1 || dist <= a.r1 - b.r2) cnt++;     return cnt;   }   int main() {     struct ring a, b;     cin >> a.c1 >> a.c2 >> a.r1 >> a.r2;     cin >> b.c1 >> b.c2 >> b.r1 >> b.r2;     double dist =         sqrt((a.c1 - b.c1) * (a.c1 - b.c1) + (a.c2 - b.c2) * (a.c2 - b.c2));     int ans = contour(a, b, dist) + contour(b, a, dist);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(int a) {     write(a);     puts(  );   }   int n, ans;   struct data {     int bo;     string first;   };   map<string, data> M;   const int N = 1005;   string a[N], b[N], t;   map<string, bool> MM;   int main() {     n = read();     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (M[a[i]].bo)         t = M[a[i]].first;       else         t = a[i];       M[a[i]] = (data){0, a[i]};       M[b[i]] = (data){1, t};     }     for (int i = 1; i <= n; i++) {       if (MM[b[i]])         continue;       else         MM[b[i]] = 1;       if (M[b[i]].bo) ans++;     }     MM.clear();     writeln(ans);     for (int i = 1; i <= n; i++)       if (M[b[i]].bo && MM[b[i]] == 0) {         MM[b[i]] = 1;         cout << M[b[i]].first <<     << b[i] << endl;       }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int n, m;   double dp_mai[155], dp_cul[155];   int d_mai[155], d_cul[155];   bool adj[155][155], used[155];   void dijk(int source, int *d, double *dp) {     fill(d + 1, d + n + 1, INF);     memset(used, 0, sizeof(used));     d[source] = 0;     dp[source] = 1.;     for (int(i) = 0; (i) < (n); i++) {       int id, low = INF;       for (int(j) = (1); (j) <= (n); j++) {         if (used[j]) continue;         if (low > d[j]) {           low = d[j];           id = j;         }       }       used[id] = true;       for (int(j) = (1); (j) <= (n); j++) {         if (used[j] || !adj[id][j]) continue;         if (d[j] > d[id] + 1) {           d[j] = d[id] + 1;           dp[j] = dp[id];         } else if (d[j] == d[id] + 1) {           dp[j] += dp[id];         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int x, y;     for (int(i) = 0; (i) < (m); i++) {       cin >> x >> y;       adj[x][y] = adj[y][x] = true;     }     dijk(n, d_mai, dp_mai);     dijk(1, d_cul, dp_cul);     double res = 0.;     for (int(i) = (1); (i) <= (n); i++) {       double temp = 0.;       for (int(j) = (1); (j) <= (n); j++) {         if (!adj[i][j]) continue;         if (d_mai[i] + d_cul[j] + 1 == d_mai[1]) temp += dp_mai[i] * dp_cul[j];         if (d_cul[i] + d_mai[j] + 1 == d_cul[n]) temp += dp_cul[i] * dp_mai[j];       }       res = max(res, temp);     }     cout << fixed << setprecision(10) << res / dp_mai[1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   using pll = pair<ll, ll>;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (const T &t : v) os <<   t  << t;     return os << endl;   }   template <class T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &a : v) is >> a;     return is;   }   template <class T, class U>   ostream &operator<<(ostream &os, const pair<T, U> &v) {     return os <<  <  << v.first <<     << v.second <<  > ;   }   bool solve() {     int q;     cin >> q;     map<pll, ll> cost;     for (int i = 0; i < (int)(q); i++) {       int t;       cin >> t;       if (t == 1) {         ll v, u, w;         cin >> v >> u >> w;         set<ll> visited;         {           ll vv = v;           while (vv) {             visited.insert(vv);             vv /= 2;           }         }         ll lca = -1;         {           ll uu = u;           while (!visited.count(uu)) uu /= 2;           lca = uu;         }         assert(lca > 0);         while (v > lca) {           cost[make_pair(v / 2, v)] += w;           v /= 2;         }         while (u > lca) {           cost[make_pair(u / 2, u)] += w;           u /= 2;         }       } else if (t == 2) {         ll v, u;         cin >> v >> u;         ll sum = 0;         set<ll> visited;         {           ll vv = v;           while (vv) {             visited.insert(vv);             vv /= 2;           }         }         ll lca = -1;         {           ll uu = u;           while (!visited.count(uu)) uu /= 2;           lca = uu;         }         assert(lca > 0);         while (v > lca) {           sum += cost[make_pair(v / 2, v)];           v /= 2;         }         while (u > lca) {           sum += cost[make_pair(u / 2, u)];           u /= 2;         }         cout << sum << endl;       } else         assert(0);     }     return false;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     while (solve())       ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {     return p1.first < p2.first;   }   struct node {     int a;     int b;   };   bool operator<(const node& x, const node& y) { return x.a > y.a; }   int sol(int x) {     int ans = 0;     if (x == 0) return 10;     if (x == 100) return 0;     if (x % 10 == 0) return 10;     while (x > ans) ans += 10;     return ans - x;   }   int main() {     int n, k;     scanf( %d , &n);     scanf( %d , &k);     priority_queue<node> q;     for (int i = 0; i < n; i++) {       int x;       node xx;       scanf( %d , &x);       int z;       z = sol(x);       xx.a = z;       xx.b = x;       q.push(xx);     }     int ans = 0;     while (k > 0 && !q.empty()) {       int xx = q.top().a;       int yy = q.top().b;       if (xx > k) break;       if (xx == 0) {         ans += (yy / 10);         q.pop();         continue;       }       node my;       my.b = yy + xx;       my.a = sol(my.b);       q.pop();       q.push(my);       k -= xx;     }     while (!q.empty()) {       ans += (q.top().b) / 10;       q.pop();     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[100009], a[100009], pos[100009], m, n, ri[100009], le[100009];   set<pair<int, int>> st;   inline bool cmp(const int& A, const int& B) { return p[A] < p[B]; }   int getdis(int x, int y) {     if (x == y) return 1000000000;     int d = (p[y] - p[x] + m) % m;     if (y < x) d = (d + a[y]) % m;     if (d <= a[x]) return 1;     if (a[x] <= a[y]) return 1000000000;     return (d - a[y] - 1) / (a[x] - a[y]) + 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d%d , p + i, a + i), pos[i] = i, p[i]--;     sort(pos + 1, pos + n + 1, cmp);     for (int i = 1; i <= n; i++) ri[pos[i]] = pos[i + 1], le[pos[i]] = pos[i - 1];     ri[pos[n]] = pos[1], le[pos[1]] = pos[n];     for (int i = 1; i <= n; i++) st.insert(make_pair(getdis(i, ri[i]), i));     while (1) {       if (st.begin()->first == 1000000000) break;       int u = st.begin()->second;       st.erase(st.begin());       st.erase(make_pair(getdis(ri[u], ri[ri[u]]), ri[u]));       if (!st.empty()) st.erase(make_pair(getdis(le[u], u), le[u]));       p[u] += getdis(u, ri[u]), p[u] %= m, a[u]--;       ri[u] = ri[ri[u]], le[ri[u]] = u;       st.insert(make_pair(getdis(le[u], u), le[u])),           st.insert(make_pair(getdis(u, ri[u]), u));     }     printf( %lu n , st.size());     for (set<pair<int, int>>::iterator it = st.begin(); it != st.end(); it++)       printf( %d  , it->second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double A[200009];   double B[200009];   int main() {     int N, i;     cin >> N;     for (i = 0; i < N; i++) {       cin >> A[i];     }     B[0] = A[0];     for (i = 1; i < N; i++) {       B[i] = (B[i - 1] + 1) * A[i];     }     double sum = 0;     for (i = 0; i < N; i++) {       sum += 2 * B[i];       sum -= A[i];     }     printf( %0.15lf n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[4000000];   int f[4000000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int s, t;     cin >> s >> t;     s--;     t--;     long long ans = 0;     for (int i = s; i < t; i++) ans += a[i];     long long num = ans;     int pos = 1;     for (int i = 2; i <= n; i++) {       ans = ans - a[(t + 1 - i + n) % n] + a[(s + 1 - i + n) % n];       if (ans > num) {         ans = num;         pos = i;       }     }     cout << pos;     return 0;   }
#include <bits/stdc++.h>   inline long long MAX2(long long a, long long int b) {     return (a) > (b) ? (a) : (b);   }   inline long long MAX3(long long a, long long b, long long c) {     return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));   }   inline long long MIN2(long long a, long long b) {     return (a) < (b) ? (a) : (b);   }   inline long long MIN3(long long a, long long b, long long c) {     return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));   }   using namespace std;   int n, a, b;   int p[1000006];   pair<int, int> compute() {     if (n % b == 0) return pair<int, int>(0, n / b);     if (n % a == 0) return pair<int, int>(n / a, 0);     int div = (n / b);     int rem = (n % b);     int ch;     while (div > 0) {       ch = rem % a;       if (ch == 0) break;       div--;       rem += b;     }     if (div == 0) return pair<int, int>(-1, -1);     return pair<int, int>((rem / a), div);   }   void make(int i, int j) {     int k;     for (k = i; k < j; k++) {       p[k] = k + 1;     }     p[j] = i;   }   int main() {     cin >> n >> a >> b;     if (a > b) {       int temp = a;       a = b;       b = temp;     }     pair<int, int> cycles = compute();     if (cycles.first == -1) {       cout << -1;       return 0;     }     int i = 1;     while (i <= n) {       if (cycles.first > 0) {         make(i, i + a - 1);         cycles.first--;         i += a;       } else {         make(i, i + b - 1);         cycles.second--;         i += b;       }     }     for (i = 1; i < n + 1; i++) {       cout << p[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 5;   int a[N], b[N];   long long check(long long x, int n, int c) {     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += x * a[i] / b[i] + 1;       if (ans > c) ans = c + 1;     }     return ans;   }   int main() {     int n, c;     scanf( %d%d , &n, &c);     long long sum = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a[i], &b[i]);       sum += a[i];     }     long long limit = 1000000000000000000LL;     long long l, r;     if (check(1, n, c) >= c)       l = 1;     else {       long long head = 1, tail = limit / sum;       while (head < tail - 1) {         long long mid = head + tail >> 1;         if (check(mid, n, c) >= c)           tail = mid;         else           head = mid;       }       l = tail;     }     if (check(limit / sum, n, c) <= c)       r = limit / sum;     else {       long long head = 1, tail = limit / sum;       while (head < tail - 1) {         long long mid = head + tail >> 1;         if (check(mid, n, c) <= c)           head = mid;         else           tail = mid;       }       r = head;     }     long long ans = 0;     if (l <= r && check(l, n, c) == c && check(r, n, c) == c) ans = r - l + 1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int m;   int n;   map<int, int> id;   int rev[100500];   int a[2];   int w[100500], ans[100500];   set<int> s;   set<int> ss;   void go(int x) {     w[x] = 1;     x = rev[x];     s.insert(x);     for (int i = 0; i < (2); i++) {       int tmp = a[i] - x;       if (ss.find(tmp) != s.end()) {         int p = id[tmp];         if (!w[p]) go(p);       }     }   }   int check(set<int> s) {     for (int i = 0; i < (2); i++) {       int g = 1;       for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {         int tmp = a[i] - *it;         if (s.find(tmp) == s.end()) {           g = 0;           break;         }       }       if (g) {         for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {           ans[id[*it]] = i;         }         return 1;       }     }     return 0;   }   int main() {     cin >> n >> a[0] >> a[1];     for (int i = 0; i < (n); i++) {       int x;       cin >> x;       id[x] = i;       rev[i] = x;       ss.insert(x);     }     for (int i = 0; i < (n); i++)       if (!w[i]) {         s.clear();         go(i);         if (!check(s)) {           cout <<  NO  << endl;           return 0;         }       }     cout <<  YES  << endl;     for (int i = 0; i < (n); i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc-- > 0) {       int arr[7];       for (int i = 0; i < 7; i++) {         cin >> arr[i];       }       cout << arr[0] <<     << arr[1] <<     << arr[6] - arr[0] - arr[1] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int power(long long int x, long long int n) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result * x) % 1000000007;       x = (x * x) % 1000000007;       n = n / 2;     }     return result % 1000000007;   }   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int inv(long long int a, long long int m) { return power(a, m - 2); }   long long int lcm(long long int a, long long int b) {     return a * b / (gcd(a, b));   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int index = -1, res = -1;       string str;       cin >> str;       long long int n = str.length(), ans = -1;       for (long long int i = 0; i < n; i++) {         if (str[i] ==  R ) {           index = max(index, i - res);           res = i;         }       }       index = max(index, n - res);       cout << index <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, arr[100000], arr1[100000];     cin >> n;     string s =   ;     for (int x = 0; x < n; x++) cin >> arr[x], arr1[x] = arr[x];     sort(arr1, arr1 + n);     for (int x = 0; x <= arr1[n - 1]; x++) {       for (int y = 0; y < n - 1; y++) {         if (arr[y] != 0) s +=  P , arr[y]--;         s +=  R ;       }       for (int z = n - 1; z > 0; z--) {         if (arr[z] != 0) s +=  P , arr[z]--;         s +=  L ;       }     }     for (int x = s.size(); x >= 0; x--)       if (s[x] ==  P ) {         s.erase(x + 1, s.size());         break;       }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int maxn = 1e5 + 10;   const int mod = 1e9 + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll pwr(ll a, ll pw) {     ll ret = 1;     while (pw > 0) {       if (pw & 1) {         ret = ret * a % mod;       }       a = a * a % mod;       pw >>= 1;     }     return ret;   }   ll modinv(ll a) { return pwr(a, mod - 2); }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     vector<ll> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     vector<vector<ll> > prob_win(n, vector<ll>(n));     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         prob_win[i][j] = v[i] * modinv(v[i] + v[j]) % mod;         prob_win[j][i] = v[j] * modinv(v[i] + v[j]) % mod;       }     }     vector<vector<ll> > win_msk(n, vector<ll>(1 << n, 1ll));     for (int i = 0; i < n; i++) {       for (int msk = 0; msk < 1 << n; msk++) {         for (int bit = 0; bit < n; bit++) {           if (msk >> bit & 1) {             win_msk[i][msk] = win_msk[i][msk] * prob_win[i][bit] % mod;           }         }       }     }     ll ans = 0;     vector<ll> dp_prob(1 << n, 1ll);     for (int msk = 1; msk < 1 << n; msk++) {       ll num_winners = __builtin_popcount(msk);       for (int bit = 0; bit < n; bit++) {         if (msk >> bit & 1) {           dp_prob[msk] = dp_prob[msk] * win_msk[bit][(1 << n) - 1 - msk] % mod;         }       }       for (int sub_winners = (msk - 1) & msk; sub_winners > 0;            sub_winners = (sub_winners - 1) & msk) {         int sub_losers = msk ^ sub_winners;         ll p = dp_prob[sub_winners];         for (int bit = 0; bit < n; bit++) {           if (sub_losers >> bit & 1) {             p = p * win_msk[bit][(1 << n) - 1 - msk] % mod;           }         }         dp_prob[msk] = (dp_prob[msk] - p + mod) % mod;       }       ans = (ans + dp_prob[msk] * num_winners % mod) % mod;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 2e5 + 5;   vector<int> E[N];   LL Size[N], Dep[N];   int ord[N];   int tourism[N];   void dfs(int x, int p, int lvl) {     Size[x] = 1;     Dep[x] = lvl;     for (const int &to : E[x]) {       if (to == p) continue;       dfs(to, x, lvl + 1);       Size[x] += Size[to];     }   }   LL res;   void go(int x, int p, int val) {     if (tourism[x])       val++;     else       res += val;     for (const int &to : E[x]) {       if (to == p) continue;       go(to, x, val);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       E[x].push_back(y);       E[y].push_back(x);     }     dfs(0, 0, 0);     iota(ord, ord + n, 0);     sort(ord, ord + n,          [](int x, int y) { return Dep[x] - Size[x] < Dep[y] - Size[y]; });     k = n - k;     for (int i = 0; i < k; i++) {       tourism[ord[i]] = 1;     }     go(0, 0, 0);     cout << res << endl;   }