malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int LIM = 15e5;   struct Vector {     int x, y;     Vector operator+(Vector v) { return {x + v.x, y + v.y}; }     Vector operator-(Vector v) { return {x - v.x, y - v.y}; }     long long operator%(Vector v) { return 1LL * x * v.y - 1LL * v.x * y; }     long long operator*(Vector v) { return 1LL * x * v.x + 1LL * y * v.y; }     friend double angle(Vector va, Vector vb) {       return abs(atan2(va % vb, va * vb) * 180 / PI);     }     double len() { return hypot(x, y); }     Vector operator*(int k) { return {k * x, k * y}; }   };   const int N = 1e5 + 1;   int n, sig[N];   Vector a[N];   vector<int> s[N];   void combine(int p) {     for (int i = p; i <= p + 2; ++i)       for (int j = i + 1; j <= p + 2; ++j) {         if (angle(a[i], a[j]) >= 120) {           int r = 3 * p + 3 - i - j;           if (s[i].size() > s[j].size()) s[i].swap(s[j]);           s[j].insert(s[j].end(), s[i].begin(), s[i].end());           a[j] = a[i] + a[j];           if (r == p) {             s[i].swap(s[r]);             a[i] = a[r];           }           return;         } else if (angle(a[i], a[j]) <= 60) {           int r = 3 * p + 3 - i - j;           for (int id : s[j]) sig[id] *= -1;           if (s[i].size() > s[j].size()) s[i].swap(s[j]);           s[j].insert(s[j].end(), s[i].begin(), s[i].end());           a[j] = a[i] - a[j];           if (r == p) {             s[i].swap(s[r]);             a[i] = a[r];           }           return;         }       }   }   bool toolong(Vector v) { return v.len() > LIM; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i].x >> a[i].y;       s[i].push_back(i);       sig[i] = 1;     }     if (n == 1) return cout << 1, 0;     for (int i = 1; i <= n - 2; ++i) {       combine(i);     }     if (angle(a[n - 1], a[n]) <= 90) {       for (int id : s[n]) sig[id] *= -1;     }     for (int i = 1; i <= n; ++i) {       cout << sig[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005];   int func(long a, long long x, long long f) {     if (a - x > 0) {       int tem;       tem = (a - x) / (f + x);       if (tem * (f + x) == (a - x))         return (a - x) / (f + x);       else         return (a - x) / (f + x) + 1;     } else       return 0;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     long long x, f;     cin >> x >> f;     long long ans = 0;     for (int i = 0; i < n; i++) {       int tem = func(a[i], x, f);       ans += tem;     }     cout << ans * f << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500100;   long long n, m, de, dt, h;   int main() {     int a, b, c;     int x, y, z;     cin >> a >> b >> c;     cin >> x >> y >> z;     int m1 = -(x - a);     int m2 = -(y - b);     int m3 = -(z - c);     int neg = 0, pos = 0;     if (m1 < 0)       neg += m1;     else       pos += m1 - m1 % 2;     if (m2 < 0)       neg += m2;     else       pos += m2 - m2 % 2;     if (m3 < 0)       neg += m3;     else       pos += m3 - m3 % 2;     if (-neg * 2 > pos)       printf( No n );     else       printf( Yes n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   vector<int> g[N];   int c[N], val[N], ans[N];   void merge(vector<int> &vc, vector<int> &tmp) {     for (auto u : tmp) vc.push_back(u);   }   vector<int> dfs(int u) {     vector<int> vc, tmp;     for (auto v : g[u]) {       tmp = dfs(v);       merge(vc, tmp);     }     if (c[u] > vc.size()) {       printf( NO n );       exit(0);     }     vc.insert(vc.begin() + c[u], u);     return vc;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1, u; i <= n; i++) {       val[i] = 1;       scanf( %d%d , &u, &c[i]);       g[u].push_back(i);     }     vector<int> vc = dfs(0);     for (int i = 0; i < vc.size(); i++) {       ans[vc[i]] = i + 1;     }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, SIZE = 1e5 * 2;   vector<long long> vec;   long long dp[100][SIZE], tree[SIZE * 8], pushing[SIZE * 8], prevPos[SIZE],       last[SIZE];   void push(int v) {     tree[v] += pushing[v];     pushing[v * 2 + 1] += pushing[v];     pushing[v * 2 + 2] += pushing[v];     pushing[v] = 0;   }   void build(int v, int l, int r, int k) {     if (l == r - 1) {       tree[v] = dp[k][l];     } else {       int mid = (l + r) / 2;       build(v * 2 + 1, l, mid, k);       build(v * 2 + 2, mid, r, k);       tree[v] = max(tree[v * 2 + 1], tree[v * 2 + 2]);     }   }   void upd(int v, int l, int r, int askl, int askr) {     push(v);     if (l >= askr || r <= askl) return;     if (l >= askl && r <= askr) {       pushing[v]++;       push(v);       return;     }     int mid = (l + r) / 2;     upd(v * 2 + 1, l, mid, askl, askr);     upd(v * 2 + 2, mid, r, askl, askr);     tree[v] = max(tree[v * 2 + 1], tree[v * 2 + 2]);   }   long long get(int v, int l, int r, int askl, int askr) {     push(v);     if (l >= askr || r <= askl) return 0;     if (l >= askl && r <= askr) {       return tree[v];     }     int mid = (l + r) / 2;     return max(get(v * 2 + 1, l, mid, askl, askr),                get(v * 2 + 2, mid, r, askl, askr));   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     ;     long long n, k;     cin >> n >> k;     vec.resize(n);     for (int i = 0; i < n; i++) cin >> vec[i];     set<long long> vals;     long long ans = 0;     for (int i = 0; i <= n; i++) {       last[i] = 0;     }     for (int i = 0; i < n; i++) {       vals.insert(vec[i]);       dp[0][i] = vals.size();       prevPos[i] = last[vec[i]];       last[vec[i]] = i;       ans = max(ans, dp[0][i]);     }     for (int j = 1; j < k; j++) {       for (int i = 0; i < SIZE; i++) {         tree[i] = 0;         pushing[i] = 0;       }       build(0, 0, n, j - 1);       for (int i = 0; i < n; i++) {         upd(0, 0, n, prevPos[i], i);         dp[j][i] = max(dp[j - 1][i], get(0, 0, n, 0, i));         ans = max(ans, dp[j][i]);       }       cout <<   ;     }     cout << dp[k - 1][n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long k;     string n;     cin >> k >> n;     long long sum = 0;     vector<long long> arr;     for (int(i) = 0; (i) < ((int)(n).size()); (i)++) {       sum += int(n[i] -  0 );       arr.push_back(int(n[i] -  0 ));     }     if (sum >= k) {       printf( 0 );       return 0;     } else {       sort((arr).begin(), (arr).end());       long long col = 0;       for (int(i) = 0; (i) < ((int)(arr).size()); (i)++) {         sum -= arr[i];         sum += 9;         col++;         if (sum >= k) {           printf( %lld , col);           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   const double eps = 1e-7;   using namespace std;   long long ans, n, s, a[maxn], b[maxn], num1, num2;   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       to1, to2;   void init() {     ans = 0;     num1 = 0;     num2 = 0;     while (to1.size()) to1.pop();     while (to2.size()) to2.pop();     memset(a, 0, sizeof(a)), memset(b, 0, sizeof(b));   }   int main() {     while (~scanf( %lld%lld , &n, &s)) {       init();       for (int i = 0; i <= n - 1; ++i) {         long long s, a, b;         scanf( %lld%lld%lld , &s, &a, &b);         if (a > b) {           num1 += s;           ans += s * a;           to2.push(pair<long long, long long>(a - b, s));         } else {           num2 += s;           ans += s * b;           to1.push(pair<long long, long long>(b - a, s));         }       }       num1 %= s, num2 %= s;       if (num1 + num2 > s) {         printf( %lld n , ans);         continue;       } else {         long long tmp1 = num1, tmp2 = num2, cost1 = 0, cost2 = 0;         while (tmp1) {           pair<long long, long long> tmp = to2.top();           to2.pop();           long long num = min(tmp1, tmp.second);           tmp1 -= num;           cost1 += num * tmp.first;         }         while (tmp2) {           pair<long long, long long> tmp = to1.top();           to1.pop();           int num = min(tmp2, tmp.second);           tmp2 -= num;           cost2 += num * tmp.first;         }         printf( %lld n , max(ans - cost1, ans - cost2));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   long long n, k, m, d;   int main() {     cin >> n >> k >> m >> d;     long long ans = min(n, m);     for (long long i = 1; i <= d; i++) {       long long tmp = (i - 1) * k + 1;       if (tmp <= 0) continue;       long long x = n / tmp;       if (x > m) x = m;       if (x * (i - 1) > (n - x) / k) continue;       long long res = x * (i - 1) + x;       if (res > ans) {         ans = res;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];       while (a[i] % 2 == 0) a[i] /= 2;       while (a[i] % 3 == 0) a[i] /= 3;     }     int flag = 0;     for (int i = 1; i < n; ++i) {       if (a[i] != a[0]) {         flag = 1;         break;       }     }     if (flag == 1)       cout <<  NO ;     else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 10;   int a[mx];   vector<int> g[mx];   vector<int> lyr[mx];   bool cmp(int i, int j) { return g[i].size() < g[j].size(); }   int main() {     int n, t, k;     scanf( %d %d %d , &n, &t, &k);     a[0] = 1;     for (int i = 1; i <= t; i++) scanf( %d , a + i);     int from = 0;     int leafs = a[t];     for (int i = 0; i < t; i++) {       int to = from + a[i] - 1;       int l = to + 1;       int r = l + a[i + 1] - 1;       for (int x = 0; x < min(a[i], a[i + 1]); x++) g[from + x].push_back(l + x);       if (a[i] < a[i + 1]) {         for (int x = 0; x < a[i + 1] - a[i]; x++) {           g[to].push_back(r - x);         }       } else         leafs += a[i] - a[i + 1];       for (int x = from; x <= to; x++) lyr[i].push_back(x);       sort(lyr[i].begin(), lyr[i].end(), cmp);       from = l;     }     for (int i = 1; i < t; i++) {       int to = lyr[i].back();       for (int u : lyr[i])         if (u != to && !g[u].empty() && leafs < k) {           for (int v : g[u]) g[to].push_back(v);           g[u].clear();           leafs++;         }     }     if (leafs != k) {       puts( -1 );       return 0;     }     printf( %d n , n);     for (int i = 0; i < n; i++)       for (int j : g[i]) printf( %d %d n , i + 1, j + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int res = -1, pos = -1, j = 0;     for (int i = 0; i < b.size(); i++) {       if (a[j] != b[i]) {         pos = j;         if (res != -1 || a[j + 1] != b[i]) {           res = 0;           break;         }         res = 1;         j++;       }       j++;     }     if (res == -1) res = 1, pos = a.size() - 1;     if (res) {       vector<int> v;       v.push_back(pos);       while (pos > 0 && a[--pos] == a[v[0]]) v.push_back(pos);       cout << v.size() << endl;       for (int i = v.size() - 1; i >= 0; i--) cout << v[i] + 1 <<    ;       cout << endl;     } else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int n, A, B;     cin >> n >> A >> B;     int msum = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(x);       msum += x;     }     int one = v[0];     v[0] = INT_MAX;     sort(v.begin(), v.end());     int x = n;     int sum = msum;     int res = 0;     for (int i = n - 2; i >= 0; i--) {       if (((one * A) / sum) >= B) {         cout << res << endl;         return 0;       }       sum -= v[i];       res++;     }     cout << n - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, nex[2000000], hea[2000000], wen[2000000], val[2000000], aid[2000000],       root2, root1, len, maxx;   struct segment_tree {     int a[2000000][2], lazy[2000000], fa[1000000], dep[1000000], in[1000000],         out[1000000], m;     void pushdown(int k) {       if (!lazy[k]) return;       swap(a[k << 1][0], a[k << 1][1]);       swap(a[(k << 1) | 1][0], a[(k << 1) | 1][1]);       lazy[k << 1] ^= 1;       lazy[(k << 1) | 1] ^= 1;       lazy[k] = 0;     }     void update1(int l, int r, int k, int x, int y, int z) {       if (l == r) {         a[k][z] = y;         return;       }       int mid = (l + r) >> 1;       if (x <= mid) update1(l, mid, k << 1, x, y, z);       if (x > mid) update1(mid + 1, r, (k << 1) | 1, x, y, z);       a[k][0] = max(a[k << 1][0], a[(k << 1) | 1][0]);       a[k][1] = max(a[k << 1][1], a[(k << 1) | 1][1]);     }     void update2(int l, int r, int k, int x, int y) {       if (l >= x && r <= y) {         lazy[k] ^= 1;         swap(a[k][0], a[k][1]);         return;       }       pushdown(k);       int mid = (l + r) >> 1;       if (x <= mid) update2(l, mid, k << 1, x, y);       if (y > mid) update2(mid + 1, r, (k << 1) | 1, x, y);       a[k][0] = max(a[k << 1][0], a[(k << 1) | 1][0]);       a[k][1] = max(a[k << 1][1], a[(k << 1) | 1][1]);     }     void build(int x, int y, int z) {       int a = 0;       in[x] = ++m;       dep[x] = dep[y] + 1;       for (int i = hea[x]; i; i = nex[i])         if (wen[i] != y) {           ++a;           fa[aid[i]] = wen[i];           build(wen[i], x, z ^ val[i]);         }       update1(1, n, 1, in[x], dep[x], z);       out[x] = m;     }     void revers(int x) { update2(1, n, 1, in[fa[x]], out[fa[x]]); }   } st1, st2;   void add(int x, int y, int z, int p) {     ++len;     nex[len] = hea[x];     wen[len] = y;     val[len] = z;     aid[len] = p;     hea[x] = len;   }   void dfs(int x, int y, int z) {     if (z >= maxx) maxx = z, root1 = x;     for (int i = hea[x]; i; i = nex[i])       if (wen[i] != y) dfs(wen[i], x, z + 1);   }   void dfs1(int x, int y, int z) {     if (z >= maxx) maxx = z, root2 = x;     for (int i = hea[x]; i; i = nex[i])       if (wen[i] != y) dfs1(wen[i], x, z + 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       add(x, y, z, i);       add(y, x, z, i);     }     dfs(1, 0, 0);     dfs1(root1, 0, 0);     st1.build(root1, 0, 0);     st2.build(root2, 0, 0);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int x;       scanf( %d , &x);       st1.revers(x);       st2.revers(x);       printf(  %d n , max(st1.a[1][0], st2.a[1][0]) - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a = 0, b = 1023, c, n;     char op;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> op >> c;       switch (op) {         case  | :           a |= c;           b |= c;           break;         case  & :           a &= c;           b &= c;           break;         case  ^ :           a ^= c;           b ^= c;           break;       }     }     int r = 0, nd = 1023, xr = 0;     for (int i = 0; i < 10; ++i) {       int p = (a >> i) & 1;       int q = (b >> i) & 1;       if (!p && !q) {         nd ^= (1 << i);       } else if (p && !q) {         xr |= (1 << i);       } else if (p && q) {         r |= (1 << i);       }     }     int s = 3;     if (nd == 1023) s--;     if (xr == 0) s--;     if (r == 0) s--;     cout << s << endl;     if (nd != 1023) cout <<  &   << nd << endl;     if (xr != 0) cout <<  ^   << xr << endl;     if (r != 0) cout <<  |   << r << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     std::string s;     std::cin >> s;     int n = s.length();     std::vector<int> prefix_fun(n, 0);     for (int i = 1; i < n; i++) {       int j = prefix_fun[i - 1];       while (j > 0 && s[i] != s[j]) {         j = prefix_fun[j - 1];       }       if (s[i] == s[j]) {         j++;       }       prefix_fun[i] = j;     }     if (prefix_fun[n - 1] == 0) {       std::cout <<  Just a legend ;       return 0;     }     for (int i = 1; i < n - 1; i++) {       if (prefix_fun[i] == prefix_fun[n - 1]) {         std::cout << s.substr(0, prefix_fun[i]);         return 0;       }     }     int j = prefix_fun[prefix_fun[n - 1] - 1];     if (j == 0) {       std::cout <<  Just a legend ;       return 0;     }     std::cout << s.substr(0, j);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 7, M = 1e6 + 7;   int row[N], col[N];   long long dpc[M], dpr[M];   int main() {     priority_queue<int> pqc, pqr;     int n, m, k, p;     scanf( %d %d %d %d , &n, &m, &k, &p);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int a;         scanf( %d , &a);         row[i] += a;         col[j] += a;         if (i == n - 1) {           pqc.push(col[j]);         }       }       pqr.push(row[i]);     }     for (int i = 1; i <= k; i++) {       dpr[i] = pqr.top() + dpr[i - 1];       pqr.push(pqr.top() - p * m);       pqr.pop();       dpc[i] = pqc.top() + dpc[i - 1];       pqc.push(pqc.top() - p * n);       pqc.pop();     }     long long ans = -1e18;     for (int i = 0; i <= k; i++) {       ans = max(ans, 1ll * dpr[i] + dpc[k - i] - (1ll * i * (k - i) * p));     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, x;       cin >> n >> x;       long long int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n);       long double rich_sum = 0;       long long int poor_idx = -1;       for (int i = 0; i < n; i++) {         if (arr[i] < x) {           poor_idx = i;         } else           rich_sum += arr[i];       }       int i;       for (i = poor_idx; i >= 0; i--) {         rich_sum += arr[i];         if (rich_sum / (n - i) < x) break;       }       int poor_cnt = i + 1;       cout << (n - poor_cnt) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int INF = (int)2e9 + 10;   typedef struct vocationn {     int min_cost[N];     vector<pair<int, int> > left[N];     vector<pair<int, int> > right[N];   } vocation;   int n, x, cost, l, r, ans = INF;   vocation voc;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     for (int i = 0; i < N; i++) voc.min_cost[i] = INF;     cin >> n >> x;     for (size_t i = 0; i < n; i++) {       cin >> l >> r >> cost;       voc.left[l].push_back(pair<int, int>(r - l + 1, cost));       voc.right[r].push_back(pair<int, int>(r - l + 1, cost));     }     for (int i = 0; i < N; i++) {       for (pair<int, int> t : voc.left[i]) {         if (t.first >= x) continue;         if (voc.min_cost[x - t.first] < INF)           ans = min(ans, voc.min_cost[x - t.first] + t.second);       }       for (pair<int, int> t : voc.right[i])         voc.min_cost[t.first] = min(voc.min_cost[t.first], t.second);     }     if (ans == INF)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   vector<int> G[maxn];   vector<int> inv[maxn];   int n, m;   int vis[2][maxn];   int in[maxn];   inline int topo_sort(vector<int>* G, int* in) {     stack<int> S;     for (auto i = (0); i < (n); ++i) {       if (in[i] == 0) S.push(i);     }     int cnt = 0;     for (; !S.empty();) {       int u = S.top();       S.pop();       ++cnt;       for (auto v : G[u]) {         if (--in[v] == 0) S.push(v);       }     }     return cnt == n;   }   inline void dfs(int u, vector<int>* g, int* vis) {     if (vis[u]) return;     vis[u] = 1;     for (auto v : g[u]) {       if (vis[v]) continue;       dfs(v, g, vis);     }   }   inline void solve() {     int ans = 0;     string o;     for (auto i = (0); i < (n); ++i) {       if (!vis[0][i] && !vis[1][i]) {         o.push_back( A );         ans++;       } else         o.push_back( E );       dfs(i, G, vis[0]);       dfs(i, inv, vis[1]);     }     printf( %d n%s n , ans, o.c_str());   }   int main(void) {     scanf( %d , &(n)), scanf( %d , &(m));     for (auto i = (0); i < (m); ++i) {       int u, v;       scanf( %d , &(u)), scanf( %d , &(v));       u--, v--;       G[u].push_back(v);       inv[v].push_back(u);       in[v]++;     }     if (!topo_sort(G, in)) return puts( -1 ), 0;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> volc[100000];   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &volc[i].first);       scanf( %d , &volc[i].second);     }     sort(volc, volc + m);     int x = 0;     vector<pair<int, int> > ints;     ints.push_back(make_pair(1, 1));     int i = 0;     while (i != m) {       if (ints.empty()) break;       if (volc[i].first > x + 1) {         int f = ints[0].first;         ints.clear();         ints.push_back(make_pair(f, n));       }       x = volc[i].first;       vector<pair<int, int> > ys;       int last = 0;       while (x == volc[i].first) {         if ((volc[i].second - last - 1) > 0)           ys.push_back(make_pair(last + 1, volc[i].second - 1));         last = volc[i].second;         i++;       }       if ((n + 1 - last - 1) > 0) ys.push_back(make_pair(last + 1, n));       vector<pair<int, int> > nints;       int k = 0;       for (int j = 0; j < (int)(ints.size()); j++) {         while (k < (int)(ys.size()) && ys[k].second < ints[j].first) k++;         while (k < (int)(ys.size()) && ys[k].first <= ints[j].second) {           nints.push_back(               make_pair(max(ys[k].first, ints[j].first), ys[k].second));           k++;         }       }       ints = nints;     }     if (ints.empty()) {       cout << -1 << endl;       return 0;     }     if (x != n || ints[(int)(ints.size()) - 1].second == n)       cout << 2 * (n - 1) << endl;     else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Polynom {     long long x, y;   } a[6001], b[6001];   int main() {     string s;     cin >> s;     if (s.length() == 1) {       cout << s << endl;       return 0;     }     for (int i = s.length(); i > 0; i--) s[i] = s[i - 1];     int n = s.length();     long long x = 0, y = s[0] - 48;     for (int i = 1; i <= n; i++) {       if (s[i] ==  +  || s[i] ==  * ) {         a[i].x = x;         a[i].y = y;       }       if (s[i] ==  + ) {         x += y;         y = s[i + 1] - 48;       }       if (s[i] ==  * ) {         y *= (s[i + 1] - 48);       }     }     a[n].x = x;     a[n].y = y;     x = 0;     y = s[n] - 48;     for (int i = n; i >= 1; i--) {       if (s[i] ==  +  || s[i] ==  * ) {         b[i].x = x;         b[i].y = y;       }       if (s[i] ==  + ) {         x += y;         y = s[i - 1] - 48;       }       if (s[i] ==  * ) {         y *= (s[i - 1] - 48);       }     }     b[0].x = x;     b[0].y = y;     long long ans = 0;     s[0] =  + ;     s[n + 1] =  + ;     s[n + 2] =  0 ;     for (int i = 0; i <= n + 1; i++) {       if (s[i] ==  +  || s[i] ==  * ) {         x = 0;         y = s[i + 1] - 48;         for (int j = i + 2; j <= n + 1; j++) {           if (s[j] ==  +  || s[j] ==  * ) {             long long res = x + y;             if (s[i] ==  * ) res *= a[i].y;             if (s[j] ==  * ) res *= b[j].y;             if (s[i] ==  + ) res += a[i].y;             if (s[j] ==  + ) res += b[j].y;             res += a[i].x + b[j].x;             if (res > ans) {               ans = res;             }           }           if (s[j] ==  + ) {             x += y;             y = s[j + 1] - 48;           }           if (s[j] ==  * ) {             y *= (s[j + 1] - 48);           }         }       }     }     cout << ans << endl;   }