malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000 * 1000 * 1000 + 7;   const long long int INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;   const long long int MOD2 = 998244353;   const long double PI = 3.141592653589793;   long long int gcd(long long int a, long long int b) {     if (!b) return a;     return gcd(b, a % b);   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x %= p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int power1(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int max(long long int a, long long int b) {     if (a > b) return a;     return b;   }   long long int min(long long int a, long long int b) {     if (a > b) return b;     return a;   }   bool sortbysec(const pair<long long int, long long int> &a,                  const pair<long long int, long long int> &b) {     return a.second < b.second;   }   vector<long long int> prime;   bool val[500];   void sieve() {     memset(val, true, sizeof(val));     val[1] = false;     val[0] = false;     for (long long int i = 2 * 2; i <= 500; i += 2) {       val[i] = false;     }     for (long long int i = 3; i <= 500; i++) {       if (val[i] == false) continue;       for (long long int j = i * i; j <= 500; j += i) {         val[j] = false;       }     }     for (int i = 0; i <= 500; i++) {       if (val[i] == true) {         prime.push_back(i);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int arr[n];       for (long long int i = 0; i < n; i++) {         cin >> arr[i];       }       if (n == 1) {         cout << k + 1 <<   n ;         continue;       }       if (k < 9) {         cout << k + 1 <<   n ;         continue;       }       long long int ans = 0;       long long int flag = 0;       long long int count = 0;       long long int count1 = 0;       for (long long int i = 1; i < n; i++) {         long long int num = power1(10, arr[i]) - 1;         count = 0;         for (long long int j = i - 1; j >= 0; j--) {           count += num / power1(10, arr[j]);           num -= ((num / power1(10, arr[j])) * power1(10, arr[j]));         }         if (count > k) {           cout << power1(10, arr[i - 1]) * (k - count1 + 1) +                       power1(10, arr[i - 1]) - 1                <<   n ;           flag = 1;           break;         }         count1 = count;       }       if (flag == 0) {         cout << (power1(10, arr[n - 1]) - 1) +                     power1(10, arr[n - 1]) * (k - count1 + 1)              <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b;   int ans[60];   void dfs(int dep) {     long long cur = ans[dep - 1];     long long x = cur << 1;     long long y = cur * 10 + 1;     if (x == b || y == b) {       puts( YES );       cout << dep + 1 << endl;       for (int i = 0; i < dep; i++) cout << ans[i] <<    ;       cout << b << endl;       exit(0);     }     ans[dep] = x;     if (x < b) dfs(dep + 1);     ans[dep] = y;     if (y < b) dfs(dep + 1);   }   int main() {     cin >> a >> b;     ans[0] = a;     dfs(1);     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, x, y, z, r = 0;     scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &z);     if (a > x) {       r += (a - x) / 2;       a -= r * 2;     }     if (b > y) {       r += (b - y) / 2;       b -= (b - y) / 2 * 2;     }     if (c > z) {       r += (c - z) / 2;       c -= (c - z) / 2 * 2;     }     if (a < x) {       r -= x - a;       a += x - a;     }     if (r < 0) {       printf( No );       return 0;     }     if (b < y) {       r -= y - b;       b += y - b;     }     if (r < 0) {       printf( No );       return 0;     }     if (c < z) {       r -= z - c;       c += z - c;     }     if (r < 0) {       printf( No );       return 0;     }     printf( Yes );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:20000000 )   #pragma warning(disable : 4146)   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int inf = 1e9;   const long long lnf = 1e18;   const long long h1 = 239017, h2 = 731604233;   const long long mod = 1000000007, mod2 = 1000000009;   const long double pi = 3.141592653589793238462643383279;   const long double EPS = 1e-9;   struct rectangle {     int x1, x2;     int y1, y2;     rectangle(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}   };   vector<rectangle> v;   int n, x, y, first, second;   int xm[2005], ym[2005];   bool obs[2005][2005], a[2005][2005];   map<int, int> mx, my;   void dfs(int x, int y) {     if (x < 0 || x >= first || y < 0 || y >= second || obs[x][y] || a[x][y])       return;     a[x][y] = true;     dfs(x + 1, y);     dfs(x - 1, y);     dfs(x, y + 1);     dfs(x, y - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     cout << setprecision(20);     cin >> n;     for (int i = 0; i < (n); i++) {       char dir;       int d;       cin >> dir >> d;       if (dir ==  L ) {         rectangle r = {x - d, y, x + 1, y + 1};         v.push_back(r);         x -= d;       }       if (dir ==  R ) {         rectangle r = {x, y, x + d + 1, y + 1};         v.push_back(r);         x += d;       }       if (dir ==  U ) {         rectangle r = {x, y, x + 1, y + d + 1};         v.push_back(r);         y += d;       }       if (dir ==  D ) {         rectangle r = {x, y - d, x + 1, y + 1};         v.push_back(r);         y -= d;       }     }     for (int i = 0; i < (n); i++) {       mx[v[i].x1] = mx[v[i].x2] = 0;       my[v[i].y1] = my[v[i].y2] = 0;     }     for (auto &it : mx) {       it.second = first;       xm[first++] = it.first;     }     for (auto &it : my) {       it.second = second;       ym[second++] = it.first;     }     --first, --second;     for (int i = 0; i < (n); i++) {       int x1 = mx[v[i].x1], x2 = mx[v[i].x2], y1 = my[v[i].y1], y2 = my[v[i].y2];       for (int j = x1; j < x2; ++j)         for (int k = y1; k < y2; ++k) obs[j][k] = true;     }     for (int i = 0; i < (first); i++)       for (int j = 0; j < (second); j++)         if (!i || i == first - 1 || !j || j == second - 1) dfs(i, j);     long long ans = 0;     for (int i = 0; i < (first); i++)       for (int j = 0; j < (second); j++)         if (!a[i][j]) {           long long dx = xm[i + 1] - xm[i], dy = ym[j + 1] - ym[j];           ans += dx * dy;         }     cout << ans << endl;     cerr <<  Time used :   << (double)clock() * 1.0 / 1000 <<   seconds. n           << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (x > y) {       cout << n << endl;       return 0;     }     int cnt = 0;     for (int i = 0; i < n; i++) {       if (a[i] <= x) {         cnt++;       }     }     cout << (cnt + 1) / 2 << endl;   }
#include <bits/stdc++.h>   const int N = 100005;   using namespace std;   long long n, a, b, k;   char s[N];   long long mod = 1e9 + 9;   long long pow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       b >>= 1;       a = a * a % mod;     }     return ans;   }   long long ex_gcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     long long tmp = ex_gcd(b, a % b, x, y);     long long t = x;     x = y;     y = t - (a / b) * x;     return tmp;   }   long long inv(long long x) {     long long a, b;     ex_gcd(x, mod, a, b);     return (a + mod) % mod;   }   int main() {     scanf( %lld%lld%lld%lld , &n, &a, &b, &k);     scanf( %s , s);     long long ans = 0, m = (n + 1) / k;     for (int i = 0; i < k; i++) {       long long x = pow(a, n - i), y = pow(b, i);       long long now = x * y % mod;       if (s[i] ==  + )         ans += now;       else         ans -= now;       ans = (ans + mod) % mod;     }     long long q = pow(inv(a), k) * pow(b, k) % mod;     if (q == 1)       ans = ans * m % mod;     else {       long long x = inv(q - 1) % mod;       ans = (ans * (pow(q, m) - 1) % mod) * x % mod;     }     ans = (ans + mod) % mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, r;     std::string s;     scanf( %d/n , &n);     for (i = 0; i < n; i++) {       std::cin >> s;       long long y = 0, ans;       int x = s.size() - 4;       for (int j = 0; j < x; j++) {         y *= 10;         y += s[j + 4] -  0 ;       }       if (x == 1) {         ans = 1990 + y;         if (ans == 1999) ans -= 10;       } else if (x == 2) {         ans = 2000 + y;         if (ans == 2099) ans -= 100;       } else if (x == 3) {         ans = 2000 + y;         if (ans < 2099) ans += 1000;       } else if (x == 4) {         ans = y;         if (ans < 3099) ans += 10000;       } else if (x == 5) {         ans = y;         if (ans < 13099) ans += 100000;       } else if (x == 6) {         ans = y;         if (ans < 113099) ans += 1000000;       } else if (x == 7) {         ans = y;         if (ans < 1113099) ans += 10000000;       } else if (x == 8) {         ans = y;         if (ans < 11113099) ans += 100000000;       } else if (x == 9) {         ans = y;         if (ans < 111113099) ans += 1000000000;       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long mod = 1000000007;   long long r(pair<int, int> a) {     long long x = a.first;     long long y = a.second;     return x * x + y * y;   }   pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int main() {     ios_base::sync_with_stdio(false);     int N;     cin >> N;     vector<pair<pair<int, int>, vector<int>>> a;     for (int i = 1; i <= N; i++) {       int x, y;       cin >> x >> y;       a.push_back({{x, y}, {i}});     }     shuffle(a.begin(), a.end(), rng);     while (a.size() >= 3) {       int i = a.size() - 1;       int j = a.size() - 2;       int wj = 1;       pair<int, int> mnn = {1e8, 1e8};       for (int x = a.size() - 3; x < (int)a.size(); x++) {         for (int y = x + 1; y < (int)a.size(); y++) {           if (x == y) continue;           pair<int, int> v1 = a[x].first + a[y].first;           pair<int, int> v2 = a[x].first - a[y].first;           if (r(v1) < r(mnn)) {             mnn = v1;             i = x;             j = y;             wj = 1;           }           if (r(v2) < r(mnn)) {             mnn = v2;             i = x;             j = y;             wj = -1;           }         }       }       a[i].first = a[j].first = mnn;       if (a[j].second.size() < a[i].second.size()) {         for (int c : a[j].second) {           a[i].second.push_back(c * wj);         }         a.erase(a.begin() + j);       } else {         if (wj == 1) {           for (int c : a[i].second) {             a[j].second.push_back(c * wj);           }           a.erase(a.begin() + i);         } else {           a[j].first = make_pair(0, 0) - a[j].first;           for (int c : a[i].second) {             a[j].second.push_back(-c);           }           a.erase(a.begin() + i);         }       }     }     if (a.size() == 2) {       if (r(a[0].first - a[1].first) < r(a[0].first + a[1].first)) {         for (int &i : a[1].second) i *= -1;       }     }     int w[N + 1];     for (auto ii : a) {       for (int i : ii.second) {         if (i > 0)           w[i] = 1;         else           w[-i] = -1;       }     }     for (int i = 1; i <= N; i++) cout << w[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, z, q, sum;   int main() {     ios_base::sync_with_stdio(0);     for (cin >> n; n; --n)       cin >> x >> y >> z >> q, sum += (z - x + 1) * (q - y + 1);     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nmax = 123456;   int n;   int a[nmax], b[nmax], c[nmax];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       if (i == a[i]) {         printf( YES n );         for (int j = 1; j <= n; j++)           if (j != i) printf( %d %d n , i, j);         return 0;       }     for (int i = 1; i <= n; i++)       if (i == a[a[i]]) {         int bb = 0;         b[i] = 1;         b[a[i]] = 1;         for (int j = 1; j <= n; j++)           if (b[j] != 1) {             int dd = j;             int cc = 0;             while (b[dd] != 1) {               cc++;               b[dd] = 1;               dd = a[dd];             }             bb += cc % 2;           }         if (bb >= 1) {           printf( NO );           return 0;         } else {           printf( YES n );           for (int j = 1; j <= n; j++) b[j] = 0;           b[i] = 1;           b[a[i]] = 1;           int y = i;           for (int j = 1; j <= n; j++)             if (b[j] != 1) {               int x = j;               while (b[x] != 1) {                 printf( %d %d n , y, x);                 b[x] = 1;                 x = a[x];                 y = a[y];               }             }           printf( %d %d , i, a[i]);           return 0;         }       }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long a[5], b[5], n, cu, medal, x, y;     cin >> a[1] >> a[2] >> a[3];     cu = a[1] + a[2] + a[3];     cin >> b[1] >> b[2] >> b[3];     medal = b[1] + b[2] + b[3];     cin >> n;     if (cu % 5 == 0)       x = cu / 5;     else       x = cu / 5 + 1;     if (medal % 10 == 0)       y = medal / 10;     else       y = medal / 10 + 1;     if (n == 1 && cu > 0 && medal > 0 || x + y > n)       cout <<  NO ;     else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int si, lef, t0;   int a1, t1, p1;   int a2, t2, p2;   int main() {     cin >> si >> lef >> t0;     cin >> a1 >> t1 >> p1;     cin >> a2 >> t2 >> p2;     if (t1 > t2) {       swap(a1, a2);       swap(t1, t2);       swap(p1, p2);     }     long long ans = 1LL * inf * inf;     for (int i = 0;; ++i) {       if ((long long)a1 * t1 * (i - 1) > lef) {         break;       }       long long t = 0;       if (i && 1LL * a1 * i >= si && 1LL * a1 * (i - 1) < si) {         t = 1LL * a1 * t1 * (i - 1) + 1LL * (si - 1LL * a1 * (i - 1)) * t1;         if (t <= lef) {           ans = min(ans, (long long)p1 * i);         }       } else if (1LL * a1 * i < si) {         t += 1LL * a1 * t1 * i;         long long ts = si - a1 * i;         if (t + 1LL * ts * t0 <= lef) {           ans = min(ans, (long long)p1 * i);         } else {           if (t2 < t0) {             long long byte = (t + 1LL * ts * t0 - lef + t0 - t2 - 1) / (t0 - t2);             if (byte <= ts) {               long long bug = (byte + a2 - 1) / a2;               ans = min(ans, 1LL * i * p1 + 1LL * bug * p2);             }           }         }       }     }     if (ans == 1LL * inf * inf) {       ans = -1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct comp {     double x, y;   } a[65600], b[65600], c[65600], fft[65600], tp[17][65600];   double pi = acos(-1.0);   comp operator+(comp a, comp b) { return (comp){a.x + b.x, a.y + b.y}; }   comp operator-(comp a, comp b) { return (comp){a.x - b.x, a.y - b.y}; }   comp operator*(comp a, comp b) {     return (comp){a.x * b.x - a.y * b.y, a.y * b.x + b.y * a.x};   }   comp operator/(comp a, double b) { return (comp){a.x / b, a.y / b}; }   int rev[65600], n, m, p, s[65600][2], as;   void dft(int s, comp *a, int t) {     for (int i = 0; i < s; i++)       rev[i] = (rev[i >> 1] >> 1) + (i & 1) * (s >> 1), fft[rev[i]] = a[i];     for (int l = 2, lg = 1; l <= s; l <<= 1, lg++)       for (int j = 0; j < s; j += l)         for (int k = j; k < j + (l >> 1); k++) {           comp sp = tp[lg][k - j];           if (t == -1) sp.y *= -1;           comp tp1 = fft[k], tp2 = fft[k + (l >> 1)] * sp;           fft[k] = tp1 + tp2, fft[k + (l >> 1)] = tp1 - tp2;         }     int inv = t == -1 ? s : 1;     for (int i = 0; i < s; i++) a[i] = fft[i] / inv;   }   void solve(int x) {     if (x == 0) return;     if (x == 1) {       s[1][1] = 1;       as = 1;       return;     }     int tp = x / 2;     solve(tp);     int l = 1;     while (l <= n * 2 + 1) l <<= 1;     for (int i = 0; i < l; i++)       a[i].x = a[i].y = b[i].x = b[i].y = c[i].x = c[i].y = 0;     for (int i = 1; i <= n; i++) a[i].x = s[i][0], b[i].x = s[i][1];     dft(l, a, 1), dft(l, b, 1);     for (int i = 0; i < l; i++) c[i] = (a[i] + b[i] + (comp){1, 0}) * a[i];     dft(l, c, -1);     for (int i = 1; i <= n; i++)       s[i][tp & 1] = (s[i][tp & 1] + (long long)(c[i].x + 0.1)) % p;     for (int i = 0; i < l; i++) c[i] = (a[i] + b[i] + (comp){1, 0}) * b[i];     dft(l, c, -1);     for (int i = 1; i <= n; i++)       s[i][~tp & 1] = ((long long)(c[i].x + 0.1) + s[i][~tp & 1]) % p;     if (x & 1)       for (int i = n; i > 1; i--)         s[i][1] = (s[i][1] + s[i - 1][1] + s[i - 1][0]) % p;     if (x & 1) s[1][1] = (s[1][1] + 1) % p;     for (int i = 1; i <= n; i += 2) as = (as + s[i][1]) % p;   }   void init() {     for (int i = 1; i < 17; i++)       for (int j = 0; j < 1 << i; j++)         tp[i][j] = (comp){cos(2 * pi / (1 << i) * j), sin(2 * pi / (1 << i) * j)};   }   int main() {     scanf( %d%d%d , &n, &m, &p);     init();     solve(m / 2);     printf( %d n , as);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[26];   int visited[26];   int p[26], deg[26];   string ans;   bool fail;   void dfs(int u) {     visited[u] = 2;     ans += (char)(u +  a );     for (int i = 0; i < (int)g[u].size(); i++) {       int v = g[u][i];       if (visited[v] == 0) {         p[v] = u;         dfs(v);       } else if (visited[v] == 2) {         if (p[u] != v) {           fail = true;         }       }     }     visited[u] = 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       string s;       cin >> s;       int n = s.size();       ans =   ;       for (int i = 0; i < 26; i++) {         g[i].clear();         visited[i] = 0;         p[i] = -1;         deg[i] = 0;       }       map<pair<int, int>, int> m;       for (int i = 1; i < n; i++) {         int v = (s[i] -  a );         int u = (s[i - 1] -  a );         int uu = min(u, v);         int vv = max(u, v);         if (m[make_pair(uu, vv)] == 0) {           g[u].push_back(v);           g[v].push_back(u);           deg[u]++;           deg[v]++;           m[make_pair(uu, vv)]++;         }       }       fail = false;       for (int i = 0; i < 26; i++) {         if (deg[i] > 2) {           fail = true;         }         if (!visited[i] && deg[i] < 2) {           dfs(i);         }       }       if (fail || ans.size() < 26) {         cout <<  NO  <<   n ;       } else {         cout <<  YES  <<   n ;         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int bench, more, temp;     vector<int> v;     cin >> bench >> more;     for (int i = 0; i < bench; i++) {       cin >> temp;       v.push_back(temp);     }     int min, max = *max_element(v.begin(), v.end());     ;     min = *min_element(v.begin(), v.end());     int max_val = max + more;     for (int i = 0; i < more; i++) {       sort(v.begin(), v.end());       v[0]++;     }     std::sort(v.begin(), v.end(), std::greater<int>());     int min_val = v[0];     cout << min_val <<     << max_val;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline int read() {     static char buf[1000000], *p1 = buf, *p2 = buf;     register int x = false;     register char ch =         p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)             ? EOF             : *p1++;     ;     register bool sgn = false;     while (ch !=  -  && (ch <  0  || ch >  9 ))       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     if (ch ==  - )       sgn = true,       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48),       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     return sgn ? -x : x;   }   long long fpow(long long a, int b, int mod) {     long long res = 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long a[N];   double ans[N];   long long sum[N];   int s[N];   int idx = 1;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     for (int i = 1; i <= n; i++) {       while (idx > 1 && (sum[i] - sum[s[idx]]) * (i - s[idx - 1]) <=                             (sum[i] - sum[s[idx - 1]]) * (i - s[idx]))         idx--;       s[++idx] = i;     }     for (int i = 2; i <= idx; i++) {       double res = 1.0 * (sum[s[i]] - sum[s[i - 1]]) / (s[i] - s[i - 1]);       for (int j = 1; j <= s[i] - s[i - 1]; j++) {         printf( %.10f n , res);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   int n, k;   int v[MAXN];   int f[MAXN];   int search(int num) {     int l = 1, r = n;     while (l < r) {       int mid = (l + r) / 2;       if (v[mid] < num) {         l = mid + 1;       } else {         r = mid;       }     }     return l;   }   bool check(int len) {     memset(f, 0, sizeof(f));     for (int i = 1; i <= n; i++) {       int t = search(v[i] - len);       if (t == 1 && i - t + 1 >= k) {         if (i == n) {           return true;         }         f[i] += f[i - 1] + 1;       } else if (t >= 2 && i - t + 1 >= k && f[i - k] - f[t - 2] > 0) {         if (i == n) {           return true;         }         f[i] += f[i - 1] + 1;       } else {         f[i] = f[i - 1];       }     }     return false;   }   int main(int argc, const char* argv[]) {     scanf( %d , &(n));     scanf( %d , &(k));     for (int i = 1; i <= n; i++) {       scanf( %d , &(v[i]));     }     sort(v + 1, v + 1 + n);     int l = 0, r = 1000000000;     while (l < r) {       int mid = (l + r) / 2;       if (check(mid)) {         r = mid;       } else {         l = mid + 1;       }     }     printf( %d n , l);     return 0;   }