malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int INF = 1e9;   const int N = 150010;   int n, m, s, k;   int a[110][110];   int main() {     scanf( %d%d%d , &n, &m, &k);     int s0 = 0, s1 = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &a[i][j]);         if (a[i][j] == 0)           s0++;         else           s1++;       }     }     int ans = min(s0, s1);     int b[110], sum, tmp;     memset(b, 0, sizeof(b));     for (int i = 0; i < n; i++) {       sum = 0, tmp = 0;       for (int j = 0; j < m; j++) {         b[j] = a[i][j];       }       for (int j = 0; j < n; j++) {         if (j == i) continue;         tmp = 0;         for (int t = 0; t < m; t++) {           if (a[j][t] != b[t]) tmp++;         }         tmp = min(tmp, m - tmp);         sum += tmp;       }       ans = min(ans, sum);     }     memset(b, 0, sizeof(b));     for (int j = 0; j < m; j++) {       sum = 0, tmp = 0;       for (int i = 0; i < n; i++) {         b[i] = a[i][j];       }       for (int i = 0; i < m; i++) {         if (i == j) continue;         tmp = 0;         for (int t = 0; t < n; t++) {           if (a[t][i] != b[t]) tmp++;         }         tmp = min(tmp, n - tmp);         sum += tmp;       }       ans = min(ans, sum);     }     if (ans > k)       puts( -1 );     else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modulo = 1000000007;   int choose(int n, int r) {     if (n < r) {       return 0;     }     if (n == r || r == 0) {       return 1;     }     return choose(n - 1, r - 1) + choose(n - 1, r);   }   int get_factors(int n) {     int numFactors = 0;     for (int i = 1; i <= sqrt(n); i++) {       bool divisible = n % i == 0;       if (!divisible) {         continue;       }       int quotient = n / i;       numFactors++;       if (quotient != i) {         numFactors++;       }     }     return numFactors;   }   int sumDigits(int num) {     int sum = 0;     while (num > 0) {       sum += num % 10;       num /= 10;     }     return sum;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   vector<int> dfs(int i, vector<int> graph[], vector<bool>& visited) {     vector<int> group = {i};     vector<int> connected = graph[i];     visited[i] = true;     for (int j : connected) {       if (!visited[j]) {         vector<int> vals = dfs(j, graph, visited);         for (int val : vals) {           group.push_back(val);         }       }     }     return group;   }   bool comparePairs(pair<long long, long long> p1,                     pair<long long, long long> p2) {     if (p1.first < p2.first) {       return true;     } else if (p1.first > p2.first) {       return false;     } else {       return p1.second < p2.second;     }   }   vector<int> primes(int n) {     vector<int> p(n + 1);     for (int i = 0; i <= n; i++) {       p[i] = i;     }     p[0] = -1;     p[1] = -1;     for (int i = 2; i <= n; i++) {       if (p[i] == -1) {         continue;       }       int temp = i * i;       while (temp <= n) {         p[temp] = -1;         temp += i;       }     }     return p;   }   vector<long long> nextPrimes(long long n) {     vector<long long> p(n + 1, 0);     for (long long i = 0; i <= n; i++) {       p[i] = i;     }     p[0] = -1;     p[1] = -1;     for (long long i = 2; i <= n; i++) {       if (p[i] == -1) {         continue;       }       long long temp = i * i;       while (temp <= n) {         p[temp] = -1;         temp += i;       }     }     long long last = -1;     for (long long i = n; i >= 0; i--) {       if (p[i] == -1) {         p[i] = last;       } else {         last = p[i];       }     }     return p;   }   bool comparePairs(const pair<int, int>& lhs, const pair<int, int>& rhs) {     return abs(lhs.first - lhs.second) < abs(rhs.first - lhs.second);   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> want(k + 1);     vector<bool> taken(n * k + 1, false);     for (int i = 1; i < k + 1; i++) {       int iOfWant;       cin >> iOfWant;       want[i] = iOfWant;       taken[iOfWant] = true;     }     int curr = 1;     for (int i = 1; i < k + 1; i++) {       cout << want[i] <<    ;       for (int j = 0; j < n - 1; j++) {         while (taken[curr]) {           curr++;         }         cout << curr <<    ;         curr++;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t-- > 0) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   long long B;   long long A[100005], Ac[100005];   int main() {     cin >> N >> K >> B;     map<long long, int> ct;     for (int i = 0; i < N; i++) {       cin >> A[i];       ct[A[i]]++;     }     ct[A[N - 1]]--;     for (int i = 0; i < N - 1; i++) Ac[i] = A[i];     sort(Ac, Ac + N - 1);     reverse(Ac, Ac + N - 1);     if (K >= N) K = N - 1;     long long presum = 0;     long long nth = Ac[K - 1];     for (int i = 0; i < K; i++) presum += Ac[i];     for (int i = 0; i < N - 1; i++) {       long long s = presum - max(nth, A[i]);       if (s + A[i] > B) {         cout << i + 1 <<   n ;         return 0;       }     }     cout << N <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int nax = 2e5;   int par[nax], dp[nax];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> prev;     int ma = -1, mai;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       dp[i] = 1;       par[i] = -1;       if (prev.count(a - 1)) {         par[i] = prev[a - 1];         dp[i] = dp[prev[a - 1]] + 1;       }       if (dp[i] > ma) {         ma = dp[i];         mai = i;       }       prev[a] = i;     }     cout << ma << endl;     int p = mai;     vector<int> path;     while (p != -1) {       path.push_back(p);       p = par[p];     }     reverse(path.begin(), path.end());     for (int i : path) cout << i + 1 <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     while (a--) {       int b, c;       cin >> b >> c;       int n = abs(b - c);       n = n / 5 + (n % 5) / 2 + (n % 5) % 2;       cout << n <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<long long> buckets[30];   long long bsum[30];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q, tot = 0;     cin >> q;     while (q--) {       char c;       long long x;       cin >> c >> x;       int p = 31 - __builtin_clz(x), ans = 0;       if (c ==  + )         buckets[p].insert(x), bsum[p] += x, tot++;       else         buckets[p].erase(buckets[p].find(x)), bsum[p] -= x, tot--;       long long sm = 0;       for (int i = 0; i < 30; i++)         if (buckets[i].size()) {           if (*buckets[i].begin() > 2 * sm) ans++;           sm += bsum[i];         }       cout << tot - ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   int n;   int cnt[1 << 20];   int cnt2[1 << 20];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     ll res = 0;     ++cnt2[0];     for (int pref = 0, a, i = 1; i <= n; ++i) {       cin >> a;       pref ^= a;       if (i & 1) {         res += cnt[pref];         ++cnt[pref];       } else {         res += cnt2[pref];         ++cnt2[pref];       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_set<int> si;   int fff = 0;   int fj = 2;   void mmin(int &t) {     for (int j = fj; 1;) {       int fflag = 0;       vector<int> pr;       for (int i = 2; i < sqrt(j) + 1; i++) {         if (j % i == 0) {           if (si.find(i) == si.end() && si.find(j / i) == si.end()) {             pr.push_back(i);             pr.push_back(j / i);           } else {             fflag = 2;             break;           }         }       }       if (fflag == 0 && si.find(j) == si.end()) {         for (auto tt : pr) si.insert(tt);         si.insert(j);         t = j;         fj = j + 1;         fff = 1;         break;       }       if (j % 2 == 0)         j++;       else         j += 2;     }   }   void check(int &t) {     vector<int> prime;     int flag = 0;     for (int i = 2; i < sqrt(t) + 1; i++) {       if (t % i == 0) {         if (si.find(i) == si.end())           prime.push_back(i);         else {           flag = 1;           break;         }         if (si.find(t / i) == si.end())           prime.push_back(t / i);         else {           flag = 1;           break;         }       }     }     if (si.find(t) == si.end())       prime.push_back(t);     else {       flag = 1;     }     if (flag) {       for (int j = t + 1; 1; j++) {         int fflag = 0;         for (int i = 2; i < sqrt(j) + 1; i++) {           if (j % i == 0) {             if (si.find(i) == si.end() && si.find(j / i) == si.end())               ;             else {               fflag = 2;               break;             }           }         }         if (fflag == 0 && si.find(j) == si.end()) {           for (int i = 2; i < max((int)sqrt(j) + 1, j); i++)             if (j % i == 0) {               si.insert(i);               si.insert(j / i);             }           si.insert(j);           t = j;           fff = 1;           break;         }       }     } else {       for (auto tt : prime) si.insert(tt);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> ans;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (t == 1) {         ans.push_back(t);         continue;       }       if (fff == 1)         mmin(t);       else         check(t);       ans.push_back(t);     }     for (auto t : ans) cout << t <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 2000005;   const int INF = 0x3f3f3f3f;   struct Num {     int a, b;     Num() {}     Num(int x, int y) : a(x), b(y) {}     bool operator<(const Num &y) const { return a == y.a ? b < y.b : a < y.a; }     bool operator>(const Num &y) const { return a == y.a ? b > y.b : a > y.a; }     bool operator==(const Num &y) const { return a == y.a && b == y.b; }     Num operator+(const Num &y) const { return Num(a + y.a, b + y.b); }   };   struct State {     Num n;     int base;     long long route;     bool operator<(const State &b) const { return n < b.n; }     bool operator==(const State &b) const { return n == b.n; }   };   bool cmp(const State &a, const State &b) {     return a.n == b.n ? a.base > b.base : a.n < b.n;   }   State sta[MaxN];   int cou;   int N;   Num rem[30][3];   int rnum[30];   int bbb;   long long lll;   void dfs1(int d, Num tn, int b, long long l) {     if (d > ((N + 1) >> 1)) {       sta[cou].n = tn;       sta[cou].base = b;       sta[cou++].route = l;       return;     }     for (int i = 0; i < 3; ++i)       dfs1(d + 1, tn + rem[d][i], b + (i ? rnum[d] : 0), (l << 2) | i);   }   void dfs2(int d, Num tn, int b, long long l) {     if (d > N) {       State ts;       ts.n.a = -tn.a;       ts.n.b = -tn.b;       int p = lower_bound(sta, sta + cou, ts) - sta;       if (p < cou && sta[p] == ts && sta[p].base + b > bbb) {         bbb = sta[p].base + b;         lll = (sta[p].route << (2 * (N / 2))) | l;       }       return;     }     for (int i = 0; i < 3; ++i)       dfs2(d + 1, tn + rem[d][i], b + (i ? rnum[d] : 0), (l << 2) | i);   }   void show() {     int rrr[30];     for (int i = 0; i < N; ++i) {       rrr[i] = lll & 3;       lll >>= 2;     }     for (int i = N - 1; i >= 0; --i)       if (rrr[i] == 0)         puts( MW );       else if (rrr[i] == 1)         puts( LW );       else         puts( LM );   }   int main() {     int a, b, c;     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %d %d %d , &a, &b, &c);       rnum[i] = a;       rem[i][0] = Num(b, c);       rem[i][1] = Num(-a, c - a);       rem[i][2] = Num(b - a, -a);     }     cou = 0;     bbb = -INF;     dfs1(1, Num(0, 0), 0, 0);     sort(sta, sta + cou, cmp);     cou = unique(sta, sta + cou) - sta;     dfs2((N + 1) / 2 + 1, Num(0, 0), 0, 0);     if (bbb == -INF)       puts( Impossible );     else       show();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long expo(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }   vector<long long> sieve(int n) {     int* arr = new int[n + 1]();     vector<long long> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long mod_div(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   int fact[N];   void precalc() {     fact[0] = 1;     for (int i = 1; i < N; i++) {       fact[i] = mod_mul(fact[i - 1], i, 1000000007);     }   }   long long mod(long long x) {     return ((x % 1000000007 + 1000000007) % 1000000007);   }   long long inv(long long x) { return expo(x, 1000000007 - 2, 1000000007); }   long long divide(long long a, long long b) {     return mod_mul(a, inv(b), 1000000007);   }   long long nCr(long long n, long long r) {     return divide(fact[n], mod_mul(fact[r], fact[n - r], 1000000007));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       string s;       cin >> s;       map<char, long long> m;       long long cnt = 0;       for (int i = 0; i < s.length(); i++) {         m[s[i]]++;       }       for (auto x : m) {         if (x.second <= 2)           cnt += x.second;         else           cnt += 2;       }       if (cnt % 2 != 0) cnt--;       cout << cnt / 2 << (  n );     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const long long int INF = 2e18;   char mode[5002 / 2][5002];   short int cup[4][5002 / 2][5002];   short int up[4][5002 / 2][5002];   int best = 0, cnt = 0;   inline int geti(int type, int x, int y) {     if (up[type][x][y] == -1 || (type >= 2 && up[type][x][y] == x) ||         (type < 2 && up[type][x][y] == y))       return up[type][x][y];     int nex = up[type][x][y];     if (type >= 2) return up[type][x][y] = geti(type, nex, y);     return up[type][x][y] = geti(type, x, nex);   }   inline void upd(int x, int y) {     for (int i = 0; i < 2; i++) {       int plus = (!i ? -1 : 1);       up[i][x][y] = y + plus;     }     for (int i = 0; i < 2; i++) {       int plus = (!i ? -1 : 1);       up[i + 2][x][y] = x + plus;     }   }   int n, m;   int dfs(int i, int j) {     char c = mode[i][j];     upd(i, j);     int out = 1;     if (c ==  L ) {       int nex = geti(0, i, j);       if (nex != -1 && nex < m) out = dfs(i, nex) + 1;     }     if (c ==  R ) {       int nex = geti(1, i, j);       if (nex != -1 && nex < m) out = dfs(i, nex) + 1;     }     if (c ==  U ) {       int nex = geti(2, i, j);       if (nex != -1 && nex < n) out = dfs(nex, j) + 1;     }     if (c ==  D ) {       int nex = geti(3, i, j);       if (nex != -1 && nex < n) out = dfs(nex, j) + 1;     }     if (out > best) {       best = out;       cnt = 0;     }     if (out == best) cnt++;     return out;   }   int main() {     cin >> n >> m;     char c;     scanf(  n );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %c , &c);         if (n < m)           mode[i][j] = c;         else {           if (c ==  U )             c =  R ;           else if (c ==  R )             c =  D ;           else if (c ==  D )             c =  L ;           else if (c !=  . )             c =  U ;           mode[j][n - 1 - i] = c;         }         if (c ==  . ) continue;       }       scanf(  n );     }     if (n >= m) swap(n, m);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         cup[1][i][j] = m;         cup[3][i][j] = n;       }     }     vector<int> pre(m, -1);     for (int i = 0; i < n; i++) {       int pp = -1;       for (int j = 0; j < m; j++) {         if (mode[i][j] !=  . ) {           pre[j] = i;           pp = j;         }         cup[0][i][j] = pp;         cup[2][i][j] = pre[j];       }     }     pre.assign(m, n);     for (int i = n - 1; i >= 0; i--) {       int pp = m;       for (int j = m - 1; j >= 0; j--) {         if (mode[i][j] !=  . ) {           pre[j] = i;           pp = j;         }         cup[1][i][j] = pp;         cup[3][i][j] = pre[j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < 4; k++) {           for (int i2 = 0; i2 <= n; i2++) {             for (int j2 = 0; j2 <= m; j2++) {               up[k][i2][j2] = cup[k][i2][j2];             }           }         }         if (mode[i][j] !=  . ) dfs(i, j);       }     }     cout << best <<     << cnt;   }
#include <bits/stdc++.h>   using namespace std;   long long totalSum;   long long check(long long a, long long b, long long c, long long r) {     if (b + c > a) {       return 0;     }     long long d = min(r, a - b - c);     return (d + 2) * (d + 1) / 2;   }   int main() {     long long a, b, c, l, total;     cin >> a >> b >> c >> l;     totalSum = a + b + c + l;     total = (l + 3) * (l + 2) * (l + 1) / 6;     for (long long i = 0; i <= l; i++) {       total -= check(a + i, b, c, l - i);       total -= check(b + i, a, c, l - i);       total -= check(c + i, b, a, l - i);     }     cout << total <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> A[55];   double pos[55][55];   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first > b.first)       return 1;     else if (a.first < b.first)       return 0;     else {       return a.second <= b.second;     }   }   bool vis[55][55];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> A[i].first;     for (int i = 1; i <= n; ++i) cin >> A[i].second;     sort(A + 1, A + n + 1, comp);     long long low = 0;     long long high = 10000000000000;     int count = 10000;     while (--count) {       long long mid = low + high;       mid /= 2.0;       for (int i = 0; i <= n; ++i) {         for (int j = 0; j <= n; ++j) {           vis[i][j] = 0;         }       }       pos[0][0] = 0;       vis[0][0] = 1;       for (int i = 1; i <= n; ++i) {         long long st = A[i].first;         int u = i - 1;         while (i <= n && A[i].first == st) ++i;         --i;         int coun = i - u;         long long sum[55];         for (int j = u + 1; j <= i; ++j) sum[j - u] = 0;         sum[0] = 0;         for (int j = u + 1; j <= i; ++j)           sum[j - u] = sum[j - u - 1] + A[j].second;         long long sum2[55];         for (int j = u + 1; j <= i; ++j) sum2[j - u] = 0;         sum2[0] = 0;         for (int j = u + 1; j <= i; ++j)           sum2[j - u] = sum2[j - u - 1] + A[j].first;         for (int j = 0; j <= u; ++j) {           for (int l = 0; l <= min(coun, j); ++l) {             if (vis[u][j] == 0) continue;             int rem = j - l + coun - l;             if (vis[i][rem] == 0) {               vis[i][rem] = 1;               pos[i][rem] = pos[u][j] - (sum[coun] - sum[l]) * mid / 1000.0 +                             (sum2[coun] - sum2[l]);             } else               pos[i][rem] = min(pos[i][rem],                                 pos[u][j] - (sum[coun] - sum[l]) * mid / 1000.0 +                                     (sum2[coun] - sum2[l]));           }         }       }       bool flag = 0;       for (int j = 0; j <= n; ++j) {         if (pos[n][j] <= 0 && vis[n][j]) {           flag = 1;         }       }       if (flag) {         high = mid;       } else {         low = mid + 1;       }     }     cout << high << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, i, j, mn, mx;     scanf( %ld %ld , &n, &m);     long a[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         scanf( %ld , &a[i][j]);       }     }     mx = 0;     for (i = 0; i < n; i++) {       mn = LONG_MAX;       for (j = 0; j < m; j++) {         mn = min(a[i][j], mn);       }       mx = max(mn, mx);     }     printf( %ld , mx);   }
#include <bits/stdc++.h>   using namespace std;   long long pwr(long long a, long long b, long long mod) {     a %= mod;     if (a < 0) a += mod;     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b /= 2;     }     return ans;   }   long long pwr(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     while (b) {       long long temp = a;       a = b;       b = temp % b;     }     return a;   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long modularInverse(long long a, long long m) {     assert(false);     return pwr(a, m - 2, m);   }   int main(int argc, char const *argv[]) {     std::ios::sync_with_stdio(false);     int n, m, num1, num2;     cin >> n >> m;     if (n > m) {       num1 = n;       num2 = m;     } else {       num1 = m;       num2 = n;     }     long long sum = 0;     while (num2 != 0 && num1 >= 2) {       sum++;       num2--;       num1 = num1 - 2;       if (num1 < num2) {         swap(num1, num2);       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   const int INF = 1000000000;   const long long LINF = 1000000000000000000;   const long long MOD = 1000000007;   const double PI = acos(-1.0);   const double EPS = 1e-10;   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline void add(T& a, T b) {     a = ((a + b) % MOD + MOD) % MOD;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n, z;     cin >> n >> z;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     int ans = 0;     int i = 0, j = n / 2;     while (i < n / 2 && j < n) {       if (a[j] - a[i] >= z) {         ans++;         i++;         j++;       } else         j++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline int setBit(int N, int pos) { return N = N | (1 << pos); }   inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); }   inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }   int main() {     long long n, k, x, sum = 0;     scanf( %lld %lld , &n, &k);     while (n--) {       scanf( %lld , &x);       sum += (x / k) + (bool)(x % k);     }     printf( %lld n , sum / 2 + (bool)(sum % 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void in() {}   int main() {     in();     int n;     cin >> n;     int arr[n + 10], ps[n + 10];     for (int i = 0; i < n; ++i) {       scanf( %d , arr + i);       ps[arr[i]] = i + 1;     }     ps[0] = ps[n + 1] = -1;     int a = 0, pre = 1;     for (int i = 1; i <= n + 1; ++i) {       if (ps[i - 1] < ps[i]) continue;       a = max(a, i - pre);       pre = i;     }     cout << (n - a) << endl;     return 0;   }