malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   int a[100005];   vector<int> v[100005];   void solve() {     int i, j, k, flag = 0, ok, sz, tmp;     for (i = 1; i <= 500; i++) {       ok = 1;       random_shuffle(a + 1, a + n + 1);       for (j = 1; j <= m; j++) {         sz = v[a[j]].size();         for (k = 0; k < sz; k++) {           if (j == n)             tmp = 1;           else             tmp = j + 1;           if (v[a[j]][k] == a[tmp]) {             ok = 0;             break;           }         }       }       if (ok) {         flag = 1;         for (j = 1; j <= m; j++) {           if (j == n)             tmp = 1;           else             tmp = j + 1;           printf( %d %d n , a[j], a[tmp]);         }         break;       }     }     if (!flag) printf( -1 n );   }   int main() {     int i, j, l, r;     while (~scanf( %d%d , &n, &m)) {       for (i = 1; i <= n; i++) {         v[i].clear();         a[i] = i;       }       for (i = 1; i <= m; i++) {         scanf( %d%d , &l, &r);         v[l].push_back(r);         v[r].push_back(l);       }       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double PI = 3.14159265359;   int n, k;   long long S;   vector<vector<long long>> dp(25);   vector<long long> fact(20, 1ll);   long long getFactVal(int mask, vector<long long>& vi) {     long long ans = 0;     int m = vi.size();     for (int i = 0; i < m; i++) {       if ((1 << i) & mask) {         if (vi[i] > 19) {           return S + 1;         } else {           ans += fact[vi[i]];         }       }       if (ans > S) {         return S + 1;       }     }     return ans;   }   long long getVal(int mask, vector<long long>& vi) {     long long ans = 0;     int m = vi.size();     for (int i = 0; i < m; i++) {       if ((1 << i) & mask) {         ans += vi[i];       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> S;     vector<long long> v1, v2;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       if (i < n / 2)         v1.push_back(x);       else         v2.push_back(x);     }     fact.push_back(0ll);     for (int i = 1; i <= 19; i++) {       fact[i] = fact[i - 1] * i;     }     for (int mask2 = 0; mask2 < (1 << v2.size()); mask2++) {       auto val = getFactVal(mask2, v2);       if (val <= S) {         for (int mask1 = 0; mask1 < (1 << v2.size()); mask1++) {           if (!(mask1 & mask2)) {             auto val2 = getVal(mask1, v2);             if (val + val2 <= S) {               dp[__builtin_popcount(mask2)].push_back(val + val2);             }           }         }       }     }     long long ans = 0;     for (int i = 0; i < 25; i++) {       if (dp[i].size()) {         sort(dp[i].begin(), dp[i].end());       }     }     for (int mask2 = 0; mask2 < (1 << v1.size()); mask2++) {       auto val = getFactVal(mask2, v1);       int k1 = __builtin_popcount(mask2);       if (val <= S && k1 <= k) {         for (int mask1 = 0; mask1 < (1 << v1.size()); mask1++) {           if (!(mask1 & mask2)) {             auto val2 = getVal(mask1, v1) + val;             if (val2 <= S) {               for (int i = 0; i <= min(k - k1, 13); i++) {                 if (dp[i].size()) {                   ans += upper_bound(dp[i].begin(), dp[i].end(), S - val2) -                          lower_bound(dp[i].begin(), dp[i].end(), S - val2);                 }               }             }           }         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int count = 0;     int len = s.size();     bool small = false;     for (int i = 0; i < len; i++) {       if (s[i] <  a ) {         count++;       }       if (s[0] >=  a ) {         small = true;       }     }     if (count == len || (count == len - 1 && small)) {       for (int i = 0; i < len; i++) {         if (i == 0 && count == len) {           s[i] = s[i] + 32;         } else if (i == 0 && small) {           s[i] = s[i] - 32;         } else {           s[i] = s[i] + 32;         }       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int deep[200000 + 10], to[200000 + 10];   int len;   string s;   stack<int> tmp;   int best_deep[200000 + 10];   void dfs(int l, int r, int dep) {     deep[l] = dep;     if (l == r - 1) {       best_deep[l] = dep;       return;     }     int now = l + 1;     int MAX_ = 0;     while (now < r - 1) {       dfs(now, to[now], dep + 1);       MAX_ = max(MAX_, best_deep[now]);       now = to[now] + 1;     }     best_deep[l] = MAX_;   }   int res[200000 + 10];   void recover(int l, int r, int dep) {     if (dep - 1 == best_deep[l] >> 1) {       for (int i = l; i <= r; ++i) {         res[i] = 1;       }       return;     }     if (l == r - 1) {       return;     }     int now = l + 1;     while (now < r - 1) {       recover(now, to[now], dep + 1);       now = to[now] + 1;     }   }   int main() {     scanf( %d , &len);     cin >> s;     for (int i = 0; i <= len - 1; ++i) {       if (s[i] ==  ( )         tmp.push(i);       else {         to[tmp.top()] = i;         tmp.pop();       }     }     int now = 0;     while (now < len - 1) {       dfs(now, to[now], 1);       now = to[now] + 1;     }     now = 0;     while (now < len - 1) {       for (int i = now; i <= to[now]; ++i) {         best_deep[i] = best_deep[now];       }       now = to[now] + 1;     }     now = 0;     while (now < len - 1) {       recover(now, to[now], 1);       now = to[now] + 1;     }     for (int i = 0; i <= len - 1; ++i) {       printf( %d , res[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int R, x1, y1, x2, y2;     scanf( %d%d%d%d%d , &R, &x1, &y1, &x2, &y2);     if ((long long)(x2 - x1) * (x2 - x1) + (long long)(y2 - y1) * (y2 - y1) >=         (long long)R * R) {       printf( %.12f %.12f %.12f n , (double)x1, (double)y1, (double)R);     } else if (x1 == x2 && y1 == y2) {       printf( %.12f %.12f %.12f n , x1 + R / 2.0, (double)y1, R / 2.0);     } else {       double L = R + hypot(x2 - x1, y2 - y1);       L /= 2;       double dx = x1 - x2, dy = y1 - y2, dl = hypot(dx, dy);       dx = dx / dl * L + x2;       dy = dy / dl * L + y2;       printf( %.12f %.12f %.12f n , dx, dy, L);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, p, l, m, n, c, d, t, k;   long long a[int(3e5 + 11)];   string s;   long long dp[4][2][int(3e5 + 11)];   int main() {     cin >> s;     long long n = s.size();     long long pas1 = 0, pas2 = 0;     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  a ) {         dp[0][0][i] = dp[1][1][i - 1] + dp[0][1][i - 1];         dp[0][1][i] = dp[1][0][i - 1] + dp[0][0][i - 1] + 1;         dp[2][0][i] = dp[2][1][i - 1] + dp[3][1][i - 1];         dp[2][1][i] = dp[2][0][i - 1] + dp[3][0][i - 1];       } else {         dp[3][0][i] = dp[2][1][i - 1] + dp[3][1][i - 1];         dp[3][1][i] = dp[2][0][i - 1] + dp[3][0][i - 1] + 1;         dp[1][0][i] = dp[1][1][i - 1] + dp[0][1][i - 1];         dp[1][1][i] = dp[1][0][i - 1] + dp[0][0][i - 1];       }       pas1 += dp[0][0][i] + dp[3][0][i];       pas2 += dp[0][1][i] + dp[3][1][i];     }     cout << pas1 <<     << pas2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   struct node {     int ou, j1, j2, j3;   } a[10020];   void setup() {     int i, j;     int ou = 2, ji = 1;     for (i = 1; i <= 10010; i++) {       while (ou % 3 == 0) ou += 2;       a[i].ou = ou;       ou += 2;       a[i].j1 = ji;       a[i].j2 = ji + 2;       a[i].j3 = ji + 4;       ji += 6;     }   }   int main() {     int i, j;     setup();     while (scanf( %d%d , &n, &k) != EOF) {       printf( %d n , a[n].j3 * k);       for (i = 1; i <= n; i++)         printf( %d %d %d %d n , a[i].ou * k, a[i].j1 * k, a[i].j2 * k,                a[i].j3 * k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000000000000ll;   long long b[230400], h[230400], d[230400], ans, t[230400], n, m;   struct node {     long long c, e;   } a[230400];   struct seg {     long long l, r, val, z;   } s[230400 * 4];   bool cmp(node u, node v) {     if (u.c == v.c) return u.e < v.e;     return u.c < v.c;   }   void build(long long p, long long l, long long r) {     s[p].l = l;     s[p].r = r;     if (l == r) {       s[p].val = t[l];       s[p].z = 0;       return;     }     long long mid = (l + r) >> 1;     build(p << 1, l, mid);     build((p << 1) | 1, mid + 1, r);     s[p].val = min(s[p << 1].val, s[(p << 1) | 1].val);     s[p].z = 0;   }   void pass(long long p) {     s[p].val += s[p].z;     if (s[p].l != s[p].r) s[p << 1].z += s[p].z, s[(p << 1) | 1].z += s[p].z;     s[p].z = 0;   }   void update(long long p, long long l, long long r, long long w) {     if (s[p].l > r || s[p].r < l) {       pass(p);       return;     }     if (s[p].l >= l && s[p].r <= r) {       s[p].z += w;       pass(p);       return;     }     pass(p);     update(p << 1, l, r, w);     update((p << 1) | 1, l, r, w);     s[p].val = min(s[p << 1].val, s[(p << 1) | 1].val);   }   long long qry(long long p, long long l, long long r) {     pass(p);     if (s[p].l > r || s[p].r < l) return inf;     if (s[p].l >= l && s[p].r <= r) return s[p].val;     return min(qry(p << 1, l, r), qry((p << 1) | 1, l, r));   }   int main() {     scanf( %d%d , &n, &m);     for (long long i = 1; i <= n; i++) scanf( %lld , &b[i]);     d[n] = b[n];     for (long long i = n - 1; i; i--) d[i] = max(d[i + 1], b[i]);     for (long long i = 1; i <= n; i++) t[i] = t[i - 1] + b[i];     build(1, 1, n);     for (long long i = 0; i < m; i++) scanf( %lld , &a[i].e);     for (long long i = 0; i < m; i++) scanf( %lld , &a[i].c);     sort(a, a + m, cmp);     for (long long i = 0; i < m; i++) {       if (d[1] < a[i].e) continue;       long long lf, rt, mid;       lf = 0;       rt = n + 1;       while (rt - lf > 1) {         mid = (lf + rt) >> 1;         if (d[mid] < a[i].e)           rt = mid;         else           lf = mid;       }       if (qry(1, lf, n) >= a[i].c) update(1, lf, n, -a[i].c), ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 9, maxV = 536, MOD = 1e9 + 7, AND = (1 << 20) - 1,             lg = 21;   vector<int> farg[maxN], adj[maxN], adjc[maxN], elems[maxN];   int incom[maxN], comp[maxN], idx;   set<pair<int, int> > mys;   stack<int> stc;   bool vi[maxN];   void dfs(int nd) {     if (vi[nd]) return;     vi[nd] = 1;     for (int sn : adj[nd]) dfs(sn);     stc.push(nd);   }   void sfd(int nd) {     if (vi[nd]) return;     vi[nd] = 1;     for (int sn : farg[nd]) sfd(sn);     comp[nd] = idx;     elems[idx].push_back(nd);   }   bool makeQuery(int a, int b) {     cout <<  ?   << a + 1 <<     << b + 1 <<   n ;     cout.flush();     int ans;     cin >> ans;     return ans == 1;   }   void procesavec(vector<int> &one, vector<int> &two) {     while (one.size() && two.size()) {       if (makeQuery(one.back(), two.back())) {         two.pop_back();       } else {         one.pop_back();       }     }   }   int n, m;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int u, v, i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       farg[v].push_back(u);     }     for (int i = 0; i < n; i++) dfs(i);     memset(vi, 0, sizeof vi);     while (stc.size()) {       while (stc.size() && vi[stc.top()]) stc.pop();       if (stc.empty()) break;       sfd(stc.top());       idx++;     }     for (int i = 0; i < n; i++) {       for (int to : adj[i]) {         if (comp[to] == comp[i]) continue;         incom[comp[to]]++;         adjc[comp[i]].push_back(comp[to]);       }     }     for (int i = 0; i < idx; i++) {       mys.insert(pair<int, int>(incom[i], i));     }     int nd = mys.begin()->second;     mys.erase(mys.begin());     while (mys.size() && mys.begin()->first == 0) {       int frontup = mys.begin()->second;       mys.erase(pair<int, int>(incom[frontup], frontup));       procesavec(elems[nd], elems[frontup]);       if (elems[nd].empty()) swap(nd, frontup);       for (int cmp : adjc[frontup]) {         mys.erase(pair<int, int>(incom[cmp]--, cmp));         mys.insert(pair<int, int>(incom[cmp], cmp));       }     }     cout <<  !   << elems[nd].back() + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[102][102];     int b, c, i, j, n, m;     cin >> n >> m;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) cin >> a[i][j];     b = n;     while (b % 2 == 0 && b / 2 != 0) {       c = 0;       for (i = 1; i <= b / 2; i++)         for (j = 1; j <= m; j++)           if (a[i][j] != a[b - i + 1][j]) c = 1;       if (c == 1) break;       b = b / 2;     }     printf( %d n , b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[200005];   int calc(int t) {     int res = 0;     for (int i = 1; i <= 200000; i++) {       res += cnt[i] / t;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       cnt[a]++;     }     int lf = 1, ri = 200005, mid;     while (lf < ri) {       mid = (lf + ri) / 2;       if (calc(mid) < k)         ri = mid;       else         lf = mid + 1;     }     if (calc(mid) < k) mid--;     int p, tot = 0;     while (tot < k) {       for (int i = 1; i <= 200000; i++) {         if (tot == k) break;         p = cnt[i] / mid;         for (int j = 0; j < p; j++) {           cout << i <<    ;           tot++;           if (tot == k) break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n;     cin >> n;     pair<long long int, long long int> a[n];     for (long long int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;     sort(a, a + n);     long long int x1 = -1, y1 = -1, x2 = -1, y2 = -1;     for (long long int i = 0; i < n; i++) {       long long int x = a[i].first, y = a[i].second;       if (x > y1) {         x1 = x, y1 = y;         continue;       }       if (x > y2) {         x2 = x, y2 = y;         continue;       }       return cout <<  NO , 0;     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, s, n, e;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> s >> n >> e;       long long l = 0, r = e + 1, m;       if (e == 0) {         if (s > n)           cout << 1 << endl;         else           cout << 0 << endl;         continue;       }       while (r - l > 1) {         m = (r + l) / 2;         if (n + m < s + e - m) {           l = m;         } else           r = m;       }       if (n < s + e) l++;       cout << l << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 10;   inline int read() {     int x = 0;     bool f = true;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = false;       c = getchar();     }     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return f ? x : -x;   }   int n, c[N], t[N], a[N], b[N];   int main() {     n = read();     for (register int i = 1; i <= n; ++i) c[i] = read();     for (register int i = 1; i <= n; ++i) t[i] = read();     for (register int i = 1; i <= n; ++i)       a[i] = c[i] - c[i - 1], b[i] = t[i] - t[i - 1];     sort(a + 2, a + n + 1), sort(b + 2, b + n + 1);     for (register int i = 1; i <= n; ++i)       if (a[i] != b[i]) return puts( No ) & 0;     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     int n;     cin >> n;     int x[n], y[n], dx[n], dy[n], s[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i] >> dx[i] >> dy[i] >> s[i];     }     float ans = -1;     int eff_s;     float t1, t2;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (dx[i] * dy[j] == dx[j] * dy[i]) {           if (dx[i] * (y[j] - y[i]) == dy[i] * (x[j] - x[i])) {             eff_s = 0;             if (dy[i] * (y[j] - y[i]) > 0) eff_s += s[i];             if (dy[j] * (y[i] - y[j]) > 0) eff_s += s[j];             if (eff_s != 0) {               t1 = sqrt((y[j] - y[i]) * (y[j] - y[i]) +                         (x[j] - x[i]) * (x[j] - x[i])) /                    eff_s;               if (ans == -1 || ans > t1) {                 ans = t1;               }             }           }         } else {           t1 = (sqrt(dx[i] * dx[i] + dy[i] * dy[i]) *                 (dy[j] * (x[j] - x[i]) - dx[j] * (y[j] - y[i]))) /                (s[i] * (dx[i] * dy[j] - dx[j] * dy[i]));           t2 = (sqrt(dx[j] * dx[j] + dy[j] * dy[j]) *                 (dy[i] * (x[i] - x[j]) - dx[i] * (y[i] - y[j]))) /                (s[j] * (dx[j] * dy[i] - dx[i] * dy[j]));           if (t1 >= 0 && t2 >= 0 && (ans == -1 || ans > max(t1, t2))) {             ans = max(t1, t2);           }         }       }     }     if (ans == -1)       cout <<  No show :( ;     else       cout << setprecision(14) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Solved() {     int n;     cin >> n;     int one = 0;     int two = 0;     vector<int> ans;     long long sum = 0;     for (int i = 1; i <= n; i++) {       int te;       cin >> te;       if (te % 2 == 0) {         two++;       } else {         one++;       }     }     if (two > 0) {       sum += 2;       ans.push_back(2);       two--;     }     while (1) {       if (two == 0 && one == 0) {         break;       }       if (sum % 2 == 0) {         if (one > 0) {           ans.push_back(1);           sum += 1;           one--;         } else {           ans.push_back(2);           sum += 2;           two--;         }       } else {         if (two > 0) {           ans.push_back(2);           sum += 2;           two--;         } else {           ans.push_back(1);           one--;           sum += 1;         }       }     }     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }   int main() {     Solved();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (ll i = 0; i < v.size(); ++i) os << v[i] <<    ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (auto it : v) os << it <<    ;     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     os << v.first <<     << v.second;     return os;   }   const ll mod = 1e9 + 7;   const ll inf = 2e18;   const ll ninf = -2e18;   ll takemod(ll a) { return ((a % mod) + mod) % mod; }   ll pow(ll a, ll b, ll m) {     ll ans = 1;     a %= m;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   ll modinv(ll a) { return takemod(pow(takemod(a), mod - 2, mod)); }   void solve() {     ll n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     ll arr[26][26];     memset(arr, 0, sizeof(arr));     for (ll i = 0; i < n; i++) {       ll a = s1[i] -  a ;       ll b = s2[i] -  a ;       if (a == b) continue;       if (a > b) {         cout << -1 <<   n ;         return;       }       arr[a][b]++;     }     ll ans = 0;     for (ll i = 0; i <= 20; i++) {       for (ll j = i + 1; j <= 20; j++) {         if (!arr[i][j]) continue;         for (ll k = j + 1; k <= 20; k++) {           if (arr[i][k]) {             arr[j][k] += arr[i][k];             arr[i][k] = 0;           }         }         ans++;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     time_t t1, t2;     t1 = clock();     ll t;     cin >> t;     while (t--) solve();     t2 = clock();     cerr <<   n  << t2 - t1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   string i2s(T x) {     ostringstream o;     o << x;     return o.str();   }   template <class T>   vector<T> split(const string& s) {     vector<T> v;     istringstream is(s);     T t;     while (is >> t) v.push_back(t);     return v;   }   vector<string> splitStr(const string& s, const string& d =   ,                           bool keepEmpty = false) {     if (d.empty()) return split<string>(s);     vector<string> v;     string t;     for (int _n = ((int((s).size()))), i = 0; i < _n; ++i)       if (d.find(s[i]) != string::npos) {         if (keepEmpty || !t.empty()) {           v.push_back(t);           t =   ;         }       } else         t += s[i];     if (!t.empty()) v.push_back(t);     return v;   }   int main() {     std::ios::sync_with_stdio(false);     int N, M;     string s;     cin >> N >> M;     vector<string> v(N);     for (int _n = (N), i = 0; i < _n; ++i) {       cin >> v[i];     }     int mini = 1000, maxi = 0, minj = 1000, maxj = 0;     for (int _n = (N), i = 0; i < _n; ++i)       for (int _n = (M), j = 0; j < _n; ++j)         if (v[i][j] ==  X ) {           mini = min(i, mini);           minj = min(j, minj);           maxi = max(i, maxi);           maxj = max(j, maxj);         }     bool poss = true;     for (int i = (mini); i <= (maxi); ++i)       for (int j = (minj); j <= (maxj); ++j)         if (v[i][j] !=  X ) {           poss = false;           break;         }     string ans = (poss ?  YES  :  NO );     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     long long int sum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += 1ll * a[i];     }     long long int m = ceil(sum / 2);     long long int temp = 0;     for (int i = 0; i < n; i++) {       temp += 1ll * a[i];       if (2 * temp >= sum) {         cout << i + 1 <<   n ;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename TYPE>   inline TYPE sqr(const TYPE& a) {     return a * a;   }   const long double EPS = 1e-9;   const long double PI = 2 * acos(0.0);   const int N = 300010;   int a[N];   int main() {     int n;     scanf( %d , &n);     long long s = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       s += a[i];     }     sort(a, a + n);     long long ans = s;     for (int i = 0; i + 1 < n; ++i) {       ans += s;       s -= a[i];     }     cout << ans << endl;     return 0;   }