malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 1e3 + 10, INF = 1e18;   long long n, m, k, a[MAX_N][MAX_N], noe[MAX_N];   long long lab[MAX_N], dp[MAX_N][MAX_N];   pair<long long, long long> tar[MAX_N];   void filldp() {     dp[m + n - 1][0] = 1;     for (int i = m + n - 2; i >= 1; i--) {       for (int j = 0; j <= i; j++) {         if (noe[i + 1] == 0) {           dp[i][j] = dp[i + 1][j - 1] + dp[i + 1][j + 1];         } else if (noe[i + 1] == 1) {           dp[i][j] = dp[i + 1][j + 1];         } else {           dp[i][j] = dp[i + 1][j - 1];         }         dp[i][j] = min(dp[i][j], INF);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(lab, 63, sizeof lab);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         lab[i + j - 1] = min(lab[i + j - 1], a[i][j]);       }     }     for (int i = 1; i <= n + m - 1; i++) {       tar[i] = {lab[i], i};     }     sort(tar + 1, tar + n + m);     for (int i = 1; i <= n + m - 1; i++) {       noe[tar[i].second] = 1;       filldp();       if (dp[1][1] >= k) {       } else {         noe[tar[i].second] = 2;         k -= dp[1][1];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (noe[i + j - 1] == 1) {           cout <<  ( ;         } else {           cout <<  ) ;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   long long srf(int a, int b, int c) {     std::cout <<  1   << (a + 1) <<     << (b + 1) <<     << (c + 1) << std::endl;     long long val;     std::cin >> val;     return val;   }   bool scl(int a, int b, int c) {     std::cout <<  2   << (a + 1) <<     << (b + 1) <<     << (c + 1) << std::endl;     int val;     std::cin >> val;     return val > 0;   }   void accept(std::vector<int> ans) {     std::cout <<  0  ;     for (int i : ans) {       std::cout << (i + 1) <<    ;     }     std::cout << std::endl;     return;   }   signed main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     int n;     std::cin >> n;     std::vector<int> ans(n);     std::iota(ans.begin(), ans.end(), 0);     int pos =         std::min_element(ans.begin() + 1, ans.end(),                          [&ans](int f, int s) { return scl(ans[0], f, s); }) -         ans.begin();     std::swap(ans[1], ans[pos]);     std::map<int, long long> map;     for (int i = 2; i < n; i++) {       map[ans[i]] = srf(ans[0], ans[1], ans[i]);     }     pos = std::max_element(ans.begin() + 1, ans.end(),                            [&map](int f, int s) { return map[f] < map[s]; }) -           ans.begin();     std::swap(ans.back(), ans[pos]);     std::vector<int> left, right;     for (int i = 2; i < (ans.size() - 1); i++) {       if (scl(ans[0], ans.back(), ans[i])) {         left.push_back(ans[i]);       } else {         right.push_back(ans[i]);       }     }     std::vector<int> ans2 = {ans[0], ans[1]};     std::sort(right.begin(), right.end(),               [&map](int f, int s) { return map[f] < map[s]; });     for (int i : right) {       ans2.push_back(i);     }     ans2.push_back(ans.back());     std::sort(left.begin(), left.end(),               [&map](int f, int s) { return map[f] < map[s]; });     std::reverse(left.begin(), left.end());     for (int i : left) {       ans2.push_back(i);     }     accept(ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> arr;   vector<long long int> b;   long long int l, f;   long long int mid;   long long int bin_s(long long int x) {     l = 0;     f = b.size() - 1;     while (l <= f) {       mid = (l + f) / 2;       if (b[mid] > x) f = mid - 1;       if (b[mid] < x) l = mid + 1;       if (b[mid] == x) {         return 1;         break;       }     }     return 0;   }   int main() {     long long int n, i, j, k, q;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> q;       arr.push_back(q);     }     long long int min = arr[0];     for (i = 0; i < n; i++) {       if (arr[i] <= min) min = arr[i];     }     for (i = 0; i < n; i++) {       if (arr[i] == min) b.push_back(i);     }     long long int c;     long long int max = 0;     long long int ways;     for (i = 0; i < n; i++) {       c = bin_s(i);       if (c == 1) {         ways = min * n;       }       if (c == 0) {         if (b[b.size() - 1] > i) ways = (min * n) + b[l] - i;         if (b[b.size() - 1] < i) ways = (min * n) + n - i + b[0];       }       if (ways > max) max = ways;     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long powm(long long base, long long exp, long long mod = 1000000007) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % mod;       exp >>= 1, base = (base * base) % mod;     }     return ans;   }   long long n, u, v, a[200005], st[2][200005], en[2][200005], timer[2],       tour[2][200005], level[200005], parent[200005], ft[2][200005];   vector<long long> adj[200005];   void dfs(long long mode, long long curr, long long par, long long now) {     parent[curr] = par, level[curr] = now;     if (now == mode)       st[mode][curr] = (++timer[mode]), tour[mode][timer[mode]] = curr;     for (auto i : adj[curr])       if (i != par) dfs(mode, i, curr, now ^ 1);     if (now == mode) en[mode][curr] = timer[mode];   }   void update(long long mode, long long p, long long val) {     long long curr = p;     for (; curr <= 200005; curr += (curr & (-curr))) ft[mode][curr] += val;   }   void update(long long mode, long long a, long long b, long long val) {     update(mode, a, val), update(mode, b + 1, -val);   }   long long query(long long mode, long long idx) {     long long sum = 0, curr = idx;     for (; curr > 0; curr -= (curr & (-curr))) sum += ft[mode][curr];     return sum;   }   int main() {     long long type, x, val, m;     cin >> n >> m;     for (long long i = 1; i < n + 1; i++) cin >> a[i];     for (long long i = 0; i < n - 1; i++) {       cin >> u >> v;       adj[u].push_back(v), adj[v].push_back(u);     }     for (long long i = 0; i < 2; i++) dfs(i, 1, 0, 0);     while (m--) {       cin >> type;       if (type == 1) {         cin >> x >> val;         long long mode = level[x], tmp = adj[x].size();         long long p = st[mode][x], q = en[mode][x], first = -1, last = -1;         update(mode, p, q, val);         for (auto i : adj[x])           if (i != parent[x]) {             first = i;             break;           }         for (long long i = tmp - 1; i >= 0; i--)           if (adj[x][i] != parent[x]) {             last = adj[x][i];             break;           }         if (first != -1) {           mode ^= 1;           p = st[mode][first], q = en[mode][last];           update(mode, p, q, -val);         }       } else {         cin >> x;         cout << query(level[x], st[level[x]][x]) + a[x] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int h = -1, e = -1, l1 = -1, l2 = -1, o = -1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  h ) {         h = i;         break;       }     }     if (h == -1)       cout <<  NO ;     else {       for (int j = h + 1; j < s.size(); j++) {         if (s[j] ==  e ) {           e = j;           break;         }       }       if (e == -1)         cout <<  NO ;       else {         for (int k = e + 1; k < s.size(); k++) {           if (s[k] ==  l ) {             l1 = k;             break;           }         }         if (l1 == -1)           cout <<  NO ;         else {           for (int l = l1 + 1; l < s.size(); l++) {             if (s[l] ==  l ) {               l2 = l;               break;             }           }           if (l2 == -1)             cout <<  NO ;           else {             for (int m = l2 + 1; m < s.size(); m++) {               if (s[m] ==  o ) {                 o = m;                 break;               }             }             if (o == -1)               cout <<  NO ;             else               cout <<  YES ;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int h, m, n;   void input() { scanf( %d%d%d , &h, &m, &n); }   set<int> s;   int head[200010], tail[200010], cnt[200010], idx[200010], nid;   void build() {     for (int i = 0; i < h; i++) s.insert(i);     memset(idx, -1, sizeof(idx));     memset(tail, -1, sizeof(tail));     for (int i = 0; i < h; i++) {       int st = nid;       if (idx[i] == -1)         for (int j = i; idx[j] == -1; j = (j + m) % h) {           head[j] = st;           idx[j] = nid++;         }       int ed = nid;       for (int j = i; tail[j] == -1; j = (j + m) % h) tail[j] = ed;     }     for (int i = 0; i < h; i++) cnt[i] = tail[i] - head[i];   }   long long ans;   map<int, int> pos;   void add(int id, int hash) {     set<int>::iterator it = s.lower_bound(idx[hash]);     if (it == s.end() || *it >= tail[hash]) it = s.lower_bound(head[hash]);     ans += (*it - idx[hash] + cnt[hash]) % cnt[hash];     pos[id] = *it;     s.erase(*it);   }   void del(int id) { s.insert(pos[id]); }   void solve() {     char op;     int id, hash;     while (n--) {       scanf(  %c%d , &op, &id);       if (op ==  + ) {         scanf( %d , &hash);         add(id, hash);       } else if (op ==  - ) {         del(id);       } else         puts( QQ );     }     printf( %I64d n , ans);   }   int main() {     input();     build();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1005;   string a[MaxN], start[MaxN], finish[MaxN], st[MaxN], Fans[MaxN];   int n, m, ind, Find;   int b[MaxN];   void check() {     int flag = 0, flag1 = 0, i, j;     ind = 0;     for (i = 1; i <= n; i++) {       if (b[i] == 1) {         ind++;         st[ind] = a[i];       }     }     for (i = 1; i <= m; i++) {       flag = 0;       for (j = 1; j <= ind; j++) {         if ((st[j] == start[i]) || (st[j] == finish[i])) {           flag++;         }       }       if (flag >= 2) {         flag1 = 1;         break;       }     }     if ((flag1 == 0) && (ind > Find)) {       for (i = 1; i <= ind; i++) {         Fans[i] = st[i];       }       Find = ind;     }   }   void rec(int i) {     if (i > n) {       check();       return;     }     b[i] = 0;     rec(i + 1);     b[i] = 1;     rec(i + 1);   }   int main() {     int i, j;     Find = 0;     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= m; i++) {       cin >> start[i] >> finish[i];     }     rec(1);     sort(Fans + 1, Fans + Find + 1);     cout << Find << endl;     for (i = 1; i <= Find; i++) {       cout << Fans[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long n, m, a, b, x, y;   int main() {     cin >> n >> m >> x >> y >> a >> b;     long long k = gcd(a, b);     long long kk = min(n / (a / k), m / (b / k));     a = a * kk / k, b = b * kk / k;     long long x1, x2, y1, y2;     x1 = x - (a + 1) / 2, x2 = x1 + a;     y1 = y - (b + 1) / 2, y2 = y1 + b;     if (x1 < 0) x1 = 0;     x2 = x1 + a;     x2 = min(n, x2), x1 = x2 - a;     if (y1 < 0) y1 = 0;     y2 = y1 + b;     y2 = min(m, y2), y1 = y2 - b;     cout << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20005;   const int len = 400;   const int mod = 1e9 + 7;   int n, p, q, ans[N];   struct node {     int c, h, t;   } a[N];   vector<int> all, in[N * 4];   vector<pair<int, int> > lazy[N];   void upd(int l, int r, int x, int v = 1, int tl = 0, int tr = all.size() - 1) {     if (tl > r || tr < l || l > r) return;     if (l <= tl && tr <= r) {       in[v].push_back(x);       return;     }     int tm = (tl + tr) / 2;     upd(l, r, x, v * 2, tl, tm);     upd(l, r, x, v * 2 + 1, tm + 1, tr);   }   void solve(vector<int> now, int v = 1, int tl = 0, int tr = all.size() - 1) {     for (auto id : in[v]) {       for (int i = 4000; i >= 0; i--) {         if (i - a[id].c >= 0) {           now[i] = max(now[i], now[i - a[id].c] + a[id].h);         }       }     }     if (tl == tr) {       for (auto i : lazy[all[tl]]) {         int id = i.second;         int w = i.first;         ans[id] = now[w];       }       return;     }     int tm = (tl + tr) / 2;     solve(now, v * 2, tl, tm);     solve(now, v * 2 + 1, tm + 1, tr);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> p;     for (int i = 1; i <= n; i++) {       cin >> a[i].c >> a[i].h >> a[i].t;     }     cin >> q;     for (int i = 1; i <= q; i++) {       int x, y;       cin >> x >> y;       all.push_back(x);       lazy[x].push_back(make_pair(y, i));     }     sort(all.begin(), all.end());     all.resize(unique(all.begin(), all.end()) - all.begin());     for (int i = 1; i <= n; i++) {       int l = lower_bound(all.begin(), all.end(), a[i].t) - all.begin();       int r =           upper_bound(all.begin(), all.end(), a[i].t + p - 1) - all.begin() - 1;       if (l <= r) upd(l, r, i);     }     vector<int> now;     now.resize(4001);     solve(now);     for (int i = 1; i <= q; i++) cout << ans[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int tes;     cin >> tes;     while (tes--) {       long long int n, m;       cin >> m >> n;       vector<pair<long long int, long long int>> arr(n);       for (long long int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;       sort(arr.begin(), arr.end());       vector<long long int> flower(n);       vector<long long int> cum(n + 1);       for (long long int i = 0; i < n; i++) flower[i] = arr[i].first;       cum[n] = 0;       for (int i = n - 1; i >= 0; i--) cum[i] = cum[i + 1] + flower[i];       long long int ans, here, left;       ans = 0;       m--;       for (long long int i = 0; i < n; i++) {         here = 0;         long long int key = arr[i].second;         long long int ix =             (upper_bound(flower.begin(), flower.end(), key) - flower.begin());         if (ix < n - m) ix = n - m;         here = here + cum[ix];         left = m - (n - ix);         here = here + left * key;         if (i < ix)           here = here + arr[i].first;         else           here = here + key;         ans = max(ans, here);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct SegTree {     const int INF = 1e9;     vector<pair<int, int>> max_vc;     vector<int> add;     int h = 1;     pair<int, int> combine(pair<int, int> a, pair<int, int> b) {       if (a.first == b.first)         return {a.first, a.second + b.second};       else         return max(a, b);     }     void push(int i) {       max_vc[i].first += add[i];       if (i < h) {         add[2 * i] += add[i];         add[2 * i + 1] += add[i];       }       add[i] = 0;     }     SegTree(int n, int v) {       while (h < n) h <<= 1;       max_vc.resize(2 * h, {v, 1});       add.resize(2 * h, 0);       for (int i = h - 1; i > 0; --i)         max_vc[i] = combine(max_vc[2 * i], max_vc[2 * i + 1]);     }     void recAdd(int a, int b, int v, int i, int ia, int ib) {       push(i);       if (ib < a || b < ia) return;       if (a <= ia && ib <= b) {         add[i] += v;         push(i);       } else {         int im = (ia + ib) >> 1;         recAdd(a, b, v, 2 * i, ia, im);         recAdd(a, b, v, 2 * i + 1, im + 1, ib);         max_vc[i] = combine(max_vc[2 * i], max_vc[2 * i + 1]);       }     }     pair<int, int> recGet(int a, int b, int i, int ia, int ib) {       push(i);       if (ib < a || b < ia) return {-INF, 0};       if (a <= ia && ib <= b) return max_vc[i];       int im = (ia + ib) >> 1;       return combine(recGet(a, b, 2 * i, ia, im),                      recGet(a, b, 2 * i + 1, im + 1, ib));     }     void addInt(int a, int b, int v) { recAdd(a, b, v, 1, 0, h - 1); }     pair<int, int> getInt(int a, int b) { return recGet(a, b, 1, 0, h - 1); }   };   int pre[300005], b[300005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     SegTree seg(n, 0);     vector<pair<int, int>> maxes;     long long res = 0;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       pre[i] = max(pre[i - 1], b[a]);       b[a] = i;       int p = pre[i] + 1;       seg.addInt(p, i, 1);       seg.addInt(i, i, -a);       pair<int, int> maxes_add = {a, i};       while ((!maxes.empty()) && (maxes.back().first <= a)) {         seg.addInt(maxes.back().second, maxes_add.second - 1,                    -(a - maxes.back().first));         maxes_add.second = maxes.back().second;         maxes.pop_back();       }       maxes.push_back(maxes_add);       pair<int, int> sub = seg.getInt(p, i);       if (sub.first == 0) res += sub.second;     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int m;     cin >> m;     unsigned long long int A[m], Ap[m];     unsigned long long int B[m];     map<unsigned long long int, vector<unsigned long long int> > mp;     for (long long int i = 0; i < m; i++) {       cin >> B[i];     }     for (long long int i = 0; i < m; i++) {       cin >> A[i];       Ap[i] = A[i];     }     sort(Ap, Ap + m);     sort(B, B + m);     for (int i = 0; i < m; i++) {       mp[Ap[i]].push_back(B[m - 1 - i]);     }     for (long long int i = 0; i < m; i++) {       cout << mp[A[i]].back() <<    ;       mp[A[i]].pop_back();     }   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const MAX = 200 * 1000 + 41;   long double const EPS = 1e-12;   bool eq(long double a, long double b) { return abs(a - b) < EPS; }   bool leq(long double a, long double b) { return (a < b || eq(a, b)); }   int n, w;   int x[MAX];   int v[MAX];   pair<long double, long double> a[MAX];   pair<int, int> b[MAX];   int const ADD = 0;   int const ASK = 1;   struct Event {     int y, s, t;     Event(){};     Event(int y, int s, int t) : y(y), s(s), t(t){};     bool operator<(const Event &a) const {       if (t != a.t) return t < a.t;       return y < a.y;     };   };   vector<Event> e[MAX];   int gethash(vector<long double> &v, long double x) {     int l = -1;     int r = (int)v.size();     while (r - l > 1) {       int h = (l + r) / 2;       if (leq(v[h], x)) {         l = h;       } else {         r = h;       }     }     return l;   }   void init() {     vector<long double> tmp;     for (int i = 1; i <= n; i++) {       long double l = (long double)v[i] / x[i] - (long double)w / x[i];       long double r = (long double)v[i] / x[i] + (long double)w / x[i];       a[i] = make_pair(l, r);       tmp.push_back(l);       tmp.push_back(r);     }     sort(tmp.begin(), tmp.end());     for (int i = 1; i <= n; i++) {       b[i] = make_pair(gethash(tmp, a[i].first), gethash(tmp, a[i].second));     }     for (int i = 1; i <= n; i++) {       int x = b[i].first;       int y = b[i].second;       e[x].push_back(Event(y, 41, ADD));       e[x].push_back(Event(y, -1, ASK));       e[MAX - 1].push_back(Event(y, 1, ASK));     }   }   namespace Fen {   int F[MAX];   void upd(int x, int v) {     while (x < MAX) {       F[x] += v;       x |= (x + 1);     }   }   int get(int x) {     int res = 0;     while (x >= 0) {       res += F[x];       x = (x & (x + 1)) - 1;     }     return res;   }   };  // namespace Fen   long long ans;   void solve() {     init();     for (int i = 1; i <= n; i++) {       while (false) {       };     }     for (int i = 0; i <= MAX - 1; i++) {       sort(e[i].begin(), e[i].end());       for (Event z : e[i]) {         if (z.t == ADD) {           Fen::upd(z.y, 1);         } else {           int q = Fen::get(z.y);           ans += q * z.s;         }       }     }     unordered_map<int, int> ql;     for (int i = 1; i <= n; i++) {       ql[b[i].first]++;       ans += ql[b[i].first] - 1;     }     printf( %lld n , ans);   }   int main() {     scanf( %d %d , &n, &w);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &x[i], &v[i]);     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nax = 1e5 + 5;   vector<int> w[nax];   bool del[nax];   int legs[nax];   void dfs(int a, int par = 0) {     if (w[a].size() <= 2) {       del[a] = true;       for (int i = 0; i < w[a].size(); i++) {         int b = w[a][i];         if (b != par) dfs(b, a);       }     }   }   int main() {     int n, b;     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       int a, b;       scanf( %d%d , &a, &b);       w[a].push_back(b);       w[b].push_back(a);     }     for (int a = 1; a <= n; ++a)       if (w[a].size() == 1) dfs(a);     for (int a = 1; a <= n; ++a) {       for (int i = 0; i < w[a].size(); i++) {         b = w[a][i];         if (del[b]) legs[a] = min(legs[a] + 1, 2);       }     }     for (int a = 1; a <= n; ++a)       if (!del[a]) {         int cnt = 0;         for (int i = 0; i < w[a].size(); i++) {           b = w[a][i];           if (!del[b] && w[b].size() - legs[b] > 1) ++cnt;         }         if (cnt > 2) {           puts( No );           return 0;         }       }     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int intmax = 0x3f3f3f3f;   const long long lldmax = 0x3f3f3f3f3f3f3f3fll;   double eps = 1e-8;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T lowbit(T n) {     return (n ^ (n - 1)) & n;   }   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   template <class T>   inline T checkmod(T n, T m) {     return (n % m + m) % m;   }   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T euclid(T a, T b, T &x, T &y) {     if (a < 0) {       T d = euclid(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclid(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclid(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <class T>   inline int dblcmp(T a, const T b) {     a -= b;     return a > eps ? 1 : (a < -eps ? -1 : 0);   }   template <class T>   inline int sgn(T a) {     return a > eps ? 1 : (a < -eps ? -1 : 0);   }   const int N = 1100000;   long long a[N], cnt[N];   long long ch[N];   int n, k;   bool check(int m) {     for (int i = 0; i < m; ++i) ch[i] = 0;     long long del = k;     for (int i = 0; i < n; ++i) {       ch[a[i] % m]++;       long long tmp = ch[a[i] % m];       if (tmp > 1) del--;       if (del < 0) break;     }     return del >= 0;   }   int main() {     cin >> n >> k;     if (n <= k + 1) {       cout << 1 << endl;       return 0;     }     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         cnt[a[j] - a[i]]++;       }     }     long long ans = N;     for (int i = 1; i < N; ++i) {       int tmp = 0;       for (int j = i; j < N; j += i) {         tmp += cnt[j];       }       if (tmp <= k * (k + 1) / 2 && check(i)) {         ans = i;         break;       }     }     cout << ans << endl;     return 0;   }