malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read_int() {     int x;     scanf( %i , &x);     return x;   }   inline int endline() { return printf(  n ); }   inline int space() { return printf(   ); }   inline int write_int(const int x) { return printf( %i , x); }   class color_ice_cream : public pair<bitset<500000>, bitset<500000> > {     int n, m, last_used_color, *color;     vector<int> *ice_cream, *neighbor;       public:     color_ice_cream()         : n(read_int()),           m(read_int()),           last_used_color(-1),           color(new int[m]),           ice_cream(new vector<int>[n]),           neighbor(new vector<int>[n]) {       for (int i = 0; i < n; i++) {         int k = read_int();         for (int j = 0; j < k; j++) ice_cream[i].push_back(read_int() - 1);       }       for (int i = 1; i < n; i++) {         int u = read_int() - 1, v = read_int() - 1;         neighbor[v].push_back(u);         neighbor[u].push_back(v);       }       for (int i = 0; i < m; i++) color[i] = -1;     }     void solve(const int v = 0) {       first.set(v);       int i, j = -1, k = ice_cream[v].size(), l;       for (i = 0; i < k; i++)         if ((l = color[ice_cream[v][i]]) != -1) second.set(l);       for (i = 0; i < k; i++)         if (color[l = ice_cream[v][i]] == -1) {           while (second[++j])             ;           color[l] = j;         }       second.reset();       if (j > last_used_color) last_used_color = j;       for (i = 0, k = neighbor[v].size(); i < k; i++)         if (!first[l = neighbor[v][i]]) solve(l);     }     void write_result() {       write_int(max(last_used_color, 0) + 1), endline();       for (int i = 0; i < m; i++) write_int(max(color[i], 0) + 1), space();     }   };   int main() {     color_ice_cream problem;     problem.solve();     problem.write_result();   }
#include <bits/stdc++.h>   template <class T>   T _diff(T a, T b) {     return (a < b ? b - a : a - b);   }   template <class T>   T _abs(T a) {     return (a < 0 ? -a : a);   }   template <class T>   T _max(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T _min(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T max3(T a, T b, T c) {     return (_max(a, b) > c ? _max(a, b) : c);   }   template <class T>   T min3(T a, T b, T c) {     return (_min(a, b) < c ? _min(a, b) : c);   }   template <class T>   T GCD(T a, T b) {     a = _abs(a);     b = _abs(b);     T tmp;     while (a % b) {       tmp = a % b;       a = b;       b = tmp;     }     return b;   }   template <class T>   T LCM(T a, T b) {     a = _abs(a);     b = _abs(b);     return (a / GCD(a, b)) * b;   }   using namespace std;   int x, y, xp, yp, xn, ynw, xl, yl, chk, si, t;   int main() {     cin >> x >> y;     xn = ynw = 0;     chk = 1;     xl = 0;     yl = 0;     t = 0;     si = 1;     int row = 1, col = 0;     t = 0;     while (1) {       xp = xn;       yp = ynw;       if (chk == 1) {         si = 1;         chk++;         xl++;         yl++;       } else if (chk == 2) {         si = 1;         chk++;       } else if (chk == 3) {         si = -1;         chk++;       } else if (chk == 4) {         si = -1;         chk = 1;       }       if (row) {         xn = (si) * (xl);         row = 0;         col = 1;       } else {         ynw = (si) * (yl);         row = 1;         col = 0;       }       if (x == xn && x == xp) {         if (si == 1 && y >= yp && y <= ynw)           break;         else if (si == -1 && y >= ynw && y <= yp)           break;       } else if (y == ynw && y == yp) {         if (si == 1 && x >= xp && x <= xn)           break;         else if (si == -1 && x <= xp && x >= xn)           break;       }       t++;     }     cout << t << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<char, int>& x, const pair<char, int>& y) {     int u = max(x.first -  a ,  z  - x.first);     int v = max(y.first -  a ,  z  - y.first);     return u > v;   }   int main() {     if (0 & 1) freopen( input ,  r , stdin);     if (0 & 2) freopen( output ,  w , stdout);     int n, k;     scanf( %d %d , &n, &k);     vector<pair<char, int> > a(n);     int id = 0;     for (auto& e : a) {       scanf(  %c , &e.first);       e.second = id++;     }     sort(a.begin(), a.end(), cmp);     string ans(n,    );     for (auto& e : a) {       int u = e.first -  a , v =  z  - e.first, cur;       if (u > v) {         cur = min(k, u);         ans[e.second] = e.first - cur;       } else {         cur = min(k, v);         ans[e.second] = e.first + cur;       }       k -= cur;     }     if (k)       printf( -1 n );     else       printf( %s n , ans.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int M = 998244853, maxn = 4005;   int n, m;   void madd(int& a, int b) {     a += b;     if (a >= M) a -= M;   }   int ch[maxn][maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     ch[0][0] = 1;     for (int i = 1; i < maxn; i++) {       for (int j = 0; j <= i; j++) {         madd(ch[i][j], ch[i - 1][j]);         if (j > 0) madd(ch[i][j], ch[i - 1][j - 1]);       }     }     int ans = 0;     for (int k = 1; k <= n; k++) {       if (n >= m + k) {         madd(ans, ch[n + m][n]);       } else {         madd(ans, ch[n + m][m + k]);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int NAX = 3e5 + 1;   const int INF = 1e9 + 1;   const long long UMAX = 2e18 + 1;   long long sm(long long n) {     int res = 0;     while (n > 0) {       res += n % 10;       n /= 10;     }     return res;   }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     vector<long long> ans;     for (int i = 0; i < n; ++i) cin >> v[i];     sort(v.begin(), v.end());     long long p1 = v[0] * v[1] * v[2] * v[3] * v[n - 1];     long long p2 = v[n - 1] * v[n - 2] * v[n - 3] * v[n - 4] * v[n - 5];     long long p3 = v[0] * v[1] * v[n - 1] * v[n - 2] * v[n - 3];     ans.push_back(p1);     ans.push_back(p2);     ans.push_back(p3);     cout << *max_element(ans.begin(), ans.end()) <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long T;     cin >> T;     while (T--) {       long long n;       cin >> n;       long long i, j = 1;       cout <<  2  ;       for (i = 1; i < n; i++) {         j += 2;         cout << j <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     vector<Node*> edges;     bool term;     vector<int> last;     Node() {       edges.resize(5);       fill(edges.begin(), edges.end(), nullptr);       term = false;     }   };   void add_string(Node* root, string s) {     for (char c : s) {       c -=  a ;       if (!root->edges[c]) {         Node* node = new Node();         root->edges[c] = node;       }       root = root->edges[c];     }     root->term = true;     root->last.push_back(0);   }   void get_ans(Node* node, string s, int cnt, int& ans, int num) {     if (cnt >= s.size()) {       if (node->term) {         for (int i = 0; i < node->last.size(); i++) {           if (node->last[i] < num) {             node->last[i] = num;             ans++;           }         }       }       return;     }     char c = s[cnt];     c -=  a ;     if (s[cnt] !=  ? ) {       if (node->edges[c]) {         get_ans(node->edges[c], s, cnt + 1, ans, num);       }     } else {       get_ans(node, s, cnt + 1, ans, num);       for (int i = 0; i < 5; i++) {         if (node->edges[i]) {           get_ans(node->edges[i], s, cnt + 1, ans, num);         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     Node* root = new Node();     for (int i = 0; i < n; i++) {       string s;       cin >> s;       add_string(root, s);     }     for (int i = 0; i < m; i++) {       string s;       cin >> s;       int ans = 0;       get_ans(root, s, 0, ans, i + 1);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long a[510];   long long dp[510][510];   long long stt[510];   long long mod = 998244353;   long long solve(long long st, long long en) {     if (st >= en) {       return 1;     }     if (dp[st][en] != -1) return dp[st][en];     long long c = 1e9;     for (int i = st; i <= en; i++) c = min(c, a[i]);     long long sol = 0;     long long sol1 = 0;     for (int i = st; i <= stt[c]; i++) {       sol += solve(i, stt[c] - 1) * solve(st, i - 1);       sol %= mod;     }     for (int i = en; i >= stt[c]; i--) {       sol1 += solve(stt[c] + 1, i) * solve(i + 1, en);       sol1 %= mod;     }     sol *= sol1;     sol %= mod;     return dp[st][en] = sol;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     memset(stt, -1, sizeof stt);     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) {       cin >> a[i];       stt[a[i]] = i;     }     long long ss = solve(0, n - 1);     cout << ss << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   void run(std::istream &in, std::ostream &out) {     int n;     in >> n;     std::vector<int> as(n);     int sum = 0;     for (int i = 0; i < n; i++) {       in >> as[i];       sum += as[i];     }     if (sum % 2 == 0) {       for (int j = 2; j <= sum; j += 2) {         if (sum % j != 0) continue;         int d = sum / j;         bool good = true;         for (int k = 0; k < n; k++) {           if ((as[k] % (2 * d)) != 0) {             good = false;             break;           }         }         if (good) {           out << 2 * d << std::endl;           std::string s;           for (int k = 0; k < n; k++) {             s.append(std::string(as[k] / (2 * d),  a  + k));           }           std::string ss = s;           std::reverse(ss.begin(), ss.end());           s.append(ss);           std::string res;           for (int k = 0; k < d; k++) {             res.append(s);           }           out << res << std::endl;           return;         }       }     } else {       for (int j = 1; j <= sum; j += 2) {         if (sum % j != 0) continue;         int d = sum / j;         int countOdd = 0;         int oddIdx = 0;         bool good = true;         for (int k = 0; k < n; k++) {           if ((as[k] % d) != 0) {             good = false;             break;           }           if (((as[k] / d) % 2) != 0) {             countOdd++;             oddIdx = k;           }         }         if (!good) continue;         if (countOdd != 1) continue;         out << d << std::endl;         std::string s;         for (int k = 0; k < n; k++) {           s.append(std::string(as[k] / d / 2,  a  + k));         }         std::string ss = s;         std::reverse(ss.begin(), ss.end());         s.append(ss);         s.push_back((char)( a  + oddIdx));         std::string res;         for (int k = 0; k < d; k++) {           res.append(s);         }         out << res << std::endl;         return;       }     }     out << 0 << std::endl;     std::string s;     for (int k = 0; k < n; k++) {       s.append(std::string(as[k],  a  + k));     }     out << s << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int i, n, fl = 0;       cin >> n;       int *a = new int[n];       for (i = 0; i < n; ++i) {         cin >> a[i];       }       sort(a, a + n);       for (i = 1; i < n; ++i) {         if (a[i] == a[i - 1]) {           fl = 1;           break;         }       }       if (fl == 1) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = s.size() - 1; i >= 0; i--) {       int x = s[i] -  0 ;       if (x >= 5)         printf( -O| );       else         printf( O-| );       x = x % 5;       if (x == 0)         printf( -OOOO n );       else if (x == 1)         printf( O-OOO n );       else if (x == 2)         printf( OO-OO n );       else if (x == 3)         printf( OOO-O n );       else         printf( OOOO- n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 16, inf = 2e8 + 10;   ;   int n, m, dis[maxn][maxn], deg[maxn], ans, dp[1024 * 33];   vector<int> veci;   void find(int a) {     int cnt = 0;     for (int i = 0; i < n; i++)       if ((a >> i) & 1) cnt++;     if (cnt % 2 == 1) return;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j && (a >> i) & 1 && (a >> j) & 1) {           int ki = a;           ki ^= (1 << i);           ki ^= (1 << j);           dp[a] = min(dp[a], dp[ki] + dis[veci[i]][veci[j]]);         }   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fill_n(dis[0], maxn * maxn, inf);     fill_n(dp, 1024 * 33, inf);     cin >> n >> m;     for (int i = 0; i < n; i++) dis[i][i] = 0;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       deg[u]++, deg[v]++;       ans += w;       dis[u][v] = dis[v][u] = min(dis[u][v], w);     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++)           dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);     for (int i = 0; i < n; i++)       if (deg[i] > 0 && dis[i][0] == inf)         return cout << -1, 0;       else if (deg[i] % 2 == 1)         veci.push_back(i);     dp[0] = 0;     for (int i = 0; i < (1 << (veci.size())); i++) find(i);     cout << ans + dp[(1 << (veci.size())) - 1];   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 7;   const int mxn = 3e5 + 9;   inline long long in() {     long long _;     scanf( %lld , &_);     return _;   }   int n, m, k;   struct node {     int len;     int link;     int firstpos;     map<char, int> nxt;     void clr() {       len = link = firstpos = 0;       nxt.clear();     }     void print() {       cerr << __FUNCTION__ <<     << 50 <<  ..  ,           cerr <<  len                 <<   =   << len,           cerr <<   ,  ,           cerr <<  link                 <<   =   << link,           cerr <<   ,  ,           cerr <<  firstpos                 <<   =   << firstpos,           cerr << endl;       for (auto z : nxt) {         cerr << z.first <<     << z.second << endl;       }     }   };   node t[mxn];   int sz, last;   void init() {     sz = last = 0;     t[0].len = 0;     t[0].firstpos = 0;     t[0].link = -1;     sz++;   }   long long cnt[mxn];   set<pair<int, int> > nodes;   void add_letter(char ch) {     int cur = sz++;     t[cur].len = t[last].len + 1;     t[cur].firstpos = t[cur].len;     cnt[cur] = 1;     nodes.insert(make_pair(t[cur].len, cur));     int p;     for (p = last; p != -1 && !t[p].nxt.count(ch); p = t[p].link)       t[p].nxt[ch] = cur;     if (p == -1)       t[cur].link = 0;     else {       int q = t[p].nxt[ch];       if (t[p].len + 1 == t[q].len)         t[cur].link = q;       else {         int clone = sz++;         t[clone].len = t[p].len + 1;         t[clone].nxt = t[q].nxt;         t[clone].link = t[q].link;         t[clone].firstpos = t[q].firstpos;         cnt[clone] = 0;         nodes.insert(make_pair(t[clone].len, clone));         for (; p != -1 && t[p].nxt[ch] == q; p = t[p].link) t[p].nxt[ch] = clone;         t[q].link = t[cur].link = clone;       }     }     last = cur;   }   string ans =   ;   void kth(int cur) {     if (k <= 0) return;     for (auto x : t[cur].nxt) {       k -= cnt[x.second];       kth(x.second);       if (k <= 0) {         ans += x.first;         return;       }     }   }   void CLR() {     for (int i = 0; i < sz; i++) {       t[i].clr();       cnt[i] = 0;     }     sz = last = 0;     nodes.clear();   }   char s[mxn];   int main() {     int tc = 1;     while (tc--) {       scanf( %s , s);       k = in();       init();       n = strlen(s);       if (1LL * n * (n + 1) < k * 2) {         printf( No such line. n );         continue;       }       for (int i = 0; i < n; i++) add_letter(s[i]);       for (set<pair<int, int> >::reverse_iterator it = nodes.rbegin();            it != nodes.rend(); it++) {         int x = (*it).second;         cnt[t[x].link] += cnt[x];       }       ans =   ;       kth(0);       reverse(ans.begin(), ans.end());       printf( %s n , ans.c_str());       if (tc) CLR();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     s =  $  + s;     int n = s.length();     vector<vector<int>> c(n, vector<int>(26, 0));     for (int i = 1; i < n; i++) {       for (int j = 0; j < 26; j++) {         c[i][j] += c[i - 1][j];       }       c[i][s[i] -  a ]++;     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       int d = 0;       for (int j = 0; j < 26; j++) {         d += ((c[r][j] - c[l - 1][j]) > 0);       }       cout << ((l == r or s[l] != s[r] or d > 2) ?  Yes n  :  No n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     unordered_map<long long, long long> mymap;     long long maxval = INT_MIN, minval = INT_MAX;     for (int i = 0; i < n; i++) {       long long temp;       cin >> temp;       mymap[temp]++;       if (temp > maxval) maxval = temp;       if (temp < minval) minval = temp;     }     cout << maxval - minval <<    ;     if (maxval == minval)       cout << (mymap[maxval] * (mymap[maxval] - 1)) / 2 << endl;     else       cout << mymap[maxval] * mymap[minval] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, ans;   int main() {     cin >> n;     int sq;     ans = -1e9;     for (int i = 0; i < n; i++) {       cin >> a;       if (a < 0) {         ans = max(ans, a);         continue;       }       sq = sqrt(a);       if (sq * sq != a) {         ans = max(ans, a);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct nom {     int i, a, l;   };   long long po(int a, int n) {     if (n == 0) return 1;     if (n == 1) return a;     if (n & 1)       return a * po(a * a, n / 2);     else       return po(a * a, n / 2);   }   struct rec {     int x, y, x1, y1;   };   int main() {     string a;     cin >> a;     cout << ((a.size() + 1) * 26 - a.size());   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, k;   long long MOD = 1000000007;   long long pref[5005][2], dp[5005][2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> a >> b >> k;     for (int i = 0; i < n + 5; i++) {       pref[i][0] = pref[i][1] = dp[i][0] = dp[i][1] = 0;     }     if (b < a) {       a = n + 1 - a;       b = n + 1 - b;     }     dp[a][0] = 1;     for (int i = a; i < b; i++) pref[i][0] = 1;     for (int j = 1; j <= k; j++) {       for (int i = 1; i < b; i++) {         dp[i][j % 2] =             (pref[(b + i - 1) / 2][(j - 1) % 2] - dp[i][(j - 1) % 2] + MOD) % MOD;         pref[i][j % 2] = (pref[i - 1][j % 2] + dp[i][j % 2]) % MOD;       }     }     cout << pref[b - 1][k % 2] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char tab[100], znak;     int konik, insekt, dlugosc, skok;     cin >> dlugosc;     cin >> skok;     for (int i = 0; i < dlugosc; i++) {       cin >> znak;       tab[i] = znak;       if (znak ==  G ) konik = i;       if (znak ==  T ) insekt = i;     }     if (konik == insekt) {       cout <<  YES ;       return 0;     }     if (konik < insekt) {       while (konik <= dlugosc && konik <= insekt) {         konik += skok;         if (konik == insekt) {           cout <<  YES ;           return 0;         }         if (tab[konik] ==  # ) {           cout <<  NO ;           return 0;         }       }       cout <<  NO ;     } else {       while (konik >= 0 && konik >= insekt) {         konik -= skok;         if (konik == insekt) {           cout <<  YES ;           return 0;         }         if (tab[konik] ==  # ) {           cout <<  NO ;           return 0;         }       }       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ceiling(long long a, long long b) {     if (a % b != 0) {       return (a / b) + 1;     } else       return (a / b);   }   void solve() {     long long n, k;     cin >> n >> k;     long long a[n * k];     for (long long i = 0; i < n * k; i++) {       cin >> a[i];     }     sort(a, a + n * k);     long long cnt = 0;     long long cnt1 = 0;     long long i = n * k - 1 - (n / 2);     while (cnt1 < k and i >= 0) {       cnt1++;       cnt += a[i];       i -= (n / 2) + 1;     }     cout << cnt << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long tc;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   string substrs(string s, int i, int j) {     string a;     for (int h = i; h < j + 1; h++) {       a.push_back(s[h]);     }     return a;   }   int main() {     int T;     cin >> T;     for (int zz = 0; zz < T; zz++) {       string s, s1;       cin >> s;       vector<int> cnt[3];       for (int i = 0; i < s.length(); i++) {         if (islower(s[i])) {           s1.push_back( l );           cnt[0].push_back(i);         } else if (isupper(s[i])) {           s1.push_back( u );           cnt[1].push_back(i);         } else if (isdigit(s[i])) {           s1.push_back( d );           cnt[2].push_back(i);         }       }       int num = 0;       for (int i = 0; i < 3; i++)         if (!cnt[i].size()) num++;       if (num == 0) {         cout << s <<   n ;         continue;       } else if (num == 1) {         for (int i = 0; i < 3; i++) {           if (!cnt[i].size()) {             for (int j = 1; j < 3; j++) {               if (cnt[(i + j) % 3].size() != 1) {                 if (i == 0)                   s[cnt[(i + j) % 3][0]] =  a ;                 else if (i == 1)                   s[cnt[(i + j) % 3][0]] =  A ;                 else if (i == 2)                   s[cnt[(i + j) % 3][0]] =  1 ;                 break;               }             }             break;           }         }       } else if (num == 2) {         for (int i = 0; i < 3; i++) {           if (cnt[i].size()) {             if (i == 0) {               s[0] =  A ;               s[1] =  1 ;             } else if (i == 1) {               s[0] =  a ;               s[1] =  1 ;             } else if (i == 2) {               s[0] =  A ;               s[1] =  a ;             }             break;           }         }       }       cout << s <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[200005], sh[200005], sp[200005];   int main() {     long long i, j, k, n, m, p, q, t, cnt = 0, mn;     scanf( %lld , &n);     scanf( %lld , &k);     for (i = 0; i < n; i++) {       scanf( %lld , &arr[i]);       ;     }     sort(arr, arr + n);     for (i = 0; i < n; i++) {       cnt = 0;       while (1) {         sh[arr[i]]++;         if (sh[arr[i]] <= k) sp[arr[i]] += cnt;         if (!arr[i]) break;         arr[i] /= 2;         cnt++;       }     }     mn = sp[0];     for (i = 0; i <= 200005; i++) {       if (sh[i] >= k && sp[i] < mn) mn = sp[i];     }     cout << mn << endl;     return 0;   }