func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long N = 2e5 + 10;   inline long long add(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline long long mul(long long x, long long y) {     x = (1LL * x * y) % mod;     return x;   }   long long first[N];   long long lvl[N];   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, k;     cin >> n >> k;     long long maxv = 0;     vector<long long> v(n);     for (long long i = 0; i <= n - 1; ++i) {       cin >> v[i];       first[v[i]]++;       maxv = max(maxv, v[i]);     }     long long ans = INF;     for (long long i = 0; i <= maxv; ++i) {       queue<long long> q;       q.push(i);       lvl[i] = 0;       long long val = 0;       long long cc = 0;       while (!q.empty()) {         long long x = q.front();         q.pop();         if (cc + first[x] > k) {           val += (k - cc) * lvl[x];           cc = k;           break;         } else {           cc += first[x];           val += first[x] * lvl[x];           if (i == 0) {           }         }         if (cc >= k) break;         if (2 * x <= 2e5 and x > 0) {           q.push(2 * x);           lvl[2 * x] = 1 + lvl[x];         }         if (2 * x + 1 <= 2e5) {           q.push(2 * x + 1);           lvl[2 * x + 1] = 1 + lvl[x];         }       }       if (cc < k) val = INF;       ans = min(ans, val);     }     cout << ans;     return 0;   }   