malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   signed main() {     unsigned long long a, b;     cin >> a >> b;     if (a < b || (a % 2 != b % 2)) {       cout << -1 << endl;       return 0;     }     unsigned long long x = (a - b) / 2;     unsigned long long y = x + b;     cout << x <<     << y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long OO = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double pi = 3.14159265359;   void skrrrt() { ios_base::sync_with_stdio(0), cin.tie(0); }   const int N = 2009;   int n, d;   long long mem[N][N][2][2];   string a, b;   long long solve(int ind, int sum, int bgra, int smlrb) {     if (ind == a.size()) return (sum == 0);     long long &ret = mem[ind][sum][bgra][smlrb];     if (~ret) return ret;     ret = 0;     for (int i =  0 ; i <=  9 ; i++) {       if ((ind % 2) ^ ((i -  0 ) == d)) continue;       if (!bgra && i < a[ind]) continue;       if (!smlrb && i > b[ind]) continue;       ret = (ret + solve(ind + 1, (sum * 10 + (i -  0 )) % n,                          bgra || (i > a[ind]), smlrb || (i < b[ind]))) %             mod;     }     return ret;   }   int main() {     skrrrt();     cin >> n >> d;     cin >> a >> b;     memset(mem, -1, sizeof mem);     cout << solve(0, 0, 0, 0);   }
#include <bits/stdc++.h>   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   constexpr long long MAX = 5100000;   constexpr long long INF = 1LL << 60;   constexpr int inf = 1 << 28;   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<long long> a(n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     vector<pair<long long, long long>> vp;     for (int i = 0; i < n; i++) {       vp.emplace_back(a[i], 1);       while (vp.size() >= 2) {         auto s = vp.back();         vp.pop_back();         auto f = vp.back();         vp.pop_back();         if (f.second * (f.first + s.first) < f.first * (f.second + s.second)) {           vp.emplace_back(f.first + s.first, f.second + s.second);         } else {           vp.emplace_back(f);           vp.emplace_back(s);           break;         }       }     }     for (int i = 0; i < vp.size(); i++) {       auto p = vp[i];       for (int j = 0; j < p.second; j++) {         printf( %.12f n , (double)p.first / p.second);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2001], b[2001], n, k, len = 0, ans = 0, res = 0;   void solve() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       if (a[i] + k <= 5) {         len++;       }     }     ans = (len / 3);     printf( %d , ans);   }   int main() { solve(); }
#include <bits/stdc++.h>   int n, g, c[6010];   bool p(int x) {     if (x == 1) return 0;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   int main() {     scanf( %d , &n);     g = n * (n + 1) / 2;     if ((g & 1) && (n > 2) && !p(g - 2)) c[3] = 2, g -= 3;     for (int i = 0; i < n + 1; i++)       if (!c[i] && p(i) && p(g - i)) {         c[i] = 1;         break;       }     for (int i = 0; i < n; i++) printf( %d  , c[i + 1] + 1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n + 1];     int c;     for (int i = 0; i <= n; i++) a[i] = i;     if (k == n)       cout << -1;     else {       for (int i = 1; i < (n - k); i++) {         c = a[i];         a[i] = a[i + 1];         a[i + 1] = c;       }       for (int i = 1; i <= n; i++) cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   map<string, int> mp1[maxn], mp2[maxn];   vector<int> ans;   char getA(string a, string b) {     int c[30];     for (int i = 0; i < 26; i++) c[i] = 0;     for (int i = 0; i < a.size(); i++) c[a[i] -  a ]++;     for (int i = 0; i < b.size(); i++) c[b[i] -  a ]--;     for (int i = 0; i < 26; i++)       if (c[i] > 0) return i +  a ;   }   string solve(int n) {     cout <<  ? 1   << n << endl;     for (int i = 0; i < n * (n + 1) / 2; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       mp1[s.size()][s]++;     }     cout <<  ? 2   << n << endl;     for (int i = 0; i < n * (n - 1) / 2; i++) {       string s;       cin >> s;       sort(s.begin(), s.end());       mp2[s.size()][s]++;     }     for (int i = 1; i <= n; i++) {       for (auto p : mp2[i]) mp1[i][p.first] -= mp2[i][p.first];       for (auto p : mp1[i]) {         if (p.second > 0) {           string new1 =   ;           for (int j = 0; j < ans.size(); j++) new1 += ans[j];           ans.push_back(getA(p.first, new1));         }       }     }     string new1 =   ;     for (int j = 0; j < ans.size(); j++) new1 += ans[j];     return new1;   }   int ori[26][105];   int main() {     int n;     cin >> n;     if (n == 1) {       cout <<  ? 1 1  << endl;       string s;       cin >> s;       cout <<  !   << s << endl;     } else if (n == 2) {       cout <<  ? 1 1  << endl;       string s1, s2;       cin >> s1;       cout <<  ? 2 2  << endl;       cin >> s2;       cout <<  !   << s1 << s2 << endl;     } else {       string ramjas = solve((n + 1) / 2);       cout <<  ? 1   << n << endl;       for (int i = 0; i < n * (n + 1) / 2; i++) {         string s;         cin >> s;         for (int j = 0; j < s.size(); j++) ori[s[j] -  a ][s.size()]++;       }       string ramjas2 =   ;       for (int i = 1; i <= n / 2; i++) {         for (int j = 0; j < 26; j++) {           int num = ori[j][1] - (ori[j][i + 1] - ori[j][i]);           for (int k = 0; k < i; k++) {             if (ramjas[k] -  a  == j) num--;           }           for (int k = 0; k < ramjas2.size(); k++) {             if (ramjas2[k] -  a  == j) num--;           }           if (num > 0) {             ramjas2 += ( a  + j);             break;           }         }       }       for (int i = 0; i < ramjas2.size(); i++)         ramjas += ramjas2[ramjas2.size() - 1 - i];       cout <<  !   << ramjas << endl;     }   }
#include <bits/stdc++.h>   int main() {     int t;     std::cin >> t;     while (t--) {       std::set<int> all;       int n;       std::cin >> n;       while (n--) {         int tmp;         std::cin >> tmp;         while ((tmp & 1) == 0) {           all.insert(tmp);           tmp >>= 1;         }       }       printf( %d n , (int)all.size());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, q, inc[101];   double a[101], mi = 1000000007LL, ma;   set<vector<int> > S;   set<vector<int> >::iterator it;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> q;     int m = n / k;     for (int i = 0; i < q; i++) {       vector<int> v;       for (int j = 0; j < m; j++) {         int x;         cin >> x;         v.push_back(x);         inc[v[j] - 1] = 1;       }       sort(v.begin(), v.end());       S.insert(v);     }     for (it = S.begin(); it != S.end(); it++) {       vector<int> v = *it;       double s = 0;       for (int i = 0; i < v.size(); i++) s += a[v[i] - 1];       s /= v.size();       mi = min(mi, s);       ma = max(ma, s);     }     vector<double> v;     for (int i = 0; i < n; i++)       if (!inc[i]) v.push_back(a[i]);     if (v.size() >= m && k > S.size()) {       sort(v.begin(), v.end());       double s = 0;       for (int i = 0; i < m; i++) s += v[i];       mi = min(mi, s / m);       s = 0;       for (int i = 0; i < m; i++) s += v[v.size() - 1 - i];       ma = max(ma, s / m);     }     cout << setprecision(9) << mi <<     << ma;   }
#include <bits/stdc++.h>   void merging(long long arr[], long long start, long long mid, long long end);   void sort(long long arr[], long long start, long long end) {     long long mid;     if (end - start + 1 > 1) {       mid = (start + end) / 2;       sort(arr, start, mid);       sort(arr, mid + 1, end);       merging(arr, start, mid, end);     }   }   void merging(long long arr[], long long start, long long mid, long long end) {     long long len1, len2, i, j, k;     len1 = mid - start + 1;     len2 = end - mid - 1 + 1;     long long right[len2], left[len1];     for (i = 0; i < len1; i++) {       left[i] = arr[i + start];     }     for (i = 0; i < len2; i++) {       right[i] = arr[i + mid + 1];     }     i = 0;     j = 0;     k = start;     while ((i < len1) && (j < len2)) {       if (left[i] > right[j]) {         arr[k] = right[j];         j++;         k++;       } else {         arr[k] = left[i];         i++;         k++;       }     }     if (i == len1) {       while (j < len2) {         arr[k] = right[j];         j++;         k++;       }     } else {       while (i < len1) {         arr[k] = left[i];         i++;         k++;       }     }   }   long long gcd(long long a, long long b) {     if (a == b)       return a;     else if (a == 0)       return b;     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     long long n;     scanf( %I64lld , &n);     long long a[200005];     for (int i = 0; i < n; i++) {       scanf( %I64lld , &a[i]);     }     sort(a, 0, n - 1);     long long cor[200005], l = 0;     for (long long int i = 0; i < n - 1; i++) {       if (a[i] != a[i + 1]) {         cor[l] = a[i];         l++;       }     }     {       cor[l] = a[n - 1];       l++;     }     long long min[200005];     for (long long int i = 0; i < l - 1; i++) {       min[i] = cor[i + 1] - cor[i];     }     long long mini = cor[1] - cor[0];     for (int i = 0; i < l - 1; i++) {       mini = gcd(min[i], mini);     }     long long nop = 0;     for (long long int i = 0; i < n; i++) {       nop = nop + (a[n - 1] - a[i]) / mini;     }     printf( %I64lld %I64lld n , nop, mini);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   int n, k;   int in[222];   int main() {     int i, j, tcc, tc = 1 << 28;     for (tcc = 0; tcc < tc; tcc++) {       n = getint(), k = getint();       for (i = 0; i < n; i++) in[i] = getint();       int s, t;       int res = in[0];       for (s = 0; s < n; s++)         for (t = s; t < n; t++) {           int sum = 0;           vector<int> with;           for (i = s; i <= t; i++) sum += in[i], with.push_back(in[i]);           vector<int> other;           for (i = 0; i < s; i++) other.push_back(in[i]);           for (i = t + 1; i < n; i++) other.push_back(in[i]);           sort(other.begin(), other.end(), greater<int>());           sort(with.begin(), with.end());           res = max(res, sum);           int lm = min(other.size(), with.size());           lm = min(lm, k);           for (i = 0; i < lm; i++) {             sum += other[i];             sum -= with[i];             res = max(res, sum);           }         }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long al;     cin >> al;     while (al--) {       long long b, c;       cin >> b >> c;       if ((abs(b - c)) % 10 == 0)         cout << abs(b - c) / 10 <<   n ;       else {         b = abs(b - c);         cout << b / 10 + 1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int pos[100010];   int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   bool check(int i, int j) {     int x = (i - 1) / m + 1, y = (i - 1) % m + 1;     int x2 = (j - 1) / m + 1, y2 = (j - 1) % m + 1;     for (int k = 0; k < 4; k++)       if (x + dx[k] == x2 && y + dy[k] == y2) return true;     return false;   }   bool dfs(int i) {     if (i == n * m + 1) return true;     int x = (i - 1) / m + 1, y = (i - 1) % m + 1;     for (int j = i; j <= n * m; j++) {       swap(pos[i], pos[j]);       if (x != 1 && check(pos[i], pos[(x - 2) * m + y])) continue;       if (y != 1 && check(pos[i], pos[(x - 1) * m + y - 1])) continue;       if (dfs(i + 1)) return true;       swap(pos[i], pos[j]);     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) pos[(i - 1) * m + j] = (i - 1) * m + j;     if (!dfs(1)) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) printf( %d  , pos[(i - 1) * m + j]);       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   const long long llinfinity = 9223372036854775807LL;   const long long llminusinfinity = -9223372036854775808LL;   const int intinfinity = 2147483647;   const int intminusinfinity = -2147483648;   using namespace std;   const int maxn = 1e5 + 5;   int a[maxn], n;   long long ans;   int main(int argc, char *argv[]) {     long long tmp = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     ans = 0;     for (int i = 0; i < n; ++i) {       tmp = 0;       if (i == 0) {         tmp = a[i];         tmp *= (n - a[i] + 1);       } else {         if (a[i] > a[i - 1]) {           tmp = a[i] - a[i - 1];           tmp *= n - a[i] + 1;         } else {           tmp = a[i];           tmp *= a[i - 1] - a[i];         }       }       ans += tmp;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int n, k, ps[N], mx[N], cnt[N], a[N];   long long ans;   int getNeed(int p, int m) {     int x = (((p - m) % k) + k) % k;     return cnt[((k - x) + k) % k];   }   void solve(int l, int r) {     if (r - l <= 1) return;     int mid = (l + r) / 2;     ps[mid - 1] = a[mid - 1] % k, mx[mid - 1] = a[mid - 1];     for (int i = mid - 2; i >= l; i--)       ps[i] = (ps[i + 1] + a[i]) % k, mx[i] = max(mx[i + 1], a[i]);     ps[mid] = a[mid] % k, mx[mid] = a[mid];     for (int i = mid + 1; i < r; i++)       ps[i] = (ps[i - 1] + a[i]) % k, mx[i] = max(mx[i - 1], a[i]);     for (int i = mid - 1; i >= l; i--) cnt[ps[i]]++;     int rn = l;     for (int i = r - 1; i >= mid; i--) {       if (mx[mid - 1] >= mx[i]) break;       while (mx[rn] >= mx[i]) cnt[ps[rn]]--, rn++;       ans += getNeed(ps[i], mx[i]);     }     for (int i = mid - 1; i >= l; i--) cnt[ps[i]] = 0;     rn = r - 1;     for (int i = mid; i < r; i++) cnt[ps[i]]++;     for (int i = l; i < mid; i++) {       if (mx[i] < mx[mid]) break;       while (mx[rn] > mx[i]) cnt[ps[rn]]--, rn--;       ans += getNeed(ps[i], mx[i]);     }     for (int i = mid; i < r; i++) cnt[ps[i]] = 0;     solve(l, mid), solve(mid, r);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     solve(0, n);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   int n, l, t;   vector<int> a;   long double ans = 0;   inline int getCount(int ll, int rr) {     if (rr < l) {       ll = lower_bound((a).begin(), (a).end(), ll) - a.begin();       rr = upper_bound((a).begin(), (a).end(), rr) - a.begin();       return rr - ll;     }     return getCount(ll, l - 1) + getCount(0, rr - l);   }   int main() {     assert(scanf( %d%d%d , &n, &l, &t));     a.resize(n);     for (int i = 0; i < n; i++) assert(scanf( %d , &a[i]));     t *= 2;     for (int i = 0; i < n; i++) ans += (t / l) * ((n - 1) / 2.0);     t %= l;     for (int i = 0; i < n; i++) ans += (getCount(a[i], a[i] + t) - 1) / 2.0;     cout.precision(20);     cout << fixed << ans / 2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 2;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       if (tmp % 2 == 0) {         ans = 3 - ans;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[20][20];   int i, j, k = 0;   string s =  WBWBWBWB , s1 =  BWBWBWBW , z[20];   int main() {     for (i = 1; i <= 8; i++) {       cin >> z[i];     }     for (i = 1; i <= 8; i++) {       if (z[i] != s && z[i] != s1) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void gethas(string s, int &has0, int &hasa, int &hasA) {     int n = int(s.size());     has0 = 0;     hasa = 0;     hasA = 0;     for (int i = 0; i < n; i++) {       char c = s[i];       has0 = has0 or ( 0  <= c and c <=  9 );       hasa = hasa or ( a  <= c and c <=  z );       hasA = hasA or ( A  <= c and c <=  Z );     }   }   bool valid(string s) {     int has0, hasa, hasA;     gethas(s, has0, hasa, hasA);     return has0 and hasa and hasA;   }   bool check(string s) {     if (valid(s)) {       cout << s << endl;       return true;     }     return false;   }   int cases;   int main() {     cin >> cases;     for (int cas = 0; cas < cases; cas++) {       string s;       cin >> s;       if (check(s)) continue;       int n = int(s.size());       int has0, hasa, hasA;       gethas(s, has0, hasa, hasA);       if (has0 + hasa + hasA == 2) {         for (int i = 0; i < n; i++) {           if (check(s.substr(0, i) +  0  + s.substr(i + 1, n - i))) break;           if (check(s.substr(0, i) +  a  + s.substr(i + 1, n - i))) break;           if (check(s.substr(0, i) +  A  + s.substr(i + 1, n - i))) break;         }         continue;       }       for (int i = 0; i < n - 1; i++) {         if (check(s.substr(0, i) +  0a  + s.substr(i + 2, n - i - 1))) break;         if (check(s.substr(0, i) +  0A  + s.substr(i + 2, n - i - 1))) break;         if (check(s.substr(0, i) +  aA  + s.substr(i + 2, n - i - 1))) break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000009;   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m, k;     cin >> n >> m >> k;     long long start = 0;     long long end = n;     long long ans = 1e12;     while (start <= end) {       long long middle = start + (end - start) / 2;       long long spaceLeft = n - middle * k;       long long questionsLeft = m - middle * k;       long long questionsCanBeFitted = spaceLeft / k * (k - 1) + spaceLeft % k;       if (questionsCanBeFitted >= questionsLeft) {         end = middle - 1;         ans = (k * (pow(2, middle + 1, MOD) - 2 + MOD) % MOD + (m - middle * k)) %               MOD;       } else         start = middle + 1;     }     cout << ans % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1007;   long long lcp[MAXN][MAXN];   string s;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     long long l = lcp[a.second][b.second];     long long al = a.second - a.first + 1;     long long bl = b.second - b.first + 1;     l = min(l, al);     l = min(l, bl);     if (al == l && bl == l)       return 0;     else if (al == l)       return 1;     else if (bl == l)       return 0;     else       return s[a.second - l] < s[b.second - l];   }   vector<pair<long long, long long>> subs;   long long n, m, k;   long long dp[2][MAXN];   long long add(long long a, long long b) {     return min(a + b, (long long)2e18 + 100);   }   long long f(long long num) {     long long l = subs[num].first;     long long r = subs[num].second;     long long len = r - l + 1;     auto lim = subs[num];     fill(dp[0], dp[0] + n + 1, 0);     dp[0][0] = 1;     for (long long c = 1; c <= m; ++c) {       long long* pdp = dp[c & 1 ^ 1];       long long* cdp = dp[c & 1];       fill(cdp, cdp + n + 1, 0);       for (long long i = 1; i <= n; ++i) pdp[i] = add(pdp[i], pdp[i - 1]);       for (long long i = 1; i <= n; ++i) {         long long first = min(lcp[i][r], len);         if (first == i)           cdp[i] = (c == 1 && first == len);         else if (first == len)           cdp[i] = pdp[i - max(1ll, first)];         else if (s[r - first] < s[i - first])           cdp[i] = pdp[i - first - 1];       }     }     return dp[m & 1][n];   }   void solve() {     cin >> n >> m >> k;     cin >> s;     s +=  # ;     reverse(s.begin(), s.end());     for (long long i = 0; i <= n; ++i)       for (long long j = 0; j <= n; ++j)         if (i && j) lcp[i][j] = (s[i] == s[j] ? lcp[i - 1][j - 1] + 1 : 0);     for (long long i = 1; i <= n; ++i)       for (long long j = i; j <= n; ++j) subs.push_back({i, j});     sort(subs.begin(), subs.end(), cmp);     reverse(subs.begin(), subs.end());     long long l = -1, r = subs.size();     while (r - l > 1) {       long long m = (l + r) / 2;       if (f(m) >= k)         r = m;       else         l = m;     }     auto p = subs[r];     for (long long i = p.second; i >= p.first; --i) cout << s[i];     cout <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = std::numeric_limits<int>::max() / 3;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   int dp[6000][6000];   long long sum[1000000];   long long min(long long a, long long b) { return a < b ? a : b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     vector<long long> a;     for (int i = 0, t; i < n; ++i) {       cin >> t;       a.push_back(t);     }     sort(a.begin(), a.end());     int sz = n / k;     int A = (n % k);     int B = k - A;     sum[0] = 0;     for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i] - a[i - 1];     for (int i = 0; i <= A; ++i)       for (int j = 0; j <= B; ++j) dp[i][j] = 2e9 + 1;     dp[0][0] = 0;     for (int i = 0; i <= A; ++i) {       for (int j = 0; j <= B; ++j) {         int x = (i + j) * sz + i;         if (i < A) {           long long t = dp[i][j] + sum[x + sz] - sum[x];           dp[i + 1][j] = min(dp[i + 1][j] * 1LL, t);         }         if (j < B) {           long long t = dp[i][j] + sum[x + sz - 1] - sum[x];           dp[i][j + 1] = min(dp[i][j + 1] * 1LL, t);         }       }     }     cout << dp[A][B] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int a[maxn], n, k;   long long sum;   long long judge1(int m) {     long long ans = 0;     for (int i = 1; a[i] < m && i <= n; i++) {       ans += m - a[i];     }     return ans;   }   long long judge2(int m) {     long long ans = 0;     for (int i = n; a[i] > m && i >= 1; i--) {       ans += a[i] - m;     }     return ans;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     sort(a + 1, a + n + 1);     int l = a[1], r = a[n], poorest = a[1];     while (l <= r) {       int mid = (l + r) >> 1;       long long p = judge1(mid);       if (p <= k) {         poorest = mid;         l = mid + 1;       } else         r = mid - 1;     }     l = a[1];     r = a[n];     int richest = a[n];     while (l <= r) {       int mid = (l + r) >> 1;       long long p = judge2(mid);       if (p <= k) {         richest = mid;         r = mid - 1;       } else         l = mid + 1;     }     if (poorest < richest)       printf( %d n , richest - poorest);     else {       if (sum % n == 0)         printf( 0 n );       else         printf( 1 n );     }     return 0;   }