func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long double eps = 1e-6;   const long long maxn = 1e6 + 100;   vector<long long> g[maxn];   long long szc1[maxn], szc2[maxn];   vector<long long> used;   void dfsc(long long v, long long col) {     used[v] = 1;     szc1[col]++;     szc2[col]++;     for (long long u : g[v]) {       if (used[u]) continue;       dfsc(u, col);     }   }   bitset<maxn> dp;   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long n, k;     cin >> n >> k;     vector<long long> p(n);     for (long long i = 0; i < n; ++i) {       cin >> p[i], --p[i];       g[i].push_back(p[i]);       g[p[i]].push_back(i);     }     long long idxc = 0;     used.assign(n, 0);     for (long long i = 0; i < n; ++i) {       if (!used[i]) {         dfsc(i, idxc);         ++idxc;       }     }     long long ansl = 0, ansr = 0;     long long kl = k, kr = k;     for (long long i = 0; i < idxc; ++i) {       if (szc1[i] >= 2 && kr) {         --kr;         ansr += 2;       }     }     long long add = 0;     for (long long i = 0; i < idxc && kr; ++i) {       long long t = szc1[i];       long long x = t / 2 - 1;       if (t >= 3 && t % 2) {         ++add;       }       x = min(x, kr);       if (x >= 1) {         ansr += 2 * x;         kr -= x;       }     }     add = min(add, kr);     ansr += add;     kr -= add;     vector<pair<long long, long long>> gg;     vector<long long> cnt(n + 1, 0), us(n + 1, 0);     for (long long i = 0; i < idxc; ++i) {       cnt[szc2[i]]++;     }     for (long long i = 0; i < idxc; ++i) {       if (us[szc2[i]]) continue;       gg.push_back({szc2[i], cnt[szc2[i]]});       us[szc2[i]] = 1;     }     dp[0] = 1;     for (long long i = 0; i < (long long)gg.size(); ++i) {       for (long long t = 1; t <= gg[i].second; t *= 2) {         long long x = t * gg[i].first;         auto bb = dp;         bb <<= x;         dp |= bb;         gg[i].second -= t;       }       long long x = gg[i].second * gg[i].first;       auto bb = dp;       bb <<= x;       dp |= bb;     }     if (dp[kl])       ansl = kl;     else       ansl = kl + 1;     cout << ansl <<     << ansr;     return 0;   }   