malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 1;   int n, m;   vector<int> A[MAXN];   int d[MAXN];   void dfs(int nod) {     for (int i = 0; i < A[nod].size(); i++) {       int v = A[nod][i];       if (d[v] == 0) {         d[v] = d[nod] + 1;         dfs(v);       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       A[a].push_back(b);       A[b].push_back(a);     }     d[1] = 1;     dfs(1);     int u = max_element(d + 1, d + n + 1) - d;     fill(d + 1, d + n + 1, 0);     d[u] = 1;     dfs(u);     int sol = *max_element(d + 1, d + n + 1);     sol--;     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7, mod = 1e9 + 7;   int dp[N], sum[N], i, n, m, j, k, nxt[N], v[N];   char a[N], b[N];   int main() {     for (scanf( %s%s , a + 1, b + 1), n = strlen(a + 1), m = strlen(b + 1), i = 2;          i <= m; ++i) {       while (b[j + 1] != b[i] && j) j = nxt[j];       if (b[j + 1] == b[i]) j++;       nxt[i] = j;     }     for (i = 1, j = 0; i <= n; ++i) {       while (b[j + 1] != a[i] && j) j = nxt[j];       if (b[j + 1] == a[i]) j++;       if (j == m) v[i] = 1, j = nxt[j];     }     for (i = 1, j = -1; i <= n; ++i) {       dp[i] = dp[i - 1];       if (v[i]) j = i - m + 1;       if (j != -1) dp[i] += sum[j - 1] + j, dp[i] %= mod;       sum[i] = (sum[i - 1] + dp[i]) % mod;     }     return 0 * printf( %d n , dp[n]);   }
#include <bits/stdc++.h>   using namespace std;   long long int vis[1005][1005];   char a[1005][1005];   pair<pair<long long int, long long int>, long long int> fuck[1005][1005];   long long int dfs(long long int i, long long int j,                     pair<long long int, long long int> par) {     vis[i][j] = 1;     long long int ret = 1;     if (a[i + 1][j] ==  .  && vis[i + 1][j] == 0) ret += dfs(i + 1, j, par);     if (a[i - 1][j] ==  .  && vis[i - 1][j] == 0) ret += dfs(i - 1, j, par);     if (a[i][j + 1] ==  .  && vis[i][j + 1] == 0) ret += dfs(i, j + 1, par);     if (a[i][j - 1] ==  .  && vis[i][j - 1] == 0) ret += dfs(i, j - 1, par);     fuck[i][j] = make_pair(par, ret);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long int i, j;       for (i = 0; i < 1005; i++) {         for (j = 0; j < 1005; j++) {           vis[i][j] = 0;           a[i][j] =  * ;         }       }       long long int n, m;       cin >> n >> m;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           cin >> a[i][j];         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (a[i][j] ==  .  && vis[i][j] == 0) {             dfs(i, j, make_pair(i, j));           }         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (a[i][j] ==  . ) {             cout <<  . ;           } else {             map<pair<long long int, long long int>, long long int> ma;             if (a[i + 1][j] ==  . ) {               ma[fuck[i + 1][j].first] =                   fuck[fuck[i + 1][j].first.first][fuck[i + 1][j].first.second]                       .second;             }             if (a[i - 1][j] ==  . ) {               ma[fuck[i - 1][j].first] =                   fuck[fuck[i - 1][j].first.first][fuck[i - 1][j].first.second]                       .second;             }             if (a[i][j + 1] ==  . ) {               ma[fuck[i][j + 1].first] =                   fuck[fuck[i][j + 1].first.first][fuck[i][j + 1].first.second]                       .second;             }             if (a[i][j - 1] ==  . ) {               ma[fuck[i][j - 1].first] =                   fuck[fuck[i][j - 1].first.first][fuck[i][j - 1].first.second]                       .second;             }             long long int ans = 1;             for (auto it : ma) {               ans += it.second;             }             cout << ans % 10;           }         }         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   typedef long long ll;   typedef long double ld;   #define fr(i, a, b) for (ll i = a; i < b; i++)   #define rf(i, a, b) for (ll i = a; i >= b; i--)   typedef std::vector<long long> vi;   #define F first   #define S second   #define fast                             ios_base::sync_with_stdio(0);        cin.tie(0);                          cout.tie(0);   #define mod 1000000007   #define PB push_back   #define MP make_pair   #define PI 3.14159265358979323846   #define all(a) a.begin(), a.end()   #define mx(a) *max_element(all(a))   #define mn(a) *min_element(all(a))   const ll INF = LLONG_MAX / 2;   const ll N = 2e5 + 1;   using namespace std;   void solve()   {       ll n, c;       cin >> n >> c;       ll a[n], b[n];       fr(i, 0, n)       {           cin >> a[i];       }       fr(i, 1, n)               cin >>           b[i];       ll ans = INF, prevcoins = 0, prevdays = 0;       fr(i, 0, n - 1)       {           if (c <= prevcoins)               ans = min(prevdays, ans);           ans = min(prevdays + (c - prevcoins + a[i] - 1) / a[i], ans);           // cout << prevdays + (c - prevcoins + a[i] - 1) / a[i] <<    ;           if (prevcoins >= b[i + 1])           {               prevcoins = prevcoins - b[i + 1];               prevdays++;           }           else           {               prevdays = prevdays + (b[i + 1] + a[i] - 1 - prevcoins) / a[i] + 1;               prevcoins = ((b[i + 1] + a[i] - 1 - prevcoins) / a[i]) * a[i] + prevcoins - b[i + 1];           }           // cout << prevdays <<     << prevcoins <<   n ;       }       ll i = n - 1;       ans = min(prevdays + (c - prevcoins + a[i] - 1) / a[i], ans);       // cout <<   n ;       cout << ans <<   n ;   }   int main()   {       fast;       ll t = 1;       std::cin >> t;       while (t--)       {           solve();       }   }
#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b) return a;     return b;   }   long long int min(long long int a, long long int b) {     if (a < b) return a;     return b;   }   long long int msb(long long int n) {     long long int ans;     for (long long int i = 31; i >= 0; i--)       if ((1LL << i) & (n)) {         ans = i;         break;       }     return ans;   }   long long power(long long x, int y, int p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modFact(long long int n, long long int p) {     if (n >= p) return 0;     long long int result = 1;     for (long long int i = 1; i <= n; i++) result = (result * i) % p;     return result;   }   long long modInverse(long long n, int p) { return power(n, p - 2, p); }   long long nCrModPFermat(long long n, int r, int p) {     if (r == 0) return 1;     long long fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   vector<long long int> primes;   void sieve(long long int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long int p = 2; p <= n; p++) {       if (prime[p] == true) {         for (long long int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long int p = 2; p <= n; p++)       if (prime[p]) primes.push_back(p);   }   vector<long long int> adj[100001], rev[100001];   bool vis[100001], recur[100001];   void init(long long int n) {     for (long long int i = 0; i <= n; i++) {       adj[i].clear();       rev[i].clear();       vis[i] = false;       recur[i] = false;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, x, k;     cin >> n >> x >> k;     long long int ar[n];     for (int i = 0; i < n; i++) cin >> ar[i];     if (x > k)       cout << n << endl;     else {       int ct = 0;       for (int i = 0; i < n; i++) {         if (ar[i] <= x) ct++;       }       double ans = double(ct) / 2.0;       cout << ceil(ans) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = 1LL << 55;   const int MAX_N = 100005;   const int MAX_M = 100005;   const int MAX_P = 105;   template <class T>   class Deque {    public:     Deque() { Clear(); }     void Clear() { front = 1, back = 0; }     void PushBack(const T x) { values[++back] = x; }     void PopBack() { --back; }     void PopFront() { ++front; }     T Front() const { return values[front]; }     T Back() const { return values[back]; }     bool Empty() const { return front > back; }     int Size() const { return back - front + 1; }     T &operator[](const int index) { return values[front + index]; }       private:     T values[MAX_M];     int front, back;   };   class Line {    public:     long long m, n;     Line() {}     Line(const long long m, const long long n) {       this->m = m;       this->n = n;     }     long long Value(const long long x) const { return m * x + n; }     static double Intersect(const Line &L1, const Line &L2) {       return (1.0 * L2.n - L1.n) / (1.0 * L1.m - L2.m);     }   };   int N, M, P, D[MAX_N], T[MAX_M];   long long SumT[MAX_M], DP[2][MAX_M], Solution;   void Preprocess() {     T[0] = 0;     sort(T + 1, T + M + 1);     SumT[0] = 0;     for (int i = 1; i <= M; ++i) SumT[i] = SumT[i - 1] + T[i];   }   void Solve() {     Preprocess();     DP[0][0] = 0;     for (int i = 1; i <= M; ++i) DP[0][i] = 1LL * T[i] * i - SumT[i];     for (int p = 2; p <= P; ++p) {       Deque<Line> deq;       for (int i = p; i <= M; ++i) {         Line L = Line(-(i - 1), SumT[i - 1] + DP[0][i - 1]);         while (deq.Size() > 1 &&                Line::Intersect(deq[deq.Size() - 1], L) <                    Line::Intersect(deq[deq.Size() - 2], deq[deq.Size() - 1]))           deq.PopBack();         deq.PushBack(L);         while (deq.Size() > 1 && Line::Intersect(deq[0], deq[1]) < 1.0 * T[i])           deq.PopFront();         DP[1][i] = deq.Front().Value(T[i]) + 1LL * i * T[i] - SumT[i];       }       memcpy(DP[0], DP[1], sizeof(DP[1]));     }     Solution = DP[0][M];   }   void Read() {     cin >> N >> M >> P;     D[1] = 0;     for (int i = 2; i <= N; ++i) {       cin >> D[i];       D[i] += D[i - 1];     }     for (int i = 1; i <= M; ++i) {       int h, t;       cin >> h >> t;       T[i] = t - D[h];     }   }   void Print() { cout << Solution <<   n ; }   int main() {     Read();     Solve();     Print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 355001;   const int SQRTN = 320;   const int LOGN = 20;   const long double PI = acos(-1);   const long double TAU = 2 * PI;   long long nk, n, k, a, b;   vector<long long> first, last;   long long gcd(long long x, long long b) {     if (b == 0) return x;     return gcd(b, x % b);   }   signed main() {     cin >> n >> k >> a >> b;     nk = n * k;     first.push_back(a);     first.push_back(k - a);     last.push_back(b);     last.push_back(k - b);     for (int i = 0; i < n; i++) {       last.push_back((last[0] + nk - i * k) % nk);       last.push_back((last[1] + nk - i * k) % nk);       last.push_back((i * k + last[0]) % nk);       last.push_back((i * k + last[1]) % nk);     }     long long mn = 100000000000000ll, mx = 0;     for (int i = 0; i < last.size(); i++) {       mn = min(mn, nk / gcd(nk, abs(last[i] - first[0])));       mx = max(mx, nk / gcd(nk, abs(last[i] - first[0])));       mx = max(mx, nk / gcd(nk, abs(last[i] - first[1])));       mn = min(mn, nk / gcd(nk, abs(last[i] - first[1])));     }     cout << mn <<     << mx << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long R[10 << 10][1 << 10];   int A[10 << 10];   int n, m, g, r;   int main() {     cin >> n >> m;     int i, j;     for (i = (0); i < (m); ++i) cin >> A[i];     cin >> g >> r;     sort(A, A + m);     for (i = (0); i < (m); ++i)       for (j = (0); j < (g + 1); ++j) R[i][j] = (1LL << 60);     R[0][0] = 0;     deque<pair<long long, pair<int, int>>> q;     q.push_front(make_pair(R[0][0], pair<int, int>(0, 0)));     long long res = (1LL << 60);     while (!q.empty()) {       int pos = q.front().second.first;       int rem = q.front().second.second;       long long val = q.front().first;       q.pop_front();       if (R[pos][rem] != val) continue;       if (pos == m - 1) res = min(res, val);       int p[] = {pos - 1, pos + 1};       int d[] = {pos == 0 ? -1 : A[pos] - A[pos - 1],                  pos + 1 == m ? -1 : A[pos + 1] - A[pos]};       for (i = (0); i < (2); ++i)         if (0 <= p[i] && p[i] < m && d[i] > 0 && rem + d[i] <= g) {           int pos2 = p[i];           int rem2 = rem + d[i];           int val2 = val + d[i];           if (R[pos2][rem2] > val2) {             R[pos2][rem2] = val2;             q.push_front(make_pair(R[pos2][rem2], pair<int, int>(pos2, rem2)));           }         }       if (rem == g) {         int pos2 = pos;         int rem2 = 0;         int val2 = val + r;         if (R[pos2][rem2] > val2) {           R[pos2][rem2] = val2;           q.push_back(make_pair(R[pos2][rem2], pair<int, int>(pos2, rem2)));         }       }     }     if (res == (1LL << 60)) res = -1;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a, b;       cin >> a >> b;       int moves = 0;       if (a == b) {         cout << 0 <<   n ;         continue;       } else if (a < b) {         int needed = b - a;         moves = needed % 2 == 1 ? 1 : 2;       } else {         int needed = a - b;         moves = needed % 2 == 0 ? 1 : 2;       }       cout << moves <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct lady {     int b, i, r;   } a[500005];   bool operator<(const lady& a, const lady& b) {     if (a.b != b.b) return a.b > b.b;     if (a.i != b.i) return a.i < b.i;     return a.r < b.r;   }   int n;   void inp() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].b);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].i);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].r);   }   set<int> s;   int x[500005], m;   void ready() {     for (int i = 1; i <= n; ++i) s.insert(a[i].i);     for (typeof((s).begin()) it = (s).begin(); it != (s).end(); ++it)       x[++m] = *it;   }   int bi[500005], ans;   inline void update(int u, int val) {     u = lower_bound(x + 1, x + m + 1, u) - x;     for (; u; u &= u - 1) bi[u] = max(bi[u], val);   }   inline int get(int u) {     u = lower_bound(x + 1, x + m + 1, u) - x;     int res = 0;     for (; u <= m; u += u & -u) res = max(res, bi[u]);     return res;   }   void solve() {     ready();     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       ans += get(a[i].i + 1) > a[i].r;       update(a[i].i, a[i].r);     }     printf( %d n , ans);   }   int main() {     srand(time(NULL));     inp();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, s;     cin >> n >> s;     vector<int> g(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u]++;       g[v]++;     }     int cnt = 0;     for (int i = 0; i < n; i++) {       if (g[i] == 1) {         cnt++;       }     }     double ans = s;     if (n > 2) {       ans = 2.0 * s / cnt;     }     cout.precision(10);     cout << fixed << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   double r, v, l;   double tim(double p1, double p2) {     double rem = p2 - p1;     double k = int(rem / l);     rem = rem - k * l;     double le = 0, ri = 1e9, mid;     for (int I = 1; I <= 200; I++) {       mid = (le + ri) / 2.0;       if (v * mid + 2 * sin(v * mid / (2 * r)) * r >= rem) {         ri = mid;       } else {         le = mid;       }     }     return mid + double(k * l) / v;   }   int main() {     scanf( %d%lf%lf , &n, &r, &v);     l = 3.141592653589 * r * 2;     for (int i = 1; i <= n; i++) {       int p1, p2;       scanf( %d%d , &p1, &p2);       printf( %.10f n , float(tim(double(p1), double(p2))));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, q;     string s;     bool can = true;     vector<string> vec;     int aux = 0;     int pos = 0;     cin >> n >> p >> q;     cin >> s;     aux = n;     if (n % p == 0) {       cout << n / p << endl;       for (int i = 0; i < n; i += p) {         cout << s.substr(i, p) << endl;       }     } else if (n % q == 0) {       cout << n / q << endl;       for (int i = 0; i < n; i += q) {         cout << s.substr(i, q) << endl;       }     } else {       while (((aux % q != 0)) && pos < n) {         vec.push_back(s.substr(pos, p));         pos += p;         aux -= p;         if (aux < 0) {           can = false;         }       }       if (can) {         while (pos < n) {           vec.push_back(s.substr(pos, q));           pos += q;         }         cout << vec.size() << endl;         for (int i = 0; i < vec.size(); i++) {           cout << vec[i] << endl;         }       } else {         cout << -1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     long long int i, a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     if (a[1] == a[n]) {       cout << 1 << endl;       return;     }     if (k == 1 && a[1] != a[n]) {       cout << -1 << endl;       return;     }     long long int c = 0;     for (i = 1; i < n; i++) {       if (a[i] != a[i + 1]) c++;     }     long long int ans = ceil(c * 1.0 / (k - 1));     if (ans < 0) ans = 1;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   long long mod(long long n) {     if (n < 0) {       return (n % MOD + MOD) % MOD;     } else {       if (n < MOD)         return n;       else if (n < 2 * MOD)         return n - MOD;       else         return n % MOD;     }   }   long long fp(long long a, long long p) {     long long ans = 1, cur = a;     for (long long i = 0; (1 << i) <= p; ++i) {       if ((p >> i) & 1) ans = mod(ans * cur);       cur = mod(cur * cur);     }     return ans;   }   long long dv(long long a, long long b) { return mod(a * fp(b, MOD - 2)); }   const long long N = 101;   long long m[N][N], ans[N][N], t[N][N];   void add(long long a[N][N], long long b[N][N]) {     for (long long i = 0; i < N; ++i) {       for (long long j = 0; j < N; ++j) {         t[i][j] = 0;       }     }     for (long long i = 0; i < N; ++i) {       for (long long j = 0; j < N; ++j) {         for (long long k = 0; k < N; ++k) {           t[i][j] = mod(t[i][j] + a[i][k] * b[k][j]);         }       }     }     for (long long i = 0; i < N; ++i) {       for (long long j = 0; j < N; ++j) {         a[i][j] = t[i][j];       }     }   }   void pw(long long p) {     for (long long i = 0; i < N; ++i) ans[i][i] = 1;     for (long long i = 0; (1 << i) <= p; ++i) {       if ((p >> i) & 1) add(ans, m);       add(m, m);     }   }   bool a[N];   long long cnt[2];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       ++cnt[a[i]];     }     long long l = cnt[0];     long long r = n - l;     long long op = n * (n - 1) / 2;     for (long long l1 = 0; l1 <= cnt[0] && l1 <= cnt[1]; ++l1) {       long long l0 = l - l1;       long long r0 = cnt[0] - l0;       long long r1 = cnt[1] - l1;       m[l1][l1] = op;       if (l1) {         m[l1][l1 - 1] = mod(l1 * r0);         m[l1][l1] = mod(m[l1][l1] - m[l1][l1 - 1]);       }       m[l1][l1 + 1] = mod(l0 * r1);       m[l1][l1] = mod(m[l1][l1] - m[l1][l1 + 1]);     }     pw(k);     long long sum = 0;     for (long long i = 0; i < l; ++i) sum += a[i];     cout << dv(ans[sum][0], fp(op, k)) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b, ans;     cin >> a >> b;     int x = (a / 4) * 4;     int i = x, val = 0;     while (i < a) {       val = val ^ i;       i++;     }     if (val == b) {       ans = a;     } else if ((val ^ a) == b) {       ans = a + 2;     } else {       ans = a + 1;     }     cout << ans << endl;     return;   }   int main() {     int t;     cin >> t;     while (t > 0) {       solve();       t--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int a[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int tot = 0;     for (int i = 1; i <= n; i++) {       if (m < (i - 1) / 2) break;       a[++tot] = i;       m -= (i - 1) / 2;     }     if (!m) {       int cnt = 1e8;       for (int i = tot + 1; i <= n; i++) a[i] = cnt, cnt += 10000;       for (int i = 1; i <= n; i++) cout << a[i] <<    ;     } else {       if (tot == n)         puts( -1 );       else {         a[tot + 1] = a[tot] + a[tot] - m * 2 + 1;         int cnt = 1e8;         for (int i = tot + 2; i <= n; i++) a[i] = cnt, cnt += 10000;         for (int i = 1; i <= n; i++) cout << a[i] <<    ;       }     }   }
#include <bits/stdc++.h>   const int N = 500500;   std::vector<int> g[N];   int d[N];   int n, maxM, maxD;   void go(int cur, int par = -1, int dist = 0) {     if (dist > maxD) maxD = dist;     bool f = false;     for (auto v : g[cur])       if (v != par) {         go(v, cur, dist + 1);         f = true;       }     if (!f) ++d[dist];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (auto v : g[1]) {       for (int i = 0; i <= maxD; ++i) d[i] = 0;       maxD = 0;       go(v, 1);       int p = -1;       for (int i = 0; i <= maxD; ++i)         if (d[i] > 0) {           if (i > p)             p = i + d[i] - 1;           else             p += d[i];         }       if (p + 1 > maxM) maxM = p + 1;     }     printf( %d n , maxM);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     if (n == k || k == 0)       cout << 0 <<     << 0;     else {       long long int min = 1, max;       if (2 * k + k < n)         max = 2 * k;       else         max = n - k;       cout << min <<     << max;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<pair<int, bool>> v(2 * n);     for (int i = 0; i < 2 * n; i++) cin >> v[i].first, v[i].second = true;     long long ans = 0, cc = 0;     for (int i = 0; i < 2 * n; i++) {       if (!v[i].second) continue;       cc = 0;       v[i].second = false;       for (int j = i + 1; j < 2 * n; j++) {         if (v[j].second && v[i].first != v[j].first) {           cc++;         } else if (v[i].first == v[j].first) {           v[j].second = false;           break;         }       }       ans += cc;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int chill = 1;     while (chill--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, dp[1 << 21], b, ans = 3e18;   pair<long long, pair<long long, long long> > a[1 << 21];   int main() {     cin >> n >> m >> b;     for (long long i = 0, m, x; i < n; i++) {       cin >> a[i].second.first >> a[i].first >> m;       while (m--) cin >> x, x--, a[i].second.second += 1 << x;     }     for (long long i = 0; i < (1 << m); i++) dp[i] = ans;     dp[0] = 0, sort(a, a + n);     for (long long i = 0; i < n; i++) {       for (int j = 0; j < (1 << m); j++)         dp[j] = min(dp[j], dp[j & (j ^ a[i].second.second)] + a[i].second.first);       ans = min(ans, dp[(1 << m) - 1] + a[i].first * b);     }     cout << (ans < (long long)3e18 ? ans : -1);     return 0;   }