malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1E9 + 7;   const long long N = 2E5 + 6;   long long n, m, a[N], b[N], ans, zeros[N];   long long dp[N];   long long modexp(long long b, long long e) {     long long res = 1;     while (e) {       if (e & 1) res = (res * b) % MOD;       e >>= 1;       b = (b * b) % MOD;     }     return res;   }   long long recur(long long ind) {     if (dp[ind] != -1) return dp[ind];     if (ind == n + 1) {       dp[ind] = 0;       return 0;     }     long long ans = 0;     if (a[ind] == 0 && b[ind] != 0) {       ans = (m - b[ind] + MOD) % MOD;       ans = (ans * modexp(m, zeros[ind + 1]) % MOD) % MOD;       ans = (ans + recur(ind + 1)) % MOD;     } else if (a[ind] != 0 && b[ind] == 0) {       ans = (a[ind] - 1 + MOD) % MOD;       ans = (ans * modexp(m, zeros[ind + 1]) % MOD) % MOD;       ans = (ans + recur(ind + 1)) % MOD;     } else if (a[ind] == 0 && b[ind] == 0) {       ans = ((m * (m - 1)) % MOD * 500000004LL) % MOD;       ans = (ans * modexp(m, zeros[ind + 1])) % MOD;       ans = (ans + (m * recur(ind + 1)) % MOD) % MOD;     } else {       if (a[ind] > b[ind]) {         ans = modexp(m, zeros[ind + 1]) % MOD;       } else if (a[ind] == b[ind])         ans = recur(ind + 1) % MOD;     }     dp[ind] = ans;     return ans;   }   long long modinv(long long x) { return modexp(x, MOD - 2); }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (fopen( inp.txt ,  r )) {       freopen( inp.txt ,  r , stdin);       freopen( outp.txt ,  w , stdout);     }     cin >> n >> m;     long long i;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     memset(dp, -1, sizeof(dp));     zeros[n + 1] = 0;     zeros[n] = (b[n] == 0) + (a[n] == 0);     for (i = n - 1; i >= 1; i--)       zeros[i] = zeros[i + 1] + (a[i] == 0) + (b[i] == 0);     long long total = modexp(m, zeros[1]);     cout << (recur(1) * modinv(total)) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   inline void write(int x) {     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1000005, P = 1e9 + 7;   inline int power(int x, long long y) {     x %= P;     static int r;     r = 1;     while (y) {       if (y & 1) r = (long long)r * x % P;       x = (long long)x * x % P;       y >>= 1;     }     return r;   }   inline long long powerc(long long x, long long y, long long k) {     static long long r;     r = 1;     while (y) {       if (y & 1) r = r * x;       x = x * x;       y >>= 1;       r = min(r, k), x = min(x, k);     }     r = min(r, k);     return r;   }   int n, p, a[N], b[N], ans;   inline void solve() {     int i;     long long now, lst, dt;     read(n), read(p);     for (i = 1; i <= n; ++i) read(a[i]);     if (p == 1) {       ans = n & 1;       write(ans), putchar(  n );       return;     }     sort(a + 1, a + n + 1);     ans = 0;     for (i = 1; i <= n; ++i) b[i] = power(p, a[i]);     for (now = 0, lst = -1, i = n; i >= 1; --i) {       if (lst == -1) {         lst = a[i], now = 1, ans = (ans + b[i]) % P;         continue;       }       if (now != 0 && lst != a[i]) {         dt = lst - a[i];         now *= powerc(p, dt, n);         now = min(now, n * 1ll);       }       if (now) {         --now, ans = (ans + P - b[i]) % P;         lst = a[i];       } else {         ans = (ans + b[i]) % P;         now = 1, lst = a[i];       }     }     write(ans), putchar(  n );   }   int main() {     int T;     read(T);     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI(acos((long double)-1.0));   struct cpx {     long double r, i;     cpx() : r(0), i(0) {}     cpx(long double a, long double b) : r(a), i(b) {}     cpx conj() { return cpx(r, -i); }   } u[20], iu[20], a[524288], b[524288];   cpx operator+(const cpx &l, const cpx &r) { return cpx(l.r + r.r, l.i + r.i); }   cpx operator-(const cpx &l, const cpx &r) { return cpx(l.r - r.r, l.i - r.i); }   cpx operator*(const cpx &l, const cpx &r) {     return cpx(l.r * r.r - l.i * r.i, l.r * r.i + r.r * l.i);   }   void dif(cpx *a, cpx *unt, int l) {     int lv, i, j;     cpx u, v, w;     for (lv = l; lv; --lv)       for (i = 0; i < 1 << l; i += 1 << lv)         for (j = i, w = {1, 0}; j < i + (1 << lv - 1); ++j, w = w * unt[lv]) {           u = a[j];           v = a[j + (1 << lv - 1)];           a[j] = u + v;           a[j + (1 << lv - 1)] = (u - v) * w;         }   }   void dit(cpx *a, cpx *unt, int l) {     int lv, i, j;     cpx u, v, w;     for (lv = 1; lv <= l; ++lv)       for (i = 0; i < 1 << l; i += 1 << lv)         for (j = i, w = {1, 0}; j < i + (1 << lv - 1); ++j, w = w * unt[lv]) {           u = a[j];           v = a[j + (1 << lv - 1)] * w;           a[j] = u + v;           a[j + (1 << lv - 1)] = u - v;         }   }   int main() {     int tn, n, x, i, j, l;     long long a0;     scanf( %d%d , &n, &x);     for (tn = 0, l = -1, a0 = 0, i = 0; i < n; ++i) {       scanf( %d , &j);       if (j < x) {         a0 += (long long)(i - l) * (i - l - 1);         a[++tn].r = i - l;         l = i;       }     }     a0 += (long long)(n - l) * (n - l - 1);     a[++tn].r = n - l;     for (l = 1; 1 << l < tn; ++l)       ;     ++l;     for (i = 1; i < tn; ++i) b[(1 << l) - i].r = a[i].r;     for (i = 1; i <= l; ++i)       iu[i] =           (u[i] = cpx(cos(2 * PI / (1 << i)), -sin(2 * PI / (1 << i)))).conj();     dif(a, u, l);     dif(b, u, l);     for (i = 0; i < 1 << l; ++i) a[i] = a[i] * b[i];     dit(a, iu, l);     long double t((long double)1.0 / (1 << l));     printf( %lld , a0 / 2);     for (i = 1; i < tn && i <= n; ++i)       printf(  %lld , (long long)(a[i].r * t + 0.1));     for (; i <= n; ++i) printf(  0 );     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 5010;   namespace SuffixArray {   const int MAXN = 1 << 21;   string S;   int N, gap;   int sa[MAXN], pos[MAXN], tmp[MAXN], lcp[MAXN];   bool sufCmp(int i, int j) {     if (pos[i] != pos[j]) return pos[i] < pos[j];     i += gap;     j += gap;     return (i < N && j < N) ? pos[i] < pos[j] : i > j;   }   void buildSA() {     N = S.size();     for (int i = 0; i < (int)(N); ++i) sa[i] = i, pos[i] = S[i];     for (gap = 1;; gap *= 2) {       sort(sa, sa + N, sufCmp);       for (int i = 0; i < (int)(N - 1); ++i)         tmp[i + 1] = tmp[i] + sufCmp(sa[i], sa[i + 1]);       for (int i = 0; i < (int)(N); ++i) pos[sa[i]] = tmp[i];       if (tmp[N - 1] == N - 1) break;     }   }   void buildLCP() {     for (int i = 0, k = 0; i < N; ++i)       if (pos[i] != N - 1) {         for (int j = sa[pos[i] + 1]; S[i + k] == S[j + k];) ++k;         lcp[pos[i]] = k;         if (k) --k;       }   }   }  // namespace SuffixArray   using namespace SuffixArray;   bool dp[M][M];   void pre(string s, int n) {     for (int i = 1; i <= n; i++) dp[i][i] = 1;     for (int i = 1; i < n; i++) {       if (s[i] == s[i + 1]) dp[i][i + 1] = 1;       if (i == (n - 1)) continue;       if (s[i] == s[i + 2]) dp[i][i + 2] = 1;       if (i == (n - 2)) continue;       if (s[i] == s[i + 3]) dp[i][i + 3] = 1;     }     for (int k = 5; k <= n; k++) {       for (int i = 1; i + k - 1 <= n; i++) {         int j = i + k - 1;         if ((s[i] == s[j]) && dp[i + 2][j - 2]) dp[i][j] = 1;       }     }   }   int main() {     string s;     cin >> s;     int n = s.size();     s =  c  + s;     pre(s, n);     int k;     cin >> k;     S = s;     buildSA();     buildLCP();     int match = 0;     for (int i = 0; i < n; i++) {       int j = sa[i];       for (int l = match + 1; l + j - 1 <= n; l++) {         int x = l + j - 1;         if (!dp[j][x]) continue;         int cnter = 1;         for (int f = i; f < n - 1; f++) {           if (lcp[f] < l) break;           cnter++;         }         k -= cnter;         if (k <= 0) {           for (int f = j; f <= x; f++) cout << s[f];           cout << endl;           return 0;         }       }       match = lcp[i];     }     assert(false);   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   char C[3000];   long long D[3000][3000];   long long S[3000];   long long s = 0;   int main() {     cin >> n >> k;     cin >> C;     S[0] = D[0][0] = (C[0] -  a );     S[n] = D[0][n] = ( z  - C[0]);     s = D[0][k];     for (int i = 1; i < n; i++) {       int z = (i + 1) * (n - i);       D[i][0] += (C[i] -  a );       if (z <= k) D[i][z] += ( z  - C[i]);       for (int j = 0; j < i; j++) {         int z = (i - j) * (n - i);         for (int x = z; x <= k; x++) D[i][x] += ( z  - C[i]) * D[j][x - z];       }       for (int j = 0; j <= k; j++) {         D[i][j] += (C[i] -  a ) * S[j];         D[i][j] %= 1000000007;         S[j] += D[i][j];         S[j] %= 1000000007;       }       s += D[i][k];       s %= 1000000007;     }     if (k == 0) s++;     cout << s % 1000000007 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 250005;   int n, k, P, ans, f[30][N], fac[N], ifac[N], inv[N];   inline int ksm(register int x, register int L) {     register int ans = 1;     while (L)       L& 1 ? ans = (0ll + ans) * x % P, 0 : 0, x = (0ll + x) * x % P, L >>= 1;     return ans;   }   inline int dfs(const int x, const int s) {     if (x > k) return 0;     if (~f[x][s]) return f[x][s];     if (!s) return f[x][s] = (0ll + fac[n]) * fac[k] % P * ifac[k - x] % P;     f[x][s] = 0;     const int ss = s - (s & -s);     for (register int i = ss; i; i = (i - 1) & ss)       f[x][s] = (f[x][s] + (0ll + dfs(x + 1, i)) * ifac[s - i]) % P;     f[x][s] = (f[x][s] + (0ll + dfs(x + 1, 0)) * ifac[s]) % P;     return f[x][s];   }   int main() {     scanf( %d%d%d , &n, &k, &P), ans = ksm(k, n);     if (n & 1) return printf( %d , ans), 0;     for (register int i =              (fac[0] = fac[1] = ifac[0] = ifac[1] = inv[0] = inv[1] = 1) + 1;          i <= n; ++i)       fac[i] = (0ll + fac[i - 1]) * i % P,       inv[i] = (0ll + inv[P % i]) * (P - P / i) % P,       ifac[i] = (0ll + ifac[i - 1]) * inv[i] % P;     memset(f, -1, sizeof(f)), ans -= dfs(0, n),         printf( %d , ans < 0 ? ans + P : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k, ans = 0;       cin >> n >> k;       if (n % k > (k / 2)) {         cout << (n / k) * k + (k / 2) << endl;       } else {         cout << n << endl;       }     }   }
#include <bits/stdc++.h>   double eps = 1e-9;   double cal(int x, int n, int m) {     double tmp = 1;     for (int i = 0; i < n; i++) {       tmp *= (double)x / m;       if (tmp < eps) return 0.0;     }     return tmp;   }   int main() {     int m, n;     scanf( %d %d , &m, &n);     double tmp = 0.0;     for (int i = m - 1; i >= 1; i--) tmp += cal(i, n, m);     printf( %.9lf n , m - tmp);   }
#include <bits/stdc++.h>   using namespace std;   long long save[100005];   long long aa[100005];   int hihi[100005];   int main() {     int n;     scanf( %d , &n);     memset(aa, 0, sizeof(aa));     memset(aa, 0, sizeof(aa));     int first = 0, second = 0, sum = 1;     long long a;     scanf( %I64d , &a);     if (a != 1) {       printf( -1 n );       return 0;     }     hihi[second] = 1;     aa[second++] = 1;     for (int i = 1; i < n; i++) {       scanf( %I64d , &a);       if (a == 1)         hihi[second] = 1, aa[second++] = 1, sum = second;       else if (a == aa[second] * 2)         hihi[second]++, aa[second++] = a;       else if (second != 0 && a == aa[second - 1] * 2)         hihi[0]++, aa[0] = a, second = 1;       else {         save[first++] = a;       }     }     if (first > sum) {       printf( -1 n );       return 0;     }     int Min, Max = sum + 1;     int add = first;     for (int i = sum - 1; i >= 0 && add <= i + 1; i--) add += hihi[i], Min = i;     long long v[100005];     while (Min < Max - 1) {       memset(v, 0, sizeof(v));       int xx = 0;       for (xx = 0; xx < first; xx++) v[xx] = save[xx];       int mid = (Max + Min) / 2;       for (int i = mid; i < sum; i++) {         for (long long j = 1; j <= aa[i]; j *= 2)           v[xx++] = j, assert(xx < 100000);         ;       }       sort(v, v + xx);       reverse(v, v + xx);       int ok = 1;       for (int i = 0; i < xx; i++) {         if (v[i] > aa[i] * 2) ok = 0;       }       if (ok) {         Max = mid;       } else {         Min = mid;       }     }     if (Min == sum) {       printf( -1 n );     } else {       printf( %d , Min + 1);       for (int i = Min + 2; i <= sum; i++) printf(  %d , i);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   int lim;   int n;   int p[maxn] = {0};   int res[maxn] = {0};   bool vis[maxn] = {0};   int cnt = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &p[i]);     }     lim = n;     res[cnt++] = 1;     for (int i = 1; i <= n; ++i) {       int temp = i + 1 + lim - n;       vis[p[i]] = 1;       if (p[i] == lim) {         temp--;         lim--;         for (int j = p[i] - 1;; --j) {           if (vis[j]) {             temp--;             lim--;           } else             break;         }       }       res[cnt++] = temp;     }     for (int i = 0; i <= n; ++i) {       cout << res[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, ans;   char signs[3];   void r1(long long a) { ans = min(ans, a); }   void r2(long long a, long long b) {     if (signs[2] ==  * ) {       r1(a * b);     } else {       r1(a + b);     }   }   void r3(long long a, long long b, long long c) {     if (signs[1] ==  * ) {       r2(a * b, c);       r2(a * c, b);       r2(b * c, a);     } else {       r2(a + b, c);       r2(a + c, b);       r2(b + c, a);     }   }   void r4(long long a, long long b, long long c, long long d) {     if (signs[0] ==  * ) {       r3(a * b, c, d);       r3(a * c, b, d);       r3(a * d, b, c);       r3(b * c, a, d);       r3(b * d, a, c);       r3(c * d, a, b);     } else {       r3(a + b, c, d);       r3(a + c, b, d);       r3(a + d, b, c);       r3(b + c, a, d);       r3(b + d, a, c);       r3(c + d, a, b);     }   }   int main() {     cin >> a >> b >> c >> d >> signs[0] >> signs[1] >> signs[2];     ans = 1000000000001;     r4(a, b, c, d);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100111;   int N, M;   int ncr[MAXN][128];   int pre[128][MAXN];   int init[MAXN];   int main() {     ios_base::sync_with_stdio(false);     ncr[0][0] = 1;     for (int n = 1; n < MAXN; n++)       for (int r = 0; r <= 100; r++) {         ncr[n][r] = ncr[n - 1][r];         if (r) {           ncr[n][r] += ncr[n - 1][r - 1];           if (ncr[n][r] >= 1000000007) ncr[n][r] -= 1000000007;         }       }     cin >> N >> M;     for (int i = 0; i < N; i++) cin >> pre[0][i];     for (int i = 0; i < M; i++) {       int l, r, k;       cin >> l >> r >> k;       l--;       r--;       pre[k + 1][l]++;       for (int j = 0; j <= k; j++) {         int n = r - l + k - j, m = k - j;         if (n < 0 || m < 0 || m > n) continue;         pre[j + 1][r + 1] = pre[j + 1][r + 1] - ncr[n][m];         if (pre[j + 1][r + 1] < 0) pre[j + 1][r + 1] += 1000000007;       }     }     for (int K = 100; K >= 0; K--)       for (int i = 0; i < N; i++) {         if (i) pre[K + 1][i] = pre[K + 1][i] + pre[K + 1][i - 1];         if (pre[K + 1][i] >= 1000000007) pre[K + 1][i] -= 1000000007;         pre[K][i] = pre[K][i] + pre[K + 1][i];         if (pre[K][i] >= 1000000007) pre[K][i] -= 1000000007;       }     for (int i = 0; i < N; i++) cout << pre[0][i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, x;     cin >> n >> x;     int sum = 0, infected = 0;     for (int i = 1; i <= n; i++) {       int val;       cin >> val;       sum += val;       infected += (val == x);     }     if (infected == n)       cout << 0 <<   n ;     else if (infected > 0 || n * x == sum)       cout << 1 <<   n ;     else       cout << 2 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int t = 1, no = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int a[n + 1];     a[0] = 0ll;     long long int ans = 0ll;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > a[i - 1]) ans += (1ll * (a[i] - a[i - 1]) * (n - a[i] + 1));       if (a[i] < a[i - 1]) ans += (1ll * a[i] * (a[i - 1] - a[i]));     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n;     cin >> n;     vector<int> a(n);     int maxNum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       maxNum = max(a[i], maxNum);     }     vector<vector<bool> > board(maxNum, vector<bool>(n));     for (int i = 0; i < n; i++) {       for (int j = maxNum - 1; j > maxNum - 1 - a[i]; j--) {         board[j][i] = true;       }     }     for (int i = 0; i < maxNum; i++) {       for (int j = n - 1; j >= 0; j--) {         if (board[i][j] == false) {           for (int k = j - 1; k >= 0; k--) {             if (board[i][k] == true) {               swap(board[i][j], board[i][k]);               break;             }           }         }       }     }     for (int i = 0; i < n; i++) {       int count = 0;       for (int j = 0; j < maxNum; j++) {         if (board[j][i]) {           count++;         }       }       cout << count <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     while (q--) {       long long n, a, b;       cin >> n >> a >> b;       if (a + b >= n)         cout << max(a, b) - (a + b - 1 - n) << endl;       else         cout << min(a, b) + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int A[101];   string s;   long long d[101][101][101];   long long f(int lo, int hi, int p) {     if (lo == hi) return A[p];     if (d[lo][hi][p]) return d[lo][hi][p];     long long ret = f(lo + 1, hi, 1) + A[p];     if (s[lo] == s[lo + 1]) ret = max(ret, f(lo + 1, hi, p + 1));     for (int i = lo + 2; i <= hi; i++)       if (s[i] == s[lo]) ret = max(ret, f(lo + 1, i - 1, 1) + f(i, hi, p + 1));     return d[lo][hi][p] = ret;   }   int main() {     cout << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     cin >> s;     s =  #  + s;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++)       for (int k = 1; k < i; k++) A[i] = max(A[i], A[i - k] + A[k]);     cout << f(1, n, 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wmissing-declarations    double triangle_area(const complex<double> p1, const complex<double> p2,                        const complex<double> p3) {     return abs((p2.real() - p1.real()) * (p3.imag() - p1.imag()) -                (p2.imag() - p1.imag()) * (p3.real() - p1.real())) /            2.0;   }   pair<double, complex<double> > getCenter(const complex<double> a,                                            const complex<double> b,                                            const complex<double> c) {     complex<double> res;     res += a;     res += b;     res += c;     return {triangle_area(a, b, c), res / 3.0};   }   complex<double> getCenter(const vector<complex<double> >& v) {     double area = 0;     complex<double> res;     const int n = v.size();     for (int i = 1; i + 1 < n; ++i) {       auto p = getCenter(v[0], v[i], v[i + 1]);       area += p.first;       res += p.second * p.first;     }     return res / area;   }   double getDist(const complex<double> p1, const complex<double> p2) {     return norm(p1 - p2);   }   int main() {     ios_base::sync_with_stdio(false);     int n, q;     cin >> n >> q;     vector<complex<double> > v(n);     for (auto& p : v) {       double x, y;       cin >> x >> y;       p = {x, y};     }     complex<double> center = getCenter(v);     stringstream out;     out << fixed << setprecision(10);     int curP = 1;     for (auto& p : v) p -= center;     complex<double> angle = 1.0;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int f;         cin >> f;         --f;         curP ^= f;         complex<double> p1 = center + angle * v[curP];         complex<double> np{p1.real(), p1.imag() - abs(v[curP])};         angle = complex<double>{0, abs(v[curP])} / v[curP];         center = np;         int t;         cin >> t;         --t;         curP ^= t;       } else {         int t;         cin >> t;         --t;         complex<double> p = center + angle * v[t];         out << p.real() <<     << p.imag() <<   n ;       }     }     cout << out.str();   }
#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, pair<S, T> const& p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> const& v) {     int l = v.size();     for (int i = 0; i < l - 1; i++) out << v[i] <<    ;     if (l > 0) out << v[l - 1];     return out;   }   template <typename T>   void trace(const char* name, T&& arg1) {     cout << name <<   :   << arg1 << endl;   }   template <typename T, typename... Args>   void trace(const char* names, T&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     trace(comma + 1, args...);   }   const int inf = 1e9 + 10;   const long long int INF = 1e18 + 10;   const int MOD = 1e9 + 7;   const int MAXN = 2e5 + 10;   void solve() {     int n;     cin >> n;     int a[MAXN] = {0};     for (int i = 0; i < n; i += 1) cin >> a[i];     sort(a, a + n);     a[n + 1] = inf;     long long int sum = 0;     int ans = 0;     for (int i = 0; i < n; i += 1) {       if (a[i] >= sum)         ans++;       else {         int j = i;         while (j < n && a[j] < sum) j++;         if (a[j] >= sum) {           ans++;         }         i = j;       }       sum += a[i];     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }