#include <bits/stdc++.h>   using namespace std;   const int MAX = 2 * 1e5 + 5;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int N, K, A[MAX], table[20][MAX];   int main() {     cin >> N >> K;     for (int i = 0; i < (N); ++i) cin >> A[i];     for (int i = 0; i < (N); ++i) table[0][i] = A[i];     vector<int> b(N, 0);     for (int i = 0; i < (N); ++i) {       for (int j = 0; j < (19); ++j) {         table[j + 1][i] = table[j][i] / 2;         b[i]++;         if (table[j + 1][i] == 0) break;       }     }     map<int, int> m, cost;     int ans = INF;     for (int i = 0; i < (20); ++i) {       for (int j = 0; j < (N); ++j) {         if (b[j] < i) continue;         int num = table[i][j];         m[num]++;         cost[num] += i;         if (m[num] >= K) ans = min(ans, cost[num]);       }     }     cout << ans << endl;   }   