malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   long long int read_int() {     char r;     bool start = false, neg = false;     long long int ret = 0;     while (true) {       r = getchar();       if ((r -  0  < 0 || r -  0  > 9) && r !=  -  && !start) {         continue;       }       if ((r -  0  < 0 || r -  0  > 9) && r !=  -  && start) {         break;       }       if (start) ret *= 10;       start = true;       if (r ==  - )         neg = true;       else         ret += r -  0 ;     }     if (!neg)       return ret;     else       return -ret;   }   int main() {     map<long long, long long> x;     map<long long, long long> y;     map<pair<long long, long long>, long long> z;     long long n, a, b, ans = 0;     n = read_int();     while (n--) {       a = read_int();       b = read_int();       ans += (x[a]++);       ans += (y[b]++);       ans -= z[make_pair(a, b)]++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const long long Inf = 0x3f3f3f3f3f3f3f3f;   const int maxn = 1e3 + 4;   const int maxm = 1e5 + 4;   vector<int> v;   int n, k, b[maxn];   int main() {     ios::sync_with_stdio(false);     int i, j, kase;     cin >> n >> k;     for (i = 1; i <= n; ++i) cin >> b[i];     v.push_back(n);     auto it = v.begin();     for (i = n - 1; i >= 1; --i) {       it = v.begin();       int num = 0;       while (num < b[i]) {         if (*it >= i + k) num++;         it++;       }       v.insert(it, i);     }     for (i = 0; i < v.size(); ++i) {       if (i) cout <<    ;       cout << v[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long a, b, c;     if (n / 2 < k + 1) {       a = b = 0;       c = n;     } else {       long long x = (n / 2) / (k + 1);       a = k * x;       b = x;       c = n - x * (k + 1);     }     cout << b <<     << a <<     << c <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<tuple<long long int, long long int, long long int> > v;   vector<long long int> v1, v3;   vector<pair<char, long long int> > v2;   long long int i, j, k, n, sum = 0, p, r, ct = 0, q, sum1 = 0, sum2, t;   set<long long int> s, s1;   priority_queue<long long int> g;   const int maxn = 1e3 + 100, inf = 1e9 + 100;   long long int dp[maxn][3];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       q = 0;       cin >> n;       long long int a[n];       map<long long int, long long int> m, m1;       for (i = 1; i < n + 1; i++) {         cin >> a[i];         m[a[i]] = i;       }       p = m[1];       for (i = 1; i < n + 1; i++) {         if (m[i] != p) {           q = 1;           break;         } else {           a[m[i]] = -1;         }         if (m[i] == n && i < n)           p = m[i + 1];         else if (m[i] < n && a[m[i] + 1] != -1)           p++;         else if (m[i] < n && a[m[i] + 1] == -1)           p = m[i + 1];       }       if (q != 1)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point(int a = 0, int b = 0) {       x = a;       y = b;     }   };   struct cmpx {     bool operator()(point a, point b) {       if (a.x == b.x) return a.y < b.y;       return a.x < b.x;     }   };   struct cmpy {     bool operator()(point a, point b) {       if (a.y == b.y) return a.x < b.x;       return a.y < b.y;     }   };   bool ltx(point a, point b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   int conq(set<point, cmpx>& sx, set<point, cmpy>& sy) {     if (sx.size() == 1) return 1;     set<point, cmpx> sx1;     set<point, cmpy> sy1;     set<point, cmpx>::iterator itx1;     set<point, cmpx>::reverse_iterator itx2;     set<point, cmpy>::iterator ity1;     set<point, cmpy>::reverse_iterator ity2;     itx1 = sx.begin();     itx2 = sx.rbegin();     ity1 = sy.begin();     ity2 = sy.rbegin();     int t;     do {       t = itx1->x;       itx1++;       if (itx1->x - t > 1) {         while (sx.begin()->x <= t) {           sx1.insert(*sx.begin());           sy1.insert(*sx.begin());           sy.erase(*sx.begin());           sx.erase(*sx.begin());         }         return conq(sx, sy) + conq(sx1, sy1);       }       t = itx2->x;       itx2++;       if (t - itx2->x > 1) {         while (sx.rbegin()->x >= t) {           sx1.insert(*sx.rbegin());           sy1.insert(*sx.rbegin());           sy.erase(*sx.rbegin());           sx.erase(*sx.rbegin());         }         return conq(sx, sy) + conq(sx1, sy1);       }       t = ity1->y;       ity1++;       if (ity1->y - t > 1) {         while (sy.begin()->y <= t) {           sx1.insert(*sy.begin());           sy1.insert(*sy.begin());           sx.erase(*sy.begin());           sy.erase(*sy.begin());         }         return conq(sx, sy) + conq(sx1, sy1);       }       t = ity2->y;       ity2++;       if (t - ity2->y > 1) {         while (sy.rbegin()->y >= t) {           sx1.insert(*sy.rbegin());           sy1.insert(*sy.rbegin());           sx.erase(*sy.rbegin());           sy.erase(*sy.rbegin());         }         return conq(sx, sy) + conq(sx1, sy1);       }     } while (ltx(*itx1, *itx2));     return 1;   }   int main() {     int n, i, x, y;     set<point, cmpx> sx;     set<point, cmpy> sy;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       sx.insert(point(x, y));       sy.insert(point(x, y));     }     printf( %d , conq(sx, sy));   }
#include <bits/stdc++.h>   const int MAXN = 200010;   const int mod = 1000000007;   void reduce(int& x) { x += x >> 31 & mod; }   int mul(int a, int b) { return (long long)a * b % mod; }   int remod(long long x) {     x %= mod;     return x + (x >> 63 & mod);   }   int n;   int A[MAXN], W[MAXN];   long long rt[MAXN];   void mdfc(int x, int v) {     for (; x <= n; x += x & -x) rt[x] += v;   }   long long qry(int x) {     long long res = 0;     for (; x; x &= x - 1) res += rt[x];     return res;   }   long long qry(int l, int r) { return qry(r) - qry(l - 1); }   int tr[MAXN];   void mdfv(int x, int v) {     for (v -= mod; x <= n; x += x & -x) reduce(tr[x] += v);   }   int qryv(int x) {     int res = 0;     for (; x; x &= x - 1) reduce(res += tr[x] - mod);     return res;   }   int qryv(int l, int r) {     int x = qryv(r) - qryv(l - 1);     return x + (x >> 31 & mod);   }   void add(int x, int v) { mdfc(x, v), mdfv(x, remod(mul(A[x], v))); }   int main() {     std::ios_base::sync_with_stdio(false), std::cin.tie(0);     int T;     std::cin >> n >> T;     for (int i = 1; i <= n; ++i) std::cin >> A[i], A[i] -= i;     for (int i = 1; i <= n; ++i) std::cin >> W[i], add(i, W[i]);     while (T-- > 0) {       int x, y;       std::cin >> x >> y;       if (x < 0)         x = -x, add(x, y - W[x]), W[x] = y;       else {         int l = x, r = y, at = -1;         long long sm = qry(l, r);         while (l <= r) {           int mid = l + r >> 1;           if (qry(x, mid) * 2 >= sm)             at = mid, r = mid - 1;           else             l = mid + 1;         }         l = x, r = y;         int X = A[at];         long long ans = qry(l, at) % mod * X - qryv(l, at);         ans += qryv(at + 1, r) - qry(at + 1, r) % mod * X;         std::cout << remod(ans) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     long n;     scanf( %ld n , &n);     std::vector<long> blocks(n + 2);     for (long p = 1; p <= n; p++) {       scanf( %ld , &blocks[p]);     }     for (long p = 1; p <= n; p++) {       blocks[p] = std::min(blocks[p], 1 + blocks[p - 1]);     }     for (long p = n; p >= 0; p--) {       blocks[p] = std::min(blocks[p], 1 + blocks[p + 1]);     }     long final(0);     for (long p = 1; p <= n; p++) {       final = std::max(final, blocks[p]);     }     printf( %ld n , final);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000010;   int a[N], pos[N], cnt[N];   long long ans[N], res;   struct node {     int l, r, idx;     bool operator<(const node& x) const {       if (pos[l] == pos[x.l]) return r < x.r;       return l < x.l;     }   } q[N];   int L, R, n, m, k;   void update(int x, int add) {     if (add > 0) {       res += cnt[a[x] ^ k];       cnt[a[x]]++;     } else {       cnt[a[x]]--;       res -= cnt[a[x] ^ k];     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int sz = sqrt(n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       a[i] ^= a[i - 1];       pos[i] = i / sz;     }     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].idx = i;     }     sort(q + 1, q + m + 1);     cnt[0] = 1;     L = 1, R = 0, res = 0;     for (int i = 1; i <= m; ++i) {       while (q[i].l < L) update(--L - 1, 1);       while (q[i].l > L) update(L++ - 1, -1);       while (q[i].r < R) update(R--, -1);       while (q[i].r > R) update(++R, 1);       ans[q[i].idx] = res;     }     for (int i = 1; i <= m; ++i) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p, k;   long long r[20005];   int i, j;   int main() {     scanf( %I64d%I64d , &p, &k);     while (p) {       r[i] = p % (-k);       p = p / (-k);       while (r[i] < 0) {         r[i] = r[i] + k;         p++;       }       i++;     }     if (i == 0) i++;     for (j = 0; j < i; j++)       if (r[j] >= k) {         printf( -1 n );         return 0;       }     printf( %d n , i);     for (j = 0; j < i; j++) printf(j == i - 1 ?  %I64d n  :  %I64d  , r[j]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200 + 5;   string s;   int dist[maxn * maxn];   bool a[maxn][maxn], chek[maxn * maxn];   vector<int> v[maxn * maxn];   void bfs(int x) {     chek[x] = true;     queue<int> q;     q.push(x);     while (!q.empty()) {       x = q.front();       q.pop();       for (int i = 0; i < (int)v[x].size(); i++)         if (chek[v[x][i]] == false) {           q.push(v[x][i]);           chek[v[x][i]] = true;           dist[v[x][i]] = dist[x] + 1;         }     }   }   int main() {     int x = 102, y = 102, ii, jj, e[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};     cin >> s;     ii = x;     jj = y;     a[ii][jj] = true;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  U )         ii--;       else if (s[i] ==  D )         ii++;       else if (s[i] ==  R )         jj++;       else if (s[i] ==  L )         jj--;       a[ii][jj] = true;     }     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxn; j++)         for (int d = 0; d < 4; d++) {           if (a[i][j] == false) {             chek[i * maxn + j] = true;             continue;           }           if (i + e[d][0] >= 0 && i + e[d][0] < maxn && j + e[d][1] < maxn &&               j + e[d][1] >= 0)             if (a[i + e[d][0]][j + e[d][1]] == true)               v[i * maxn + j].push_back((i + e[d][0]) * maxn + j + e[d][1]);         }     bfs(x * maxn + y);     if (dist[ii * maxn + jj] < (int)s.size()) {       cout <<  BUG  << endl;       return 0;     }     cout <<  OK  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long const N = 2e5 + 70;   long long n, k, a[N], cnt[N], ans, fi = -1, la = -1;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 0; i <= n; i++) {       cin >> a[i];       cnt[i] = a[i];     }     for (long long i = 0; i < n + 50; i++) {       if (cnt[i] < 0) {         cnt[i + 1] += cnt[i];         cnt[i] = -cnt[i];       }       cnt[i + 1] += cnt[i] / 2;       cnt[i] &= 1;       if (cnt[i]) {         if (fi == -1) fi = i;         la = i;       }     }     if (cnt[n + 50]) {       fi = la = -1;       memset(cnt, 0, sizeof cnt);       for (long long i = 0; i <= n; i++) a[i] = -a[i], cnt[i] = a[i];       for (long long i = 0; i < n + 50; i++) {         if (cnt[i] < 0) {           cnt[i + 1] += cnt[i];           cnt[i] = -cnt[i];         }         cnt[i + 1] += cnt[i] / 2;         cnt[i] &= 1;         if (cnt[i]) {           if (fi == -1) fi = i;           la = i;         }       }     }     if (la - fi >= 35) return cout <<  0 n , 0;     long long res = 0;     for (long long i = fi; i <= la; i++) res += (1 << (i - fi)) * cnt[i];     long long cur = res;     for (long long i = fi; i >= 0 && cur <= 2e9; i--) {       if (i <= n && a[i] - cur >= -k && (i != n || a[i] - cur != 0)) ans++;       cur *= 2;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   const int MOD = 998244353;   int add(int x, int y) {     int res = x + y;     return res < MOD ? res : res - MOD;   }   int mul(int x, int y) { return (long long)x * y % MOD; }   int pow(int base, int p) {     int res = 1;     while (p > 0) {       if (p & 1) res = mul(res, base);       base = mul(base, base);       p /= 2;     }     return res;   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     std::vector<int> dp(std::min(k, n) + 1, 0);     dp[1] = n;     for (int i = 2; i <= k; ++i)       for (int j = std::min(i, n); j >= 1; --j)         dp[j] = add(mul(dp[j - 1], n - j + 1), mul(dp[j], j));     int res = 0;     for (int i = 1; i < dp.size(); ++i)       res = add(res, mul(dp[i], pow(pow(m, MOD - 2), i)));     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   int id(string s) {     if (s ==  C )       return 1;     else if (s ==  C# )       return 2;     else if (s ==  D )       return 3;     else if (s ==  D# )       return 4;     else if (s ==  E )       return 5;     else if (s ==  F )       return 6;     else if (s ==  F# )       return 7;     else if (s ==  G )       return 8;     else if (s ==  G# )       return 9;     else if (s ==  A )       return 10;     else if (s ==  B )       return 11;     else if (s ==  H )       return 12;   }   int Distance(string s, string t) {     int a = id(s);     int b = id(t);     if (b < a) b += 12;     return b - a;   }   int main() {     string x, y, z;     int i, j, k;     vector<string> v;     cin >> x >> y >> z;     v.push_back(x);     v.push_back(y);     v.push_back(z);     for (i = 0; i < 3; i++) {       for (j = 0; j < 3; j++) {         for (k = 0; k < 3; k++) {           if (Distance(v[i], v[j]) == 4 and Distance(v[j], v[k]) == 3) {             cout <<  major ;             return 0;           } else if (Distance(v[i], v[j]) == 3 and Distance(v[j], v[k]) == 4) {             cout <<  minor ;             return 0;           }         }       }     }     cout <<  strange ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string n;     cin >> n;     vector<string> vec;     int si = n.size();     for (int i = 0; i < si; i++) {       if (n[i] ==  0 ) continue;       string s =   ;       s += n[i];       for (int j = i + 1; j < si; j++) {         s +=  0 ;       }       vec.push_back(s);     }     cout << vec.size() <<   n ;     for (int i = 0; i < int(vec.size()); i++) {       cout << vec[i] <<    ;     }   }   int main() {     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static int aQWEs = []() -> int {     ios::sync_with_stdio(false);     cin.tie(NULL);     return 0;   }();   long long int power(long long int a, long long int p,                       long long int m = 1000000007) {     a %= m;     long long int val = 1;     while (p > 0) {       if (p & 1) {         val = (val * a) % m;       }       a = (a * a) % m;       p >>= 1;     }     return (val);   }   int dfs(const vector<int>& v, std::vector<bool>& vis, int cur, int depth) {     vis[cur] = 1;     if (!vis[v[cur]]) return dfs(v, vis, v[cur], depth + 1);     return depth;   }   int main() {     long long int i, j;     int T = 1;     while (T--) {       int n;       cin >> n;       std::vector<int> v(n + 1);       std::vector<bool> vis(n + 1);       int ans = 0;       for (i = 1; i <= n; ++i) {         cin >> v[i];       }       for (i = 1; i <= n; ++i) {         if (!vis[i]) ans += dfs(v, vis, i, 0);       }       if (!((3 * n - ans) & 1)) {         cout <<  Petr n ;       } else         cout <<  Um_nik n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   int N, w, W[100100], b, B[100100], C[100100], S[100100];   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int(i) = 1; (i) <= (N); (i)++) {       cin >> C[i] >> S[i];       if (C[i])         B[b++] = i;       else         W[w++] = i;     }     w--, b--;     while (w >= 0 && b >= 0) {       int s = min(S[W[w]], S[B[b]]);       cout << W[w] <<     << B[b] <<     << s << endl;       S[W[w]] -= s;       S[B[b]] -= s;       if (S[B[b]])         w--;       else         b--;     }     w--;     b--;     while (w >= 0) cout << W[w] <<     << B[0] <<     << 0 << endl, w--;     while (b >= 0) cout << W[0] <<     << B[b] <<     << 0 << endl, b--;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 3e5 + 10;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, q;   int cnt[M];   string ss;   void solve() {     cin >> n >> q;     cin >> ss;     for (int i = 1; i <= n; i++) {       if (i % 2)         cnt[i] = ss[i - 1] ==  +  ? 1 : -1;       else         cnt[i] = ss[i - 1] ==  -  ? 1 : -1;       cnt[i] += cnt[i - 1];     }     int l, r;     while (q--) {       cin >> l >> r;       int ans = cnt[r] - cnt[l - 1];       if (ans == 0)         cout << 0 << endl;       else if ((r - l + 1) % 2)         cout << 1 << endl;       else         cout << 2 << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     int T;     cin >> T;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int findLengthOfLNDS(vector<pair<int, float> > &plants_data) {     if (plants_data.size() == 0) return 0;     vector<int> m;     m.push_back(0);     for (int i = 1; i < plants_data.size(); i++) {       if (plants_data[m.back()].first <= plants_data[i].first) {         m.push_back(i);       } else {         int b = 0, e = m.size() - 1, mid = 0, replace_at = 0;         while (b <= e) {           mid = (b + e) / 2;           if (plants_data[i].first >= plants_data[m[mid]].first) {             b = mid + 1;           } else {             e = mid - 1;           }         }         if (plants_data[m[mid]].first <= plants_data[i].first) {           replace_at = mid + 1;         } else {           replace_at = mid;         }         m[replace_at] = i;       }     }     return m.size();   }   int main() {     int no_plants, no_species;     vector<pair<int, float> > plants_data;     cin >> no_plants >> no_species;     for (int i = 0; i < no_plants; i++) {       int speci;       float location;       cin >> speci >> location;       plants_data.push_back(make_pair(speci, location));     }     cout << no_plants - findLengthOfLNDS(plants_data);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n0, n1, n2;       cin >> n0 >> n1 >> n2;       if (n1 == 0 && n2 == 0) {         cout << string(n0 + 1,  0 ) << endl;         continue;       }       string result = string(n2 + 1,  1 );       char turn =  0 ;       while (n1--) {         result += turn;         if (turn ==  0 ) {           turn =  1 ;         } else {           turn =  0 ;         }       }       if (result[result.size() - 1] ==  0 ) {         result += string(n0,  0 );       } else {         result = result.substr(0, result.size() - 1);         result = result + string(n0,  0 ) +  1 ;       }       cout << result << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   string s;   bool flag;   void solve() {     int n, k;     cin >> n >> k;     unordered_set<int> s;     queue<int> q;     vector<int> a(n);     for (auto i = 0; i < n; i++) cin >> a[i];     ;     for (auto i = 0; i < n; i++) {       if (s.find(a[i]) == s.end()) {         if (s.size() >= k) {           int kk = q.front();           s.erase(kk);           q.pop();         }         s.insert(a[i]);         q.push(a[i]);       }     }     stack<int> st;     while (!q.empty()) {       int aa = q.front();       st.push(aa);       q.pop();     }     cout << st.size() << endl;     while (!st.empty()) {       int aa = st.top();       st.pop();       cout << aa <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5) + 10;   const int K = 11;   const int MOD = int(1e9) + 7;   const int INF = int(2e9) + 5;   const long long INF64 = 1e18;   int dp[N];   void solve() {     string s;     cin >> s;     stack<int> st;     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] ==  (  || s[i] ==  [  || s[i] ==  { ) {         st.push(i);       } else {         if (st.empty()) continue;         int t = st.top();         if (s[i] ==  )  && s[t] ==  ( ) {           dp[i] = i - t + 1;           if (t > 0) dp[i] += dp[t - 1];           st.pop();         } else if (s[i] ==  ]  && s[t] ==  [ ) {           dp[i] = i - t + 1;           if (t > 0) dp[i] += dp[t - 1];           st.pop();         } else if (s[i] ==  }  && s[t] ==  { ) {           dp[i] = i - t + 1;           if (t > 0) dp[i] += dp[t - 1];           st.pop();         } else {           while (!st.empty()) st.pop();         }       }     }     int i = n - 1;     int mx = 0, index = -1;     while (i >= 0) {       if (dp[i] == 0) {         i--;         continue;       }       int cnt = 0, t = i;       int x = dp[i];       for (int j = 0; j < x; j++) {         if (s[i] ==  [ ) cnt++;         i--;       }       if (cnt > mx) {         mx = cnt;         index = t;       }     }     if (mx == 0) {       cout << 0 <<   n ;       return;     }     cout << mx <<   n ;     cout << s.substr(index + 1 - dp[index], dp[index]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200005];   int main() {     int n;     int i;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       sort(a, a + n);       int p = (n - 2) / 2;       int ans = 1e9;       for (i = 0; i < n - p - 1; i++) {         int dis = a[i + p + 1] - a[i];         if (ans > dis) ans = dis;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10;   const int B = 1e3 + 10;   bool vis[N], inque[2 * N];   int n, k;   vector<int> v;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < k; i++) {       int t;       scanf( %d , &t);       if (!vis[t]) {         vis[t] = true;         v.push_back(t);       }     }     for (int i = 0; i < v.size(); i++) {       v[i] -= n;     }     queue<pair<int, int>> Q;     Q.push(make_pair(0, 0));     inque[B] = true;     while (!Q.empty()) {       pair<int, int> t = Q.front();       Q.pop();       inque[t.first + B] = 0;       for (int i = 0; i < v.size(); i++) {         int u = v[i] + t.first;         if (u < -1000 || u > 1000) continue;         if (!inque[u + B]) {           if (u == 0) {             printf( %d n , t.second + 1);             return 0;           }           inque[u + B] = true;           Q.push(make_pair(u, t.second + 1));         }       }     }     printf( -1 n );     return 0;   }