malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)(1e5) + 123;   const int INF = (int)(1e9);   int n, a[maxn], t[4 * maxn], tt;   pair<int, int> b[maxn];   int gcd(int a, int b) {     while (a > 0 && b > 0) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   void build(int v, int tl, int tr) {     if (tl == tr)       t[v] = a[tl];     else {       int tm = (tl + tr) / 2;       build(v + v, tl, tm);       build(v + 1 + v, tm + 1, tr);       t[v] = gcd(t[v + v], t[v + 1 + v]);     }   }   int get(int v, int tl, int tr, int l, int r) {     if (l > tr || r < tl) return 0;     if (l <= tl && r >= tr) return t[v];     int tm = (tl + tr) / 2;     return gcd(get(v + v, tl, tm, l, r), get(v + 1 + v, tm + 1, tr, l, r));   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = make_pair(a[i], i);     }     sort(b + 1, b + 1 + n);     build(1, 1, n);     cin >> tt;     for (int i = 1; i <= tt; ++i) {       int l, r;       cin >> l >> r;       int cur = get(1, 1, n, l, r);       pair<int, int> now = make_pair(cur, l);       int to = (lower_bound(b + 1, b + 1 + n, now) - (b + 1));       now = make_pair(cur, r + 1);       int from = (lower_bound(b + 1, b + 1 + n, now) - (b + 1));       cout << (r - l + 1) - (from - to) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int maxn = 5e5 + 5;   char st1[maxn], st2[maxn];   long long ans = 0, pre = 0;   int n, k;   int main() {     n = read(), k = read();     scanf( %s , st1);     scanf( %s , st2);     for (int i = 0; i <= n - 1; i++) {       pre = min(pre * 2 + (int)(st2[i] - st1[i]), 1ll << 36);       ans += min(pre + 1, (long long)k);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   const int maxn = 3e5 + 10;   const int maxm = 1e6 + 10;   const long long mod = 998244353;   int a[maxn], b[maxn];   bool judge(int mid, int h) {     int temph = h;     for (int i = 0; i < mid; i++) b[i] = a[i];     sort(b, b + mid);     int ans = 0;     for (int i = 0; i < mid; i += 2) {       if (b[i] <= h) ans++;       if (i + 1 < mid && b[i + 1] <= h) ans++;       if (i == mid - 1)         h -= b[i];       else         h -= b[i + 1];       if (h <= 0) break;     }     if (ans >= mid) return true;     ans = 0, h = temph;     for (int i = mid - 1; i >= 0; i -= 2) {       if (b[i] <= h) ans++;       if (i - 1 >= 0 && b[i - 1] <= h) ans++;       h -= b[i];       if (h <= 0) break;     }     return ans >= mid;   }   int main() {     int n, h;     cin >> n >> h;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 1;     int l = 1, r = n;     while (l <= r) {       int mid = (l + r) >> 1;       if (judge(mid, h))         l = mid + 1, ans = mid;       else         r = mid - 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p_arr[200005];   int main() {     int n, in, cnt, x, arr[200005];     std::cin >> n;     queue<int> q;     for (int i = 1; i <= n; i++) {       std::cin >> in;       q.push(in);     }     for (int i = 1; i <= n; i++) {       std::cin >> arr[i];     }     cnt = 0;     for (int i = 1; i <= n; i++) {       x = q.front();       while (p_arr[x] == -1) {         q.pop();         x = q.front();       }       x = q.front();       if (x == arr[i]) {         q.pop();       } else {         cnt++;         p_arr[arr[i]] = -1;       }     }     std::cout << cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char g[21][21];   int n, m, id[21][21], cv, cb, var[(1 << 8)],       dr[] = {1, 0, -1, 0}, dc[] = {0, 1, 0, -1}, d[21][21][(1 << 8)];   bool inq[21][21][(1 << 8)];   struct node {     int r, c, msk;   };   queue<node> q;   vector<node> b;   void input() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (n); i++) scanf( %s , g[i]);     memset(id, -1, sizeof(id));     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (isdigit(g[i][j])) id[i][j] = g[i][j] -  1 , cv++;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (g[i][j] ==  B ) id[i][j] = cv + (cb++);     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++) {         if (g[i][j] ==  B ) b.push_back((node){i, j, (1 << id[i][j] >> cv)});         if (isdigit(g[i][j])) b.push_back((node){i, j, (1 << id[i][j] << cb)});       }     for (int i = 0; i < (cv); i++) scanf( %d , &var[1 << i]);   }   int lowbit(int x) { return x & (-x); }   void pretreat() {     for (int i = 0; i < ((1 << 8)); i++)       if (i) var[i] = var[i - lowbit(i)] + var[lowbit(i)];   }   bool invalid(node cur) {     if (cur.r < 0 || cur.r >= n || cur.c < 0 || cur.c >= m) return true;     if (id[cur.r][cur.c] != -1) return true;     if (g[cur.r][cur.c] ==  # ) return true;     return false;   }   void updata(node nxt, int x) {     if (d[nxt.r][nxt.c][nxt.msk] == -1 || d[nxt.r][nxt.c][nxt.msk] > x) {       d[nxt.r][nxt.c][nxt.msk] = x;       if (!inq[nxt.r][nxt.c][nxt.msk]) {         inq[nxt.r][nxt.c][nxt.msk] = 1;         q.push(nxt);       }     }   }   int bfs() {     memset(d, -1, sizeof(d));     memset(inq, 0, sizeof(inq));     node cur, nxt;     int ans = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (g[i][j] ==  S ) {           q.push((node){i, j, 0});           d[i][j][0] = 0;           inq[i][j][0] = 1;           break;         }     while (!q.empty()) {       cur = q.front();       q.pop();       inq[cur.r][cur.c][cur.msk] = 0;       if (g[cur.r][cur.c] ==  S  && ((cur.msk & ((1 << cb) - 1)) == 0))         ans = max(ans, var[cur.msk >> cb] - d[cur.r][cur.c][cur.msk]);       for (int i = 0; i < (4); i++) {         nxt.r = cur.r + dr[i];         nxt.c = cur.c + dc[i];         if (invalid(nxt)) continue;         if (i & 1) {           nxt.msk = cur.msk;           for (int j = 0; j < ((int)b.size()); j++) {             if (i == 1) {               if (b[j].r > nxt.r && b[j].c == nxt.c) nxt.msk ^= b[j].msk;             } else {               if (b[j].r > cur.r && b[j].c == cur.c) nxt.msk ^= b[j].msk;             }           }         } else           nxt.msk = cur.msk;         updata(nxt, d[cur.r][cur.c][cur.msk] + 1);       }     }     return ans;   }   int main() {     input();     pretreat();     printf( %d n , bfs());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     ;     vector<int> v(n);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     ;     int diff = 0;     int ans = v[0];     for (int i = 0; i < n - 1; i++) {       diff += (v[i] - v[i + 1]);       if (diff < 0) {         ans = ans + abs(diff);         diff = 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int x;   int a[1000];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < 2 * n + 1; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < 2 * n + 1; i++) {       if (i % 2 == 1 && k > 0 && a[i] > a[i - 1] + 1 && a[i] > a[i + 1] + 1) {         printf( %d  , a[i] - 1);         k--;       } else         printf( %d  , a[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005], mi, mid, ma;   long long m, sum;   bool b[100005], flag;   bool check() {     long long sum = 0;     for (int i = 0; i < n; i++) sum += min(a[i], mid);     return sum <= m;   }   int main() {     cin >> n >> m;     sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (sum < m) {       printf( -1 n );     } else if (sum == m) {       printf(  n );     } else {       mi = 0;       ma = 1000000000;       while (mi < ma) {         mid = (mi + ma + 1) >> 1;         if (check())           mi = mid;         else           ma = mid - 1;       }       for (int i = 0; i < n; i++) {         m -= min(a[i], mi);         a[i] -= min(a[i], mi);       }       memset(b, true, sizeof(b));       flag = false;       for (int i = 0; b[i]; i = (i + 1) % n) {         if (a[i]) {           if (m) {             a[i]--;             m--;           } else {             if (flag) printf(   );             flag = true;             b[i] = false;             printf( %d , i + 1);           }         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000005;   int lp[N + 1];   vector<int> pr, adj[100005];   vector<int> v[N];   int a[N], ans[100005], depth[100005];   void seive() {     for (int i = 2; i <= N; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)         lp[i * pr[j]] = pr[j];     }   }   void dfs(int s, int p) {     int x = a[s];     while (x > 1) {       int te = lp[x];       while (x % te == 0) x /= te;       int sz = v[te].size();       if (sz > 0) {         ;         if (ans[s] == -1 || depth[ans[s]] < depth[v[te][sz - 1]])           ans[s] = v[te][sz - 1];       }       v[te].push_back(s);     }     for (auto it : adj[s]) {       if (it != p) {         depth[it] = depth[s] + 1;         dfs(it, s);       }     }     x = a[s];     while (x > 1) {       int te = lp[x];       while (x % te == 0) x /= te;       v[te].pop_back();     }   }   int main() {     int n, q, i;     seive();     scanf( %d%d , &n, &q);     memset(ans, -1, sizeof(ans));     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       adj[a - 1].push_back(b - 1);       adj[b - 1].push_back(a - 1);     }     dfs(0, -1);     while (q--) {       int type, v;       scanf( %d%d , &type, &v);       if (type == 1) {         if (ans[v - 1] == -1) ans[v - 1] = -2;         printf( %d n , ans[v - 1] + 1);       } else {         int w;         scanf( %d , &w);         a[v - 1] = w;         memset(ans, -1, sizeof(ans));         dfs(0, -1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, y;     cin >> n >> x >> y;     set<double> s;     int count = 0;     while (n--) {       double m;       double a, b;       cin >> a >> b;       a -= x;       b -= y;       if (a != 0) {         m = b / a;         s.insert(m);       } else {         count++;       }     }     cout << (count > 0) + s.size() << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int nMAX = 20;   long long comb[nMAX][nMAX];   long long mem[10][20];   int cnt[10];   long long nCr(int n, int k) {     if (n < k) return 0;     if (k == 0 || n == 0) return 1;     if (~comb[n][k]) return comb[n][k];     if (n - k < k) return comb[n][k] = nCr(n, n - k);     return comb[n][k] = nCr(n - 1, k - 1) + nCr(n - 1, k);   }   long long dp(int digit, int mad) {     if (digit == 10) return 1;     long long &ret = mem[digit][mad];     ret = 0;     if (!cnt[digit]) ret = dp(digit + 1, mad);     for (int takenSoFar = 1; takenSoFar < (int)cnt[digit] + 1; ++takenSoFar)       ret +=           nCr(digit == 9 ? takenSoFar + mad - 1 : takenSoFar + mad, takenSoFar) *           dp(digit + 1, mad + takenSoFar);     return ret;   }   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(mem, -1, sizeof mem);     memset(comb, -1, sizeof comb);     cin >> s;     for (int i = 0; i < (int)(int)s.size(); ++i) cnt[s[i] -  0 ]++;     reverse(cnt, cnt + 10);     cout << dp(0, 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int coolness[6001];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       fill(coolness, coolness + 6001, 0);       for (int i = 0; i < n; i++) {         int temp;         scanf( %d , &temp);         coolness[temp]++;       }       int cost = 0;       for (int i = 1; i <= n; i++) {         for (; coolness[i] > 1; coolness[i]--) {           for (int j = i + 1;; j++) {             if (coolness[j] == 0) {               coolness[j]++;               cost += j - i;               break;             }           }         }       }       printf( %d n , cost);     }   }
#include <bits/stdc++.h>   using namespace std;   int t[1000006], c[1000006];   int main() {     int n, a, i, x;     scanf( %d , &n);     scanf( %d , &a);     t[a] = 1;     for (i = 0; i < n; i++) {       scanf( %d , &x);       if (x == a) {         c[x]++;       } else {         c[x]++;         if (c[x] <= c[a]) {           t[x] = 1;         }       }     }     for (i = 1; i <= 1000000; i++) {       if (!t[i] && c[i] >= c[a]) {         cout << i;         return 0;       }     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   int main() {     const int N = 3 * 3;     bool buttons[N] = {0};     int k(0);     while (k < N) {       char temp;       scanf( %c , &temp);       if (temp ==  X ) {         buttons[k++] = 1;       } else if (temp ==  . ) {         buttons[k++] = 0;       }     }     bool symmetric(1);     for (int k = 0; k < N; k++) {       if (buttons[k] != buttons[N - 1 - k]) {         symmetric = 0;         break;       }     }     if (symmetric) {       puts( YES );     } else {       puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   int main() {     int n, k;     scanf( %d%d , &n, &k);     vector<int> ans;     int a = (n - k) / 2;     while (ans.size() < n) {       for (int i = 0; i < a; i++) ans.push_back(0);       ans.push_back(1);     }     for (int i = 0; i < n; i++) printf( %d , ans[i]);     puts(  );   }
#include <bits/stdc++.h>   long long mod = 1000000007;   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void solve() {     long long n;     cin >> n;     long long odd = 0, even = 0;     string s = to_string(n);     for (int i = 0; i < s.size(); i++) {       long long d = s[i] -  0 ;       if (i % 2 == 0) {         even = (even * 10) + d;       } else {         odd = (odd * 10) + d;       }     }     long long ans = ((even + 1) * (odd + 1)) - 2;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int n, a[100001], i;   int d[100001], k = 1;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       d[a[i]]++;     }     for (i = 0; i < n; i++) {       if (d[a[i]] == 1 && a[i] <= n) {         printf( %d  , a[i]);       } else {         while (d[k]) k++;         d[a[i]]--;         printf( %d  , k);         d[k]++;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     {       for (auto &e : (a)) cin >> e;     }     sort((a).begin(), (a).end());     vector<int> used(1, a[0]);     for (auto e : a) {       bool go = 0;       for (auto ee : used) {         if (e % ee == 0) {           go = 1;         }       }       if (!go) used.push_back(e);     }     cout << used.size();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double v1, v2, s1, s2, t, f, c;     double m;     int co;     while (cin >> v1 >> v2 >> t >> f >> c) {       if (v2 <= v1)         cout << 0 << endl;       else {         s1 = t * v1;         s2 = 0;         m = v2 - v1;         co = 0;         while (s1 < c) {           s1 += (s1 / m) * v1;           if (s1 >= c) break;           co++;           s1 += (s1 / v2 + f) * v1;         }         cout << co << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30);   const long long llinf = (1ll << 60);   const double eps = (1e-10);   const int xx[8] = {1, 0, -1, 0, 1, -1, 1, -1};   const int yy[8] = {0, 1, 0, -1, -1, 1, -1, 1};   int main() {     int n;     scanf( %d , &n);     int cnt[10] = {0};     bool fl = true;     char input[4][4];     getchar();     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         char x;         scanf( %c , &x);         if (x ==  . ) continue;         cnt[x -  0 ]++;         if (cnt[x -  0 ] > (n * 2)) fl = false;       }       getchar();     }     if (fl)       cout <<  YES n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long L = 1e9;   int n, m, p, r, par[N];   long long size[N];   vector<int> adj[N];   vector<pair<long long, int> > ans;   priority_queue<pair<long long, int> > q;   int find_par(int v) { return par[v] == v ? v : par[v] = find_par(par[v]); }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> p >> r;     if (!m && r == n) {       cout << (p ?  NO  :  YES ) <<   n ;       return 0;     }     for (int i = 0; i < n; i++) par[i] = i, size[i] = 0;     for (int i = 0; i < m; i++) {       int u, v, l;       cin >> u >> v >> l;       u = find_par(--u), v = find_par(--v);       if (u != v) par[u] = v, size[v] += size[u];       size[v] += l;     }     for (int i = 0; i < n; i++)       if (par[i] == i) q.push(pair<long long, int>(-size[i], i));     while (p && q.size() > r) {       p--;       pair<long long, int> a, b;       a = q.top(), q.pop();       b = q.top(), q.pop();       long long l = min(L, -a.first + -b.first + 1);       q.push(pair<long long, int>(a.first + b.first - l, a.second));       ans.push_back(pair<long long, int>(a.second + 1, b.second + 1));       par[b.second] = a.second;     }     if (q.size() != r)       cout <<  NO n ;     else {       cout <<  YES n ;       for (int i = 0; i < ans.size(); i++)         cout << ans[i].first <<     << ans[i].second <<   n ;       for (int v = 0; v < n; v++)         if (par[v] != v) {           while (p--) cout << v + 1 <<     << par[v] + 1 <<   n ;           break;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long i, j;   long long const size = 1e5;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   long long modd(string num, long long a) {     int res = 0;     for (int i = 0; i < num.length(); i++)       res = (res * 10 + (int)num[i] -  0 ) % a;     return res;   }   int check_xor(int n) {     if ((n % 4) == 0)       return n;     else if ((n % 4) == 1)       return 1;     else if ((n % 4) == 2)       return n + 1;     else       return 0;   }   vector<long long> sieve(long long n) {     vector<bool> prime(n + 1, true);     prime[0] = false;     prime[1] = false;     long long range = sqrt(n);     for (i = 2; i <= range; i++) {       if (prime[i]) {         for (j = i * 2; j <= n; j = j + i) {           prime[j] = false;         }       }     }     vector<long long> ans;     for (i = 0; i < n; i++) {       if (prime[i]) ans.push_back(i);     }     return ans;   }   bool iszero(long long n) { return n == 0; }   vector<long long> sieve_range(long long s, long long e) {     vector<long long> v1 = sieve(s);     vector<long long> v2 = sieve(e);     vector<long long> ans(e - s);     set_difference(v2.begin(), v2.end(), v1.begin(), v1.end(), ans.begin());     auto it = remove_if(ans.begin(), ans.end(), iszero);     ans.resize(it - ans.begin());     return ans;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       if (n * 2 <= m)         cout << n <<     << 2 * n <<   n ;       else         cout << -1 <<     << -1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000 + 10;   const int MAXM = 600000 + 10;   int a[64][64];   int ans, n, m;   inline int sg(int x) { return 1 - 2 * x; }   inline int sg(int s, int x) { return sg(s >> x & 1); }   int main() {     ios::sync_with_stdio(false);     cin >> n;     m = n >> 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     int ans = 0;     for (int s = 0; s < (1 << m + 1); s++) {       int ret = a[m][m] * sg(s, m);       for (int j = 0; j < m; j++)         ret +=             a[m][j] * sg(s, j) + a[m][j + m + 1] * sg(s >> j & 1 ^ (s >> m & 1));       for (int i = 0; i < m; i++) {         int tmp1 = a[i][m] + a[i + m + 1][m] * sg(s, m);         int tmp2 = -tmp1;         for (int j = 0; j < m; j++)           tmp1 += abs(a[i][j] + a[i + m + 1][j] * sg(s, j) + a[i][j + m + 1] +                       a[i + m + 1][j + m + 1] * sg(s >> j & 1 ^ (s >> m & 1)));         for (int j = 0; j < m; j++)           tmp2 +=               abs(a[i][j] + a[i + m + 1][j] * sg(s, j) - a[i][j + m + 1] +                   a[i + m + 1][j + m + 1] * sg(s >> j & 1 ^ (s >> m & 1) ^ 1));         ret += max(tmp1, tmp2);       }       ans = max(ans, ret);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, ans = 0;     cin >> n;     long long int ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     sort(ar, ar + n);     long long int s = 0;     for (int i = 0; i < n; i++) {       if (s <= ar[i]) {         s += ar[i];         ans++;       }     }     cout << ans;   }   int main() {     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int arr[1000];   int main() {     int count, i, j, n;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     count = 0;     i = 0;     while (i < n) {       j = i;       while ((j < n) && (arr[j] == 1)) j++;       if (j > i) count += j - i + 1;       i = j + 1;     }     if (count > 0)       printf( %d n , count - 1);     else       printf( 0 n );     return 0;   }
#include <bits/stdc++.h>   long long arr[10000001];   using namespace std;   int main() {     long long n, k, m = 0;     cin >> n >> k;     m = (2 * n) + 1;     for (int i = 1; i <= m; i++) {       cin >> arr[i];     }     for (int i = 2; i <= m; i += 2) {       if (k == 0) {         break;       }       if (arr[i] > arr[i - 1] + 1 && arr[i] > arr[i + 1] + 1) {         --arr[i];         k--;       }     }     for (int i = 1; i <= m; i++) {       cout << arr[i] <<    ;     }   }