malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], b[maxn];   int n, k;   bool check(int x, int state) {     if (state == 1) {       int c = 0, right = 0;       for (int i = 1; i <= n; i++) {         if (a[i] <= x) {           right = i;           c++;           i++;         }       }       if (c == k - k / 2 && right == n && k % 2 == 0) return false;       return c >= k - k / 2;     } else {       int c = 0, right = 0;       for (int i = 2; i <= n; i++) {         if (a[i] <= x) {           right = i;           c++;           i++;         }       }       if (c == k / 2 && right == n && k % 2 != 0) return false;       return c >= k / 2;     }   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     int l = 1, r = n;     while (l < r) {       int mid = r + l >> 1;       if (check(b[mid], 0) || check(b[mid], 1))         r = mid;       else         l = mid + 1;     }     cout << b[l];     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class T>   inline void amin(T &x, const T &y) {     if (y < x) x = y;   }   template <class T>   inline void amax(T &x, const T &y) {     if (x < y) x = y;   }   template <class Iter>   void rprintf(const char *fmt, Iter begin, Iter end) {     for (bool sp = 0; begin != end; ++begin) {       if (sp)         putchar(   );       else         sp = true;       printf(fmt, *begin);     }     putchar(  n );   }   int N;   int dp[2011];   int prv[2011];   bool tar[1011];   bool cur[1011];   int calc(int a) {     memset(dp, 0xc0, sizeof dp);     dp[0] = 0;     for (int i = 0, i_len = (N); i < i_len; ++i) {       for (int j = 1; j < a; j++) {         if (dp[i + j + 1] < dp[i] + j) {           dp[i + j + 1] = dp[i] + j;           prv[i + j + 1] = i;         }       }     }     return dp[N] - a + 1;   }   void query(vector<int> v) {     printf( %d , (int)v.size());     for (int i = 0, i_len = (v.size()); i < i_len; ++i) printf(  %d , v[i] + 1);     printf(  n );     fflush(stdout);     for (__typeof((v).begin()) e = (v).begin(), e_end = (v).end(); e != e_end;          ++e)       cur[*e] = true;     int x;     scanf( %d , &x);     x--;     for (int i = 0, i_len = (v.size()); i < i_len; ++i) cur[(x + i) % N] = false;   }   void solve() {     int ma = 0, a = 0;     for (int b = 1; b < N; b++) {       int tmp = calc(b);       if (ma < tmp) {         ma = tmp;         a = b;       }     }     if (ma == 0) {       puts( 0 );       fflush(stdout);     } else {       calc(a);       int x = N;       memset(tar, 0, sizeof tar);       memset(cur, 0, sizeof cur);       while (x) {         for (int k = prv[x]; k < x - 1; k++) tar[k] = true;         x = prv[x];       }       while (1) {         vector<int> v;         for (int i = 0, i_len = (N); i < i_len; ++i)           if (tar[i] && !cur[i]) {             v.push_back(i);           }         if ((int)v.size() <= a) {           for (int i = 0, i_len = (N); i < i_len; ++i)             if (tar[i] && cur[i]) {               if ((int)v.size() == a) break;               v.push_back(i);             }           query(v);           break;         } else {           v.resize(a);           query(v);         }       }       puts( 0 );       fflush(stdout);     }   }   void MAIN() {     scanf( %d , &N);     solve();   }   int main() {     int TC = 1;     for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 5;   long long dp[105], cnt[105], b[N], a[N];   void add(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   struct Mat {     long long t[101][101];     Mat() { memset(t, 0, sizeof t); }   } I;   int m;   Mat operator*(Mat a, Mat b) {     Mat c;     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) {         long long t = 0;         for (int k = 0; k < m; k++) {           add(c.t[i][j], a.t[i][k] * b.t[k][j] % mod);         }       }     return c;   }   Mat Pow(Mat a, int b) {     Mat c = I;     while (b) {       if (b & 1) c = c * a;       a = a * a;       b >>= 1;     }     return c;   }   int main() {     int n, l, x;     cin >> n >> l >> m;     for (int i = 0; i < m; i++) dp[i] = 0, cnt[i] = 0;     for (int i = 1; i <= n; i++) scanf( %d , &x), dp[x % m]++;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), cnt[a[i] % m]++;     for (int i = 1; i <= n; i++) scanf( %lld , &b[i]);     for (int i = 0; i < m; i++) I.t[0][i] = dp[i];     Mat pi;     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) pi.t[i][j] = cnt[(m - i + j) % m];     Mat ans = Pow(pi, l - 2);     for (int i = 0; i < m; i++) cnt[i] = 0, dp[i] = 0;     for (int i = 1; i <= n; i++) {       cnt[(a[i] + b[i]) % m]++;     }     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++)         add(dp[(j + i) % m], ans.t[0][j] * cnt[i] % mod);     printf( %lld n , dp[0]);   }
#include <bits/stdc++.h>   using namespace std;   long long int variables[3001][3001];   long long int cost[3001][3001];   int n;   long long int a[3001];   void inicjuj() {     for (int i = 0; i < n; ++i) {       variables[0][i] = a[i] - i;     }     sort(variables[0], variables[0] + n);     for (int i = 0; i < n; ++i) cost[0][i] = abs(variables[0][i] - a[0]);   }   void __built_column(int X) {     long long int minpref = 1e18;     for (int j = 0; j < n; ++j) {       minpref = min(minpref, cost[X - 1][j]);       variables[X][j] = variables[X - 1][j] + 1;       cost[X][j] = minpref + (long long int)abs(a[X] - variables[X][j]);     }   }   long long int oblicz() {     for (int i = 1; i < n; ++i) {       __built_column(i);     }     long long int wyn = 1e18;     for (int j = 0; j < n; ++j) {       wyn = min(wyn, cost[n - 1][j]);     }     return wyn;   }   void wczytaj() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) cin >> a[i];   }   int main() {     wczytaj();     inicjuj();     cout << oblicz() << endl;   }
#include <bits/stdc++.h>   using namespace std;   namespace IO {   template <typename T>   inline void read(T &x) {     x = 0;     long long f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x = x * f;   }   }  // namespace IO   using namespace IO;   const long long maxn = 200000;   long long dp[maxn + 10][4];   long long a[maxn + 10];   void DP(long long &x, long long y) { x = max(x, y); }   signed main() {     long long _;     read(_);     while (_--) {       long long n;       read(n);       for (long long i = 0; i <= n; i++) {         dp[i][0] = dp[i][1] = dp[i][2] = 0;         a[i] = 0;       }       for (long long i = 0; i < n; i++) {         read(a[i]);       }       for (long long i = 0; i < n; i++) {         if (i % 2 == 1) {           DP(dp[i + 1][0], dp[i][0]);           if (i + 2 <= n) DP(dp[i + 2][1], max(dp[i][1] + a[i], dp[i][0] + a[i]));           DP(dp[i + 1][2], max(dp[i][1], max(dp[i][0], dp[i][2])));         } else {           DP(dp[i + 1][0], dp[i][0] + a[i]);           if (i + 2 <= n) DP(dp[i + 2][1], max(dp[i][1], dp[i][0]) + a[i + 1]);           DP(dp[i + 1][2], max(dp[i][1], max(dp[i][0], dp[i][2])) + a[i]);         }       }       cout << max(dp[n][1], max(dp[n][2], dp[n][0])) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   char a[11];   bool ok = true;   bool check(char a[]) {     for (int i = 0; i < 7; i++)       if (a[i] == a[i + 1]) return false;     return true;   }   int main() {     for (int i = 1; i <= 8; i++) {       scanf( %s , a);       ok &= check(a);     }     if (ok)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long arr[41] = {         1,          2,          4,          8,          16,          32,         64,         128,        256,        512,        1024,        2048,         4096,       8092,       16184,      32368,      64736,       129472,         258944,     517888,     1035776,    2071552,    4143104,     8286208,         16572416,   33144832,   66289664,   132579328,  265158656,   530317312,         1060634624, 2121269248, 4242538496, 8485076992, 16970153984, 33940307968};     int a;     cin >> a;     cout << arr[a];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100050;   const int M = 10050;   long long mn[M], h;   int ord[M], tmp[M], que[M], k, n, m;   bool was[M];   long long a[N];   int c[N];   stack<int> stk[M];   struct cmp {     bool operator()(int i, int j) {       return c[i] > c[j] || (c[i] == c[j] && i < j);     }   };   set<int, cmp> pts;   bool in[N];   void Cns(int ost) {     while (stk[ost].size() && a[stk[ost].top()] >= mn[ost]) {       int i = stk[ost].top();       stk[ost].pop();       pts.insert(i);       in[i] = 1;     }   }   void Upd(long long x) {     int i = 1, j = 1, xb = 0, xz = 0;     for (int i = 0; i < k; i++) was[i] = 0;     for (; i <= k || j <= xb;) {       int u;       if (i > k || (j <= xb && mn[que[j]] < mn[ord[i]]))         u = que[j++];       else         u = ord[i++];       if (was[u]) continue;       was[u] = 1;       tmp[++xz] = u;       int v = (u + x) % k;       if (mn[v] > mn[u] + x) {         mn[v] = mn[u] + x;         Cns(v);         que[++xb] = v;       }     }     assert(xz == k);     for (int i = 1; i <= k; i++) ord[i] = tmp[i];   }   int main() {     scanf( %lld %i %i %i , &h, &n, &m, &k);     for (int i = 1; i < k; i++) mn[i] = h;     for (int i = 1; i <= k; i++) ord[i] = i - 1;     vector<int> ord;     for (int i = 1; i <= n; i++)       scanf( %lld %i , &a[i], &c[i]), a[i]--, ord.push_back(i);     sort(ord.begin(), ord.end(), [&](int i, int j) { return a[i] < a[j]; });     for (int i : ord) stk[a[i] % k].push(i);     Cns(0);     while (m--) {       int t;       scanf( %i , &t);       if (t == 1) {         long long x;         scanf( %lld , &x);         Upd(x);       } else if (t == 2) {         int x, y;         scanf( %i %i , &x, &y);         if (in[x]) pts.erase(x);         c[x] -= y;         if (in[x]) pts.insert(x);       } else {         if (pts.empty())           printf( 0 n );         else {           int i = *pts.begin();           printf( %i n , c[i]);           pts.erase(i);           c[i] = 0;           in[i] = 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long n, k;   long long a[N];   priority_queue<tuple<long long, long long, long long> > pq;   inline long long sq(long long x) { return x * x; }   long long cost(long long len, long long pieces) {     long long each = len / pieces;     long long extra = len % pieces;     long long res = extra * sq(each + 1) + sq(each) * (pieces - extra);     return res;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       ans += sq(a[i]);       long long val = cost(a[i], 1) - cost(a[i], 2);       long long len = a[i];       long long pieces = 2;       pq.push(make_tuple(val, len, pieces));     }     for (long long i = 1; i <= k - n; i++) {       long long val, len, pieces;       tie(val, len, pieces) = pq.top();       pq.pop();       ans -= val;       long long new_val = cost(len, pieces) - cost(len, pieces + 1);       pieces++;       pq.push(make_tuple(new_val, len, pieces));     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, h, m, data[55];   int main() {     cin >> n >> h >> m;     for (int i = 1; i <= n; i++) {       data[i] = h;     }     for (int i = 1; i <= m; i++) {       long long l, r, x;       cin >> l >> r >> x;       for (int j = l; j <= r; j++) {         data[j] = min(data[j], x);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) ans += data[i] * data[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, m, l, r, T, mid;   bool check(long long x) {     long long p = x * m, s = 1, d = n, t;     for (long i = 0; i <= x && p >= 0 && d; i++) {       d -= (t = min(s, d));       p -= t * i;       s = s * (x - i) / (i + 1);     }     return p >= 0 && !d;   }   int main() {     for (scanf( %ld , &T); T; T--) {       scanf( %ld%ld , &n, &m);       m = min(m, n / 2);       l = 0;       r = n;       while (l < r) {         mid = (l + r) / 2;         if (check(mid))           r = mid;         else           l = mid + 1;       }       printf( %ld n , r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct Vec {     long long x, y;     Vec operator+(const Vec &o) const { return (Vec){x + o.x, y + o.y}; }     Vec operator-(const Vec &o) const { return (Vec){x - o.x, y - o.y}; }     long long operator*(const Vec &o) const {       return 1ll * x * o.y - 1ll * y * o.x;     }     long long operator|(const Vec &o) const {       return 1ll * x * o.x + 1ll * y * o.y;     }   } mon[1010], arr[11];   vector<int> ir[11][1010];   bool book[11];   int a[11];   int die[1010], clk;   int now;   bool chk(int p) {     if (die[p] == clk) return 1;     now++;     if (now > m) return 0;     int ap = a[now];     int ma = ir[ap][p].size();     if (!ma) {       die[p] = clk;       return 1;     }     for (int i = 0; i < ma; ++i)       if (!chk(ir[ap][p][i])) return 0;     die[p] = clk;     return 1;   }   bool check(int x) {     clk++;     now = 0;     return chk(x);   }   bool dfs(int x, int p) {     if (x > m) {       if (check(p)) return 1;       return 0;     }     for (int i = 1; i <= m; ++i)       if (!book[i]) {         a[x] = i;         book[i] = 1;         if (dfs(x + 1, p)) return 1;         book[i] = 0;       }     return 0;   }   int main() {     scanf( %d%d , &m, &n);     for (int i = 1; i <= m; ++i) scanf( %lld%lld , &arr[i].x, &arr[i].y);     for (int i = 1; i <= n; ++i) scanf( %lld%lld , &mon[i].x, &mon[i].y);     Vec vn, v1;     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= n; ++j) {         vn = mon[j] - arr[i];         for (int k = 1; k <= n; ++k) {           if (k == j) continue;           v1 = mon[k] - arr[i];           if (v1 * vn != 0 || (v1 | vn) <= 0) continue;           if (abs(v1.x) > abs(vn.x) || abs(v1.y) > abs(vn.y)) continue;           ir[i][j].push_back(k);         }       }     int ans = 0;     for (int i = 1; i <= n; ++i) {       memset(book, 0, sizeof(book));       if (dfs(1, i)) ans++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct frnd {     int w;     int h;     frnd(int w, int h) : w(w), h(h) {}   };   bool cmp(frnd a, frnd b) { return a.h < b.h; }   int main() {     int n;     cin >> n;     vector<frnd> friends;     int sum = 0;     int height = 0;     int prevH = 0;     for (int i = 0; i < n; i++) {       int w, h;       cin >> w >> h;       frnd a(w, h);       friends.push_back(a);       sum += w;       if (h > height) {         prevH = height;         height = h;       } else {         if (h > prevH) {           prevH = h;         }       }     }     for (int i = 0; i < n; i++) {       cout << (sum - friends[i].w) * ((height == friends[i].h) ? prevH : height)            <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct query {     int id, l, x, ans;   } qrs[100009];   bool idcomp(query a, query b) { return a.id < b.id; }   bool lcomp(query a, query b) { return a.l < b.l; }   int N, Q, a[100009], killer[20];   int modExp(int a, int b) {     if (b == 0) return 1;     int c = modExp(a, b >> 1);     c = (c * 1ll * c) % 1000000007;     if (b & 1) c = (c * 1ll * a) % 1000000007;     return c;   }   int main() {     scanf( %d %d , &N, &Q);     memset(&killer, -1, sizeof killer);     for (int i = 0; i < N; i++) {       scanf( %d , &a[i]);     }     for (int q = 0; q < Q; q++) {       scanf( %d %d , &qrs[q].l, &qrs[q].x);       qrs[q].id = q;       qrs[q].l--;     }     sort(qrs, qrs + Q, lcomp);     int q = 0, nz = 0;     for (int i = 0; i < N; i++) {       for (int j = 0; j < 20; j++) {         if (killer[j] != -1 && (a[i] & 1 << j)) {           a[i] ^= a[killer[j]];         }       }       for (int j = 0; j < 20; j++) {         if (killer[j] == -1 && (a[i] & 1 << j)) {           killer[j] = i;           for (int it = 0; it < i; it++) {             if ((a[it] & 1 << j)) a[it] ^= a[i];           }           break;         }       }       if (a[i] == 0) nz++;       while (q < Q && qrs[q].l < i) q++;       while (q < Q && qrs[q].l == i) {         int x = qrs[q].x;         for (int j = 0; j < 20; j++) {           if (killer[j] != -1 && (x & 1 << j)) {             x ^= a[killer[j]];           }         }         if (x == 0)           qrs[q].ans = modExp(2, nz);         else           qrs[q].ans = 0;         q++;       }     }     sort(qrs, qrs + Q, idcomp);     for (int q = 0; q < Q; q++) {       printf( %d n , qrs[q].ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = 1e9 + 7;   const int N = 1007;   int n;   vector<int> ans, l, r, p1, p2, p3, p4;   long long dis[N];   long long qry(int t, int i, int j, int k) {     printf( %d %d %d %d n , t, i, j, k);     fflush(stdout);     long long res;     scanf( %lld , &res);     return res;   }   void Init() {     ans.clear();     l.clear();     r.clear();   }   int Solve() {     for (int i = (3); i < (n + 1); ++i) {       long long res = qry(2, 1, 2, i);       if (res == 1)         l.push_back(i);       else         r.push_back(i);     }     ans.push_back(1);     if ((int)(r).size()) {       long long mx = -LINF, id;       for (auto o : r) {         long long res = qry(1, 1, 2, o);         dis[o] = res;         if (res > mx) {           mx = res;           id = o;         }       }       p4.clear();       p1.clear();       for (auto o : r)         if (o != id) {           long long res = qry(2, 1, id, o);           if (res == 1)             p1.push_back(o);           else             p4.push_back(o);         }       sort((p4).begin(), (p4).end(),            [](int a, int b) { return dis[a] < dis[b]; });       sort((p1).begin(), (p1).end(),            [](int a, int b) { return dis[a] > dis[b]; });       for (auto o : p4) ans.push_back(o);       ans.push_back(id);       for (auto o : p1) ans.push_back(o);     }     ans.push_back(2);     if ((int)(l).size()) {       long long mx = -LINF, id;       for (auto o : l) {         long long res = qry(1, 1, 2, o);         dis[o] = res;         if (res > mx) {           mx = res;           id = o;         }       }       p2.clear();       p3.clear();       for (auto o : l)         if (o != id) {           long long res = qry(2, 1, id, o);           if (res == 1)             p3.push_back(o);           else             p2.push_back(o);         }       sort((p2).begin(), (p2).end(),            [](int a, int b) { return dis[a] < dis[b]; });       sort((p3).begin(), (p3).end(),            [](int a, int b) { return dis[a] > dis[b]; });       for (auto o : p2) ans.push_back(o);       ans.push_back(id);       for (auto o : p3) ans.push_back(o);     }     printf( 0 );     for (auto o : ans) printf(  %d , o);     return puts(  );   }   int main() {     scanf( %d , &n);     Init();     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct r {     int p, t;   } a;   vector<r> v;   bool sss(const r& i, const r& j) {     if (i.p > j.p)       return true;     else if (i.p == j.p)       return i.t < j.t;     else       return false;   }   int main() {     int n, k;     cin >> n >> k;     map<pair<int, int>, int> mp;     for (int cs = 1; cs <= n; cs++) {       cin >> a.p >> a.t;       mp[make_pair(a.p, a.t)]++;       v.push_back(a);     }     sort(v.begin(), v.end(), sss);     cout << mp[{v[k - 1].p, v[k - 1].t}] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500;   const int dr[] = {0, 1, 0, -1};   const int dc[] = {1, 0, -1, 0};   bool vis[MAXN + 5][MAXN + 5];   char grid[MAXN + 5][MAXN + 5];   int W, H;   vector<pair<char, pair<int, int> > > ans;   inline void put(char ch, int i, int j) {     ans.push_back(make_pair(ch, make_pair(i, j)));   }   void buildRed(int i, int j) {     if (i < 0 || j < 0 || i >= H || j >= W) return;     if (grid[i][j] ==  # ) return;     if (vis[i][j]) return;     vis[i][j] = true;     for (int dir = 0; dir < 4; dir++) buildRed(i + dr[dir], j + dc[dir]);     put( D , i + 1, j + 1);     put( R , i + 1, j + 1);     return;   }   int main() {     int c, c2;     scanf( %d%d , &H, &W);     for (c = 0; c < H; c++) scanf( %s , grid[c]);     for (c = 0; c < H; c++)       for (c2 = 0; c2 < W; c2++)         if (grid[c][c2] ==  . ) put( B , c + 1, c2 + 1);     for (c = 0; c < H; c++)       for (c2 = 0; c2 < W; c2++)         if (!vis[c][c2] && grid[c][c2] ==  . ) {           vis[c][c2] = true;           for (int dir = 0; dir < 4; dir++) buildRed(c + dr[dir], c2 + dc[dir]);         }     printf( %d n , ans.size());     for (c = 0; c < ans.size(); c++)       printf( %c %d %d n , ans[c].first, ans[c].second.first,              ans[c].second.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 19;   int n, k, m, e, a[N], b[N], g[N], c[N], d[N], f[N], t[N], w[N], p[N];   vector<int> v[N];   void upd(int k) {     if (t[k << 1] > t[k << 1 | 1])       t[k] = t[k << 1] + w[k], p[k] = p[k << 1];     else       t[k] = t[k << 1 | 1] + w[k], p[k] = p[k << 1 | 1];   }   void build(int k = 1, int l = 1, int r = n) {     if (l == r) {       t[k] = d[g[l]];       w[k] = 0;       p[k] = l;       return;     }     int h = l + r >> 1;     build(k << 1, l, h);     build(k << 1 | 1, h + 1, r);     upd(k);   }   void modify(int L, int R, int X, int k = 1, int l = 1, int r = n) {     if (L <= l && r <= R) {       w[k] += X;       t[k] += X;       return;     }     int h = l + r >> 1;     if (L <= h) modify(L, R, X, k << 1, l, h);     if (h < R) modify(L, R, X, k << 1 | 1, h + 1, r);     upd(k);   }   void dfs(int u, int fa) {     int i, x, o = 1;     a[u] = ++e;     g[e] = u;     d[u] = d[fa] + 1;     f[u] = fa;     for (i = 0; i < v[u].size(); i++) {       x = v[u][i];       if (x != fa) dfs(x, u), o = 0;     }     m += o;     b[u] = e;   }   void go(int x) {     while (x && !c[x]) {       modify(a[x], b[x], -1);       c[x] = 1;       e++;       x = f[x];     }   }   int main() {     int i, x, y;     long long s = 0;     scanf( %d%d , &n, &k);     for (i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     e = 0;     dfs(1, 0);     if (m <= k) {       for (i = m; i <= k; i++) s = max(s, (long long)i * (n - i));       cout << s;       return 0;     }     build();     e = 0;     for (i = 1; i <= k; i++) {       go(g[p[1]]);     }     s = (long long)k * (n - k);     for (i = 0; i <= n - e; i++) s = min(s, (long long)(k - i) * (n - k - i));     cout << s;     return 0;   }