malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long, pair<long long, long long>>> pq;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       bool flag = true, cond = true;       long long n, i, j, x, y, ind, k, m, mn = INT_MAX, p = 0, mx = 0, diff, y1,                                           count = 0;       cin >> n;       vector<long long> a(n), b(n);       for (i = 0; i < n; i++) {         cin >> a[i];       }       map<long long, long long> mp;       for (j = 0; j < n; j++) {         cin >> b[j];         mp[b[j]]++;       }       vector<long long> c;       map<long long, long long>::iterator it;       for (i = 0; i < n; i++) {         it = mp.lower_bound(n - a[i]);         if (it == mp.end()) {           it = mp.begin();           c.push_back((a[i] + it->first) % n);           if (it->second == 1)             mp.erase(it->first);           else             mp[it->first]--;         } else {           c.push_back((a[i] + it->first) % n);           if (it->second == 1)             mp.erase(it->first);           else             mp[it->first]--;         }       }       for (int iz = 0; iz < c.size(); iz++) {         cout << c[iz] <<    ;       }       cout <<   n ;       ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[50005];   bool cmp(const string &a, const string &b) { return a + b < b + a; }   int main() {     int n, i;     cin >> n;     for (i = 0; i < n; i++) cin >> s[i];     sort(s, s + n, cmp);     string ans = accumulate(s, s + n, string());     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxs = 300 * 1000 + 5, Maxn = 300 * 1000 + 5;   int n, dp[Maxs];   string s, t;   long long ans;   vector<pair<int, string> > adj[Maxn];   void kmp() {     dp[0] = -1;     for (int i = 0; i < t.size(); i++) {       int pt = i;       while (dp[pt] != -1 && t[dp[pt]] != t[i]) pt = dp[pt];       dp[i + 1] = dp[pt] + 1;     }   }   double now;   void dfs(int v, int indt) {     for (auto u : adj[v]) {       int indt2 = indt;       for (int j = 0; j < u.second.size(); ++j) {         if (clock() - now == CLOCKS_PER_SEC * 0.990) {           cout << ans << endl;           exit(0);         }         if (indt2 == t.size()) ans++, indt2 = dp[indt2];         if (indt2 >= 0 && indt2 < t.size() && u.second[j] == t[indt2])           indt2++;         else if (indt2 != 0 && indt2 >= 0)           indt2 = dp[indt2], j--;       }       if (indt2 == t.size()) ans++, indt2 = dp[indt2];       dfs(u.first, indt2);     }   }   int main() {     now = clock();     cin >> n;     int par;     for (int i = 1; i < n; i++)       cin >> par >> s, par--, adj[par].push_back(make_pair(i, s));     cin >> s;     t = s;     kmp();     dfs(0, 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int calc(long long n, long long k, long long a1, long long a2, long long a3) {     long long sum;     if (a2 < a3) {       swap(a2, a3);     }     if (a1 < a2) {       swap(a1, a2);     }     if (a2 < a3) {       swap(a2, a3);     }     if (a1 < 0 || a2 < 0 || a3 < 0) {       return 0;     }     sum = a1 - a2 + a1 - a3;     if (sum > n - k) {       return 0;     }     if ((n - k - sum) % 3 == 0) {       return 1;     }     return 0;   }   int task() {     long long i, n, k, d1, d2, a1, a2, a3;     cin >> n;     ;     cin >> k;     ;     cin >> d1;     ;     cin >> d2;     ;     a1 = k + 2 * d1 + d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 - d1;       a3 = a2 - d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     a1 = k + 2 * d1 - d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 - d1;       a3 = a2 + d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     a1 = k - 2 * d1 + d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 + d1;       a3 = a2 - d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     a1 = k - 2 * d1 - d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 + d1;       a3 = a2 + d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     return 0;   }   int main(int argc, char const *argv[]) {     int i, t;     string yes( yes );     string no( no );     cin >> t;     ;     for (i = 0; i < t; i++) {       if (task()) {         cout << yes << endl;         ;       } else {         cout << no << endl;         ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, f[1000010], mn, rt, ans;   int cnt, head[1000010], to[2000010], nxt[2000010];   void add(int x, int y) {     cnt++;     to[cnt] = y;     nxt[cnt] = head[x];     head[x] = cnt;   }   void dfs(int x, int fa, int now) {     f[x] = now;     for (int i = head[x]; i; i = nxt[i]) {       int y = to[i];       if (y == fa) {         continue;       }       dfs(y, x, min(now, y));     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     q--;     scanf( %d , &rt);     scanf( %d , &rt);     rt = rt % n + 1;     mn = rt;     dfs(rt, 0, rt);     while (q--) {       int op, x;       scanf( %d%d , &op, &x);       x = (x + ans) % n + 1;       if (op == 1) {         mn = min(mn, f[x]);       } else {         ans = min(mn, f[x]);         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, a, b;     cin >> n >> a >> b;     for (long long i = 0; i <= n; ++i) {       if (a * i > n) {         break;       }       long long cur = a * i;       if (n - cur >= 0 && (n - cur) % b == 0) {         cout <<  YES n ;         cout << i <<     << (n - cur) / b;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   long long r, g, b, k = 0;   long long a[4];   int main() {     cin >> t;     while (t--) {       cin >> a[1] >> a[2] >> a[3];       sort(a + 1, a + 1 + 3);       k = a[1] + a[2];       if (a[3] >= k)         cout << k << endl;       else {         k -= a[3];         r = min(a[1], k / 2) + a[3];         cout << r << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 * 1000 + 50;   vector<int> v[maxN];   int cnt;   bool mark[maxN];   void dfs(int s) {     mark[s] = 1;     cnt++;     for (int i = 0; i < v[s].size(); i++)       if (mark[v[s][i]] == 0) dfs(v[s][i]);   }   int main() {     int n, m, k, sum = 0, com = 0;     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (mark[i] == 0) {         com++;         cnt = 0;         dfs(i);         sum += min(k, cnt);       }     if (k == 1)       cout << max(0, com - 2) << endl;     else       cout << max(0, com - 1 - (sum / 2)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     int i;     cin >> x;     for (i = 0; x[i]; i++) {       if (i == 0 && x[i] == 57)         x[i] = x[i];       else if (x[i] >= 53)         x[i] = (57 - x[i]) + 48;       cout << x[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, n, k, tot, ans, sum;   int a[100005];   string st;   char ch;   int main() {     ios::sync_with_stdio(false);     cin >> n;     if (n == 2) {       cout << 3 << endl;       return 0;     }     if (n == 3) {       cout << 5 << endl;       return 0;     }     for (i = 1; i <= 100; i++) {       if (i % 2 == 0) continue;       j = (i * i + 1) / 2;       if (j >= n) break;     }     cout << i << endl;   }
#include <bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef pair <int, int> ii;      const int Maxn = 200005;   const ll Inf = 1000000000000000000ll;      int T;   int n;   vector <int> neigh[Maxn];   int a[Maxn];   int mylvl[Maxn];   vector <ii> L[Maxn];   int mxlvl;   ll best[Maxn];   ll dp[Maxn];      void Traverse(int v, int p, int lvl)   {    mylvl[v] = lvl;    L[lvl].push_back(ii(a[v], v));    mxlvl = max(mxlvl, lvl);    for (int i = 0; i < neigh[v].size(); i++) {     int u = neigh[v][i];     if (u == p) continue;     Traverse(u, v, lvl + 1);    }   }      int main()   {    scanf( %d , &T);    while (T--) {     scanf( %d , &n);     for (int i = 1; i <= n; i++)      neigh[i].clear();     for (int i = 2; i <= n; i++) {      int a; scanf( %d , &a);      neigh[i].push_back(a);      neigh[a].push_back(i);     }     for (int i = 2; i <= n; i++)      scanf( %d , &a[i]);     mxlvl = 0;     Traverse(1, 0, 0);     for (int i = mxlvl; i >= 0; i--) {      sort(L[i].begin(), L[i].end());      ll all = -Inf, notall = -Inf;      for (int j = 0; j < L[i].size(); j++) {       int v = L[i][j].second;       best[v] = 0;       for (int z = 0; z < neigh[v].size(); z++) {        int u = neigh[v][z];        if (mylvl[u] <= mylvl[v]) continue;        best[v] = max(best[v], dp[u]);       }       all = max(all, best[v] - L[i][j].first);       notall = max(notall, -ll(L[i][j].first));       dp[v] = max(all + L[i][j].first, notall + L[i][j].first + best[v]);      }      all = -Inf, notall = -Inf;      for (int j = int(L[i].size()) - 1; j >= 0; j--) {       int v = L[i][j].second;       dp[v] = max(dp[v], max(all - L[i][j].first, notall - L[i][j].first + best[v]));       all = max(all, best[v] + L[i][j].first);       notall = max(notall, ll(L[i][j].first));      }      L[i].clear();     }     printf( %I64d n , dp[1]);    }       return 0;   }
#include <bits/stdc++.h>   const long long md = (1e9 + 7);   const long long fakmd = 998244353;   using namespace std;   long long n, m;   pair<long long, long long> a[100100];   long long ans[100100];   int32_t main() {     cin >> n >> m;     long long it = 1;     long long sum = 0;     for (long long i = 1; i <= m; i++) {       cin >> a[i].first;       sum += a[i].first;       a[i].second = i;     }     if (sum < n) {       return cout << -1, 0;     }     for (long long i = 1; i <= m; i++) {       sum -= a[i].first;       long long ln = max((n - it + 1) - sum, 1ll);       if (ln > a[i].first || it + a[i].first - 1 > n) {         return cout << -1, 0;       }       ans[a[i].second] = it;       it += ln;     }     if (it < n) {       cout << -1;     } else {       for (long long i = 1; i <= m; i++) {         cout << ans[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long k, d, t;     cin >> k >> d >> t;     if (k % d == 0) {       printf( %lld n , t);     } else {       unsigned long long num = k / d;       unsigned long long num1 = k % d;       unsigned long long t1 = (num + 1) * d;       double onezhi = num * d + (d - num1) * 0.5 + num1;       unsigned long long ans1 = t / onezhi;       double t2 = t - onezhi * ans1;       double ans;       if (t2 <= k) {         ans = t2 + t1 * ans1;       } else {         ans = t1 * ans1 + k + (t2 - k) * 2;       }       printf( %.9lf n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e3 + 51, MOD = 998244353;   int n, res;   int p[MAXN][MAXN], fact[MAXN], finv[MAXN];   inline int read() {     register int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   inline int qpow(int base, int exponent) {     int res = 1;     while (exponent) {       if (exponent & 1) {         res = (long long int)res * base % MOD;       }       base = (long long int)base * base % MOD, exponent >>= 1;     }     return res;   }   inline void setup(int cnt) {     fact[0] = fact[1] = finv[0] = 1;     for (register int i = 0; i <= cnt; i++) {       p[i][0] = 1;     }     for (register int i = 1; i <= cnt; i++) {       for (register int j = 1; j <= i; j++) {         p[i][j] = ((long long int)(i - j) * p[i - 1][j - 1] % MOD +                    (long long int)(j + 1) * p[i - 1][j] % MOD) %                   MOD;       }     }     for (register int i = 2; i <= cnt; i++) {       fact[i] = (long long int)fact[i - 1] * i % MOD;     }     finv[cnt] = qpow(fact[cnt], MOD - 2);     for (register int i = cnt - 1; i; i--) {       finv[i] = (long long int)finv[i + 1] * (i + 1) % MOD;     }   }   inline int binom(int m, int n) {     return (long long int)fact[m] * finv[n] % MOD * finv[m - n] % MOD;   }   int main() {     setup(n = read());     for (register int k = 0; k < n; k++) {       res = 0;       for (register int i = max(k, 1); i <= n; i++) {         res = (res +                (long long int)binom(n, i) * p[i][k] % MOD * fact[n - i] % MOD) %               MOD;       }       printf( %d  , res);     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int pgcd(int a, int b) {     if (b % a == 0) return a;     pgcd(b % a, a);   }   int main() {     int o = 0, gcd, az[1001], t[5000], j, k = 0, m, x, y, i, a, b, n;     cin >> a >> b >> n;     gcd = pgcd(a, b);     for (i = 1; i * i <= gcd; i++) {       if (gcd % i == 0) {         t[k] = i;         k++;         t[k] = gcd / i;         k++;       }     }     for (i = 0; i < n; i++) {       m = -1;       cin >> x >> y;       for (j = 0; j < k; j++) {         if (t[j] <= y && t[j] >= x) m = max(m, t[j]);       }       cout << m << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int x, y, x2, y2;   int v;   vector<int> mass1, mass2;   int check1(int ind) {     if (ind == -1 || ind == (int)mass1.size()) {       return 1e9;     }     return abs(mass1[ind] - x) + abs(x2 - mass1[ind]) + (y2 - y + v - 1) / v;   }   int check2(int ind) {     if (ind == -1 || ind == (int)mass2.size()) {       return 1e9;     }     return abs(mass2[ind] - x) + abs(x2 - mass2[ind]) + (y2 - y);   }   signed main() {     int n, m, c1, c2;     cin >> n >> m >> c1 >> c2 >> v;     mass1.resize(c2);     mass2.resize(c1);     for (int i = 0; i < c1; i++) {       cin >> mass2[i];     }     for (int i = 0; i < c2; i++) {       cin >> mass1[i];     }     int q;     cin >> q;     while (q--) {       cin >> x >> y >> x2 >> y2;       swap(x, y);       swap(x2, y2);       if (x > x2) {         swap(x, x2);       }       if (y > y2) {         swap(y, y2);       }       int ans = 1e9;       if (y == y2) {         ans = x2 - x;       }       int l1 = lower_bound(mass1.begin(), mass1.end(), x) - mass1.begin();       ans = min(ans, check1(l1));       ans = min(ans, check1(l1 - 1));       l1 = lower_bound(mass1.begin(), mass1.end(), x2) - mass1.begin();       ans = min(ans, check1(l1));       ans = min(ans, check1(l1 - 1));       l1 = lower_bound(mass2.begin(), mass2.end(), x) - mass2.begin();       ans = min(ans, check2(l1));       ans = min(ans, check2(l1 - 1));       l1 = lower_bound(mass2.begin(), mass2.end(), x2) - mass2.begin();       ans = min(ans, check2(l1));       ans = min(ans, check2(l1 - 1));       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int N = 2000 + 10;   int n;   int pa, pb, p, q;   int cp[N][N];   int strong[N];   int f[N];   void add(int &t, int s) {     t += s;     if (t >= MOD) t -= MOD;   }   void mul(int &t, int s) { t = (long long)t * s % MOD; }   int pow(int s, int n) {     long long ret = 1;     while (n)       if (n % 2)         ret = ret * s % MOD, n--;       else         s = (long long)s * s % MOD, n >>= 1;     return ret;   }   int inv(int s) { return pow(s, MOD - 2); }   int main() {     cin >> n >> pa >> pb;     p = (long long)pa * inv(pb) % MOD;     q = (MOD - p + 1) % MOD;     f[0] = 0;     f[1] = 0;     cp[0][0] = 1;     for (int i = 1; i <= n; i++) {       cp[i][0] = 1;       for (int j = 1; j <= i; j++) {         cp[i][j] = ((long long)cp[i - 1][j - 1] * pow(q, i - j) +                     (long long)cp[i - 1][j] * pow(p, j)) %                    MOD;       }     }     strong[1] = 1;     for (int i = 2; i <= n; i++) {       int res = 0;       for (int j = 1; j < i; j++) {         int tmp = strong[j];         mul(tmp, cp[i][j]);         add(res, tmp);       }       strong[i] = (1 - res + MOD) % MOD;     }     for (int s = 2; s <= n; s++) {       int res = 0;       for (int i = 1; i < s; i++) {         int cur = 1;         mul(cur, strong[i]);         mul(cur, cp[s][i]);         int games = 0;         add(games, i * (s - i));         add(games, i * (i - 1) / 2);         add(games, f[i]);         add(games, f[s - i]);         mul(cur, games);         add(res, cur);       }       int coeff = 1;       mul(coeff, strong[s]);       mul(coeff, cp[s][s]);       int tmp = coeff;       mul(tmp, s * (s - 1) / 2);       add(res, tmp);       coeff = (1 + MOD - coeff) % MOD;       mul(res, inv(coeff));       f[s] = res;     }     cout << f[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   vector<T>& operator--(vector<T>& v) {     for (auto& i : v) --i;     return v;   }   template <typename T>   vector<T>& operator++(vector<T>& v) {     for (auto& i : v) ++i;     return v;   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> v) {     for (auto& i : v) os << i <<    ;     return os;   }   template <typename T, typename U>   pair<T, U>& operator--(pair<T, U>& p) {     --p.first;     --p.second;     return p;   }   template <typename T, typename U>   pair<T, U>& operator++(pair<T, U>& p) {     ++p.first;     ++p.second;     return p;   }   template <typename T, typename U>   istream& operator>>(istream& is, pair<T, U>& p) {     is >> p.first >> p.second;     return is;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, pair<T, U> p) {     os << p.first <<     << p.second;     return os;   }   template <typename T, typename U>   pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {     return mp(a.first - b.first, a.second - b.second);   }   template <typename T, typename U>   pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {     return mp(a.first + b.first, a.second + b.second);   }   template <typename T, typename U>   void umin(T& a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   void umax(T& a, U b) {     if (a < b) a = b;   }   bool prime(long long n) {     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long fact(long long x) {     long long ans = 1;     for (long long i = 2; i <= x; i++) ans *= i;     return ans;   }   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     cin >> a;     if (n == 1) {       cout << 0 << endl;       return;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long cnt = 0;       if ((i == 0 && a[i + 1] == 2) || (i == n - 1 && a[i - 1] == 999) ||           (i > 0 && i + 1 < n && a[i + 1] - a[i - 1] == 2)) {         while (i < n) {           if (i == 0) {             if (a[i + 1] == 2) {               cnt++;               i++;             } else {               break;             }           } else if (i == n - 1) {             if (a[i - 1] == 999) {               cnt++;               i++;             } else {               break;             }           } else {             if (a[i + 1] - a[i - 1] == 2) {               cnt++;               i++;             } else {               break;             }           }         }         i--;         ans = max(ans, cnt);       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }
#include <bits/stdc++.h>   using namespace std;   long long Tc, a, b, n, m;   int main() {     long long ans = 0;     cin >> n >> m;     if (m % n != 0) {       cout <<  -1 n ;       return 0;     }     m /= n;     while (m % 2 == 0) {       m /= 2;       ans++;     }     while (m % 3 == 0) {       m /= 3;       ans++;     }     (m > 1) ? cout <<  -1  : cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)2e5 + 5;   const int maxM = (int)2e5 + 5;   inline int readInt() {     char c;     int tmp = 0, x = 1;     c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) x = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       tmp = tmp * 10 + c -  0 ;       c = getchar();     }     return tmp * x;   }   vector<int> g[maxN];   void addEdge(int u, int v) {     g[u].push_back(v);     g[v].push_back(u);   }   int Father[maxN], Ranking[maxN];   void init(int n) {     for (int i = 1; i <= n; i++) Father[i] = i;   }   int getFather(int x) {     return x == Father[x] ? x : Father[x] = getFather(Father[x]);   }   void mergeUnion(int u, int v) {     int Fu = getFather(u), Fv = getFather(v);     if (Fu == Fv) return;     if (Ranking[Fu] > Ranking[Fv]) swap(Fu, Fv);     Father[Fu] = Fv;     Ranking[Fv] += Ranking[Fu];   }   int n, m, s[maxN], ans[maxM];   pair<int, int> rec[maxM];   int dep[maxN], Sum[maxN];   void dfs(int v, int fa) {     dep[v] = (fa == -1 ? 1 : dep[fa] + 1);     Sum[v] = s[v];     for (int i = 0; i < (int)g[v].size(); i++) {       if (g[v][i] != fa) dfs(g[v][i], v), Sum[v] += Sum[g[v][i]];     }   }   int main() {     n = readInt();     int tot = 0;     for (int i = 1; i <= n; i++) s[i] = readInt(), tot += s[i];     if (tot) {       printf( Impossible n );       exit(0);     } else       printf( Possible n );     m = readInt();     init(n);     int u, v;     for (int i = 1; i <= m; i++) {       u = readInt(), v = readInt();       if (getFather(u) != getFather(v)) {         addEdge(u, v);         mergeUnion(u, v);         rec[i] = make_pair(u, v);       }     }     dfs(1, -1);     for (int i = 1; i <= m; i++) {       if (!rec[i].first && !rec[i].second) continue;       if (dep[rec[i].first] < dep[rec[i].second])         ans[i] = Sum[rec[i].second];       else         ans[i] = -Sum[rec[i].first];     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100000;   int a[MaxN];   int color[MaxN];   bool f = true;   int n;   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     while (n % k) {       a[n + 1] = a[n];       n++;     }     int ans = 0;     for (int i = 0; i < n / k; ++i) {       ans += (2 * (a[k * i + 1] - 1));     }     cout << ans;   }