malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 55, mod = 1LL * 1000 * 1000 * 1000 + 7;   int dp[N][N][2], ans[N][N][2], n, cnt50, cnt100, W, c[N][N], seen[N][N];   bool vis[N][N][2], vis2[N][N][2];   int C(int r, int n) {     if (r == 0 || r == n) return 1;     if (r > n) return 0;     if (seen[r][n]) return c[r][n];     seen[r][n] = true;     return c[r][n] = (C(r - 1, n - 1) + C(r, n - 1)) % mod;   }   int dfs(int x, int y, int tp) {     if (vis2[x][y][tp]) return ans[x][y][tp];     vis2[x][y][tp] = true;     if (tp) {       for (int i = 0; i <= cnt50 - x; i++)         for (int j = 0; j <= cnt100 - y; j++)           if (i * 50 + j * 100 <= W && (i || j) &&               dp[x][y][tp] == dp[x + i][y + j][!tp] + 1)             (ans[x][y][tp] += 1LL * dfs(x + i, y + j, !tp) * C(i, cnt50 - x) %                               mod * C(j, cnt100 - y) % mod) %= mod;     } else {       for (int i = 0; i <= x; i++)         for (int j = 0; j <= y; j++)           if ((i || j) && i * 50 + j * 100 <= W &&               dp[x][y][tp] == dp[x - i][y - j][!tp] + 1)             (ans[x][y][tp] +=              1LL * dfs(x - i, y - j, !tp) * C(i, x) % mod * C(j, y) % mod) %= mod;     }     return ans[x][y][tp];   }   struct Node {     int x = 0, y = 0, tp = 0;     Node(int a = 0, int b = 0, int c = 0) { x = a, y = b, tp = c; }   };   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < 2; k++) dp[i][j][k] = 1 << 29;     cin >> n >> W;     for (int i = 0, a; i < n; i++) {       cin >> a;       cnt50 += (a == 50);       cnt100 += (a == 100);     }     dp[0][0][0] = dp[0][0][1] = 0;     vis[0][0][0] = vis[0][0][1] = true;     ans[0][0][0] = ans[0][0][1] = 1;     queue<Node> q;     q.push(Node(0, 0, 0)), q.push(Node(0, 0, 1));     while (q.size()) {       Node tmp = q.front();       q.pop();       int x = tmp.x, y = tmp.y, tp = tmp.tp;       if (tp) {         for (int i = 0; i <= cnt50 - x; i++)           for (int j = 0; j <= cnt100 - y; j++)             if (i * 50 + j * 100 <= W && (i || j) && !vis[x + i][y + j][!tp]) {               q.push(Node(x + i, y + j, !tp));               dp[x + i][y + j][!tp] = dp[x][y][tp] + 1;               vis[x + i][y + j][!tp] = true;             }       } else {         for (int i = 0; i <= x; i++)           for (int j = 0; j <= y; j++)             if ((i || j) && i * 50 + 100 * j <= W && !vis[x - i][y - j][!tp]) {               q.push(Node(x - i, y - j, !tp));               dp[x - i][y - j][!tp] = dp[x][y][tp] + 1;               vis[x - i][y - j][!tp] = true;             }       }     }     dfs(cnt50, cnt100, 0);     if (dp[cnt50][cnt100][0] >= (1 << 29)) dp[cnt50][cnt100][0] = -1;     cout << dp[cnt50][cnt100][0] <<   n  << ans[cnt50][cnt100][0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 100005;   const int inf = 2147483647;   long long f[maxN], s[maxN], ans[maxN];   int n, m, c, g, r, l[maxN], a[maxN], sa[maxN];   int t[maxN * 8], b[maxN], h, mm;   int query(int l, int r) {     l = lower_bound(b + 1, b + 1 + c, l) - b;     r = upper_bound(b + 1, b + 1 + c, r) - b - 1;     l += mm - 1;     r += mm + 1;     int k = inf;     for (; l != r - 1; l >>= 1, r >>= 1) {       if ((l & 1) == 0) k = ((k) < (t[l + 1]) ? (k) : (t[l + 1]));       if ((r & 1) == 1) k = ((k) < (t[r - 1]) ? (k) : (t[r - 1]));     }     return k;   }   int ask(int x, int y) {     if (x < 0) x += g + r;     if (y < 0) y += g + r;     if (x <= y) return query(x, y);     int k = query(x, g + r - 1), t = query(0, y);     return ((k) < (t) ? (k) : (t));   }   void chg(int x, int d) {     x = lower_bound(b + 1, b + 1 + c, x) - b;     x += mm;     t[x] = d;     for (x >>= 1; x; x >>= 1)       t[x] = ((t[x + x]) < (t[x + x + 1]) ? (t[x + x]) : (t[x + x + 1]));   }   void Init() {     scanf( %d%d%d , &n, &g, &r);     for (int i = 0; i <= n; ++i) scanf( %d , l + i);     for (int i = n; i; --i) {       s[i] = s[i + 1] + l[i];       b[i] = s[i] % (g + r);     }     sort(b + 1, b + 1 + n);     c = unique(b + 1, b + 1 + n) - b - 1;     for (; (c + 1) >> h; ++h)       ;     mm = 1 << h;     for (int i = 1; i <= mm + 1 + c; ++i) t[i] = inf;     for (int i = n; i; --i) {       int k = ask((s[i] - (g + r - 1)) % (g + r), (s[i] - g) % (g + r));       if (k > n)         f[i] = s[i];       else         f[i] = (s[i] - s[k] + g + r - 1) / (g + r) * (g + r) + f[k];       chg(s[i] % (g + r), i);     }   }   void Work() {     long long p;     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d , a + i);       p = a[i] + l[0] + s[1];       int k = ask((p - (g + r - 1)) % (g + r), (p - g) % (g + r));       if (k > n)         printf( %I64d n , p);       else         printf( %I64d n , (p - s[k] + g + r - 1) / (g + r) * (g + r) + f[k]);     }   }   int main() {     Init();     Work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   int main() {     cin >> n >> m >> k;     if (k > n + m - 2) {       cout << -1 << endl;       return 0;     }     long long ans1, ans2;     if (k >= m) {       ans1 = n / (k - m + 2);     } else {       ans1 = (m / (k + 1)) * n;     }     if (k >= n) {       ans2 = m / (k - n + 2);     } else {       ans2 = (n / (k + 1)) * m;     }     cout << max(ans1, ans2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, dbg[100005];   pair<int, int> A[100005];   map<int, int> mp;   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a;       scanf( %d , &a);       mp[a]++;     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)       A[M++] = *it;     for (int i = 1; i < M; i++)       if (A[i].first != A[i - 1].first + 1) {         puts( NO );         return 0;       }     int p = 0;     for (int i = 0; i < M; i++) {       A[i].second--;       dbg[p++] = A[i].first;     }     for (int i = M - 1; i > 1; i--) {       while (A[i].second) {         if (!A[i - 1].second) {           puts( NO );           return 0;         }         A[i - 1].second--;         A[i].second--;         dbg[p++] = A[i - 1].first;         dbg[p++] = A[i].first;       }       if (!A[i - 1].second) {         puts( NO );         return 0;       }       A[i - 1].second--;       dbg[p++] = A[i - 1].first;     }     while (A[1].second) {       if (!A[0].second) {         puts( NO );         return 0;       }       A[0].second--;       A[1].second--;       dbg[p++] = A[0].first;       dbg[p++] = A[1].first;     }     if (A[0].second) {       puts( NO );       return 0;     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   int aa[120][5], kk[5];   int solve(int *bb, int n) {     int k, sum1, sum2, j, bad;     sum1 = sum2 = 0;     for (j = 0; j < 5; j++) {       if (aa[0][j] != -1) sum1 += (bb[j] + 1) * (250 - aa[0][j]) * 2;       if (aa[1][j] != -1) sum2 += (bb[j] + 1) * (250 - aa[1][j]) * 2;     }     if (sum1 <= sum2) return n * 32 + 1;     for (k = 0; k <= n * 32; k++) {       bad = 0;       for (j = 0; j < 5; j++)         if (aa[0][j] != -1) {           int lower = bb[j] == 5 ? 0 : (n + k) / (1 << (bb[j] + 1)) + 1 - kk[j];           int upper = (n + k) / (1 << bb[j]) - kk[j];           if (upper < 0 || lower > upper || lower > k) {             bad = 1;             break;           }         } else if ((bb[j] != 5 && kk[j] << (bb[j] + 1) <= (n + k)) ||                    (kk[j] << bb[j] > (n + k))) {           bad = 1;           break;         }       if (!bad) return k;     }     return n * 32 + 1;   }   int main() {     static int bb[5];     int n, i, j, b, b_, min, k;     scanf( %d , &n);     for (i = 0; i < n; i++)       for (j = 0; j < 5; j++) {         scanf( %d , &aa[i][j]);         if (aa[i][j] != -1) kk[j]++;       }     min = n * 32 + 1;     for (b = 0; b < 7776; b++) {       for (j = 0, b_ = b; j < 5; j++, b_ /= 6) bb[j] = b_ % 6;       k = solve(bb, n);       if (min > k) min = k;     }     printf( %d n , min == n * 32 + 1 ? -1 : min);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1000010];   int n;   bool check(int len) {     int now = 0, lft = 0;     bool flag = 1;     for (int i = 0; i < n; i++) {       if (s[i] ==  R ) {         flag = 0;         if (now + 1 != len) now++;       } else         now--;       if (now < lft) {         lft = now;         flag = 1;       }     }     return flag;   }   int main() {     scanf( %s , s);     n = strlen(s);     if (s[n - 1] ==  R ) {       for (int i = 0; i < n; i++) {         if (s[i] ==  R )           s[i] =  L ;         else           s[i] =  R ;       }     }     if (check(n + 5)) {       puts( 1 );       return 0;     }     int l = 0, r = n + 5, ret = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ret = mid, l = mid + 1;       else         r = mid - 1;     }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, flag;   vector<int> graph[100005];   bool vis[100005];   void dfs(int node, int parent) {     vis[node] = 1;     int x, u, v, i;     cnt++;     for (i = 0; i < graph[node].size(); i++) {       v = graph[node][i];       if (v == parent) continue;       if (vis[v] == 1)         flag = 1;       else         dfs(v, node);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     int i, j, k, u, v, x, sum = 0;     for (i = 0; i < m; i++) {       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     for (i = 1; i <= n; i++) {       if (vis[i] == 0) {         cnt = 0;         flag = 0;         dfs(i, 0);         if (flag == 1)           sum += cnt;         else           sum += (cnt - 1);       }     }     cout << n - sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> g(n);     int mm = 99999;     for (int i = 0; i < n; i++) {       cin >> g[i];       mm = min(mm, abs(g[i]));     }     sort(g.begin(), g.end());     int rest = k;     for (int i = 0; i < k; i++) {       if (i < g.size() && g[i] < 0) {         g[i] = -g[i];         rest--;       }     }     int ans = 0;     for (int i = 0; i < g.size(); i++) {       ans += g[i];     }     if (rest % 2) {       ans -= 2 * mm;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> g[500010];   int rad[2][500010], tata[500010], niv[500010];   char in[500010], vaz[500010], tip[500010];   struct edge {     int x, y, c;   };   edge v[500010];   int radacina(int x, int t) {     int y = x;     while (y != rad[t][y]) y = rad[t][y];     while (rad[t][x] != y) {       int aux = rad[t][x];       rad[t][x] = y;       x = aux;     }     return y;   }   void unite(int x, int y) {     x = radacina(x, 0);     y = radacina(y, 0);     rad[0][x] = y;   }   void dfs(int nod) {     vaz[nod] = 1;     for (int i = 0; i < g[nod].size(); i++) {       int vec = g[nod][i].first;       if (vaz[vec] == 1) continue;       niv[vec] = niv[nod] + 1;       tata[vec] = nod;       tip[vec] = g[nod][i].second;       dfs(vec);     }   }   int main() {     int n, k, m, x, y;     long long sol = 0;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= n; i++) rad[0][i] = rad[1][i] = i;     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       unite(x, y);       g[x].push_back({y, 1});       g[y].push_back({x, 1});     }     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &v[i].x, &v[i].y, &v[i].c);       if (radacina(v[i].x, 0) != radacina(v[i].y, 0)) {         unite(v[i].x, v[i].y);         in[i] = 1;         g[v[i].x].push_back({v[i].y, 0});         g[v[i].y].push_back({v[i].x, 0});       }     }     dfs(1);     tata[1] = 1;     int nr = 0;     for (int i = 1; i <= m; i++) {       if (in[i] == 1) continue;       x = v[i].x;       y = v[i].y;       x = radacina(x, 1);       y = radacina(y, 1);       while (x != y) {         if (niv[x] < niv[y]) swap(x, y);         sol += tip[x] * v[i].c;         nr += tip[x];         rad[1][x] = tata[x];         x = radacina(x, 1);       }     }     if (nr < k)       printf( -1 );     else       printf( %I64d , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long rot = 0;     long long last = 0;     long long ans;     for (int i = 0; i < m; i++) {       long long t;       cin >> t;       if (last > t) {         rot++;       }       last = t;     }     ans = rot * n + last - 1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f(int y) {     return y % 400 == 0 ? 2 : y % 100 == 0 ? 1 : y % 4 == 0 ? 2 : 1;   }   int main() {     int n, r = 0, t;     scanf( %d , &n);     t = f(n);     while (r % 7 != 0 || r == 0 || t != f(n)) {       r += f(n);       n++;     }     printf( %d n , n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long binSearch(long long n, long long pow2) {     long long L = 0, R = (n / pow2) + 10, M;     while (R - L > 1) {       M = (L + R) / 2;       double dM = M + 0.0;       if ((2.0 * dM + 1.0) * (pow2 + dM - 1.0) < n + 0.0)         L = M;       else         R = M;     }     if ((2 * L + 1) * (pow2 + L - 1) == n)       return L;     else if ((2 * R + 1) * (pow2 + R - 1) == n)       return R;     else       return -1;   }   int main() {     long long n;     cin >> n;     vector<long long> result;     for (long long pow2 = 1; pow2 - 1 <= n; pow2 *= 2) {       long long v = binSearch(n, pow2);       if (v != -1) result.push_back((2 * v + 1) * pow2);     }     sort(result.begin(), result.end());     if (result.size() == 0)       cout << -1;     else {       for (int i = 0; i < result.size(); i++) cout << result[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max(int a, int b) { return a > b ? a : b; }   pair<int, int> a[100], ans[1000], p;   vector<pair<int, int>> v;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     int i = 0;     while (i < k) {       if (a[0].first - a[n - 1].first >= -1) break;       a[0].first++;       a[n - 1].first--;       p.first = a[0].second;       p.second = a[n - 1].second;       v.push_back(p);       sort(a, a + n);       i++;     }     cout << a[n - 1].first - a[0].first <<     << i << endl;     for (int k = 0; k < i; k++) {       cout << v[k].second <<     << v[k].first << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<double> E[100010];   int color[100010];   int seen[100010];   set<int> sets[100010];   void dfs(int u) {     for (int i = 0; i < E[u].size(); ++i) {       int v = E[u][i];       if (color[u] != color[v]) sets[color[u]].insert(color[v]);       if (!seen[v]) {         seen[v] = true;         dfs(v);       }     }   }   int main() {     int n, m, u, v;     cin >> n >> m;     set<int> colorids;     for (int i = 0; i < n; ++i) {       cin >> color[i];       colorids.insert(color[i]);     }     for (int i = 0; i < m; ++i) {       cin >> u >> v;       --u;       --v;       E[u].push_back(v);       E[v].push_back(u);     }     memset(seen, 0, sizeof(seen));     for (int i = 0; i < n; ++i)       if (!seen[i]) {         seen[i] = true;         dfs(i);       }     int maxcolor = -1;     int maxn = -(1 << 30);     for (typeof(colorids.begin()) it = colorids.begin(); it != colorids.end();          ++it) {       int color = *it;       int ncolors = sets[*it].size();       if (maxn < ncolors) {         maxn = ncolors;         maxcolor = *it;       }     }     cout << maxcolor << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll N = 1e6 + 100;   ll n;   ll m;   ll **arr() {     ll **res = new ll *[n + 2];     for (ll i = 0; i < n + 2; ++i) {       res[i] = new ll[m + 2];       fill_n(res[i], m + 2, 0);     }     return res;   }   ll **inp;   ll **ans;   void pref(ll **a) {     for (ll i = 1; i <= n + 1; ++i) {       for (ll j = 1; j <= m + 1; ++j) {         a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];       }     }   }   ll sum(ll **a, ll il, ll ir, ll jl, ll jr) {     il = max(il, 1ll);     ir = min(ir, n);     jl = max(jl, 1ll);     jr = min(jr, m);     --il;     --jl;     return a[ir][jr] - a[ir][jl] - a[il][jr] + a[il][jl];   }   ll sq(ll first) { return first * first; }   bool check(ll t) {     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         ans[i][j] = sum(inp, i - t, i + t, j - t, j + t) == sq(2 * t + 1);       }     }     pref(ans);     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         if (sum(inp, i, i, j, j) && sum(ans, i - t, i + t, j - t, j + t) == 0) {           return false;         }       }     }     return true;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     inp = arr();     ans = arr();     for (ll i = 1; i <= n; ++i) {       string s;       cin >> s;       for (ll j = 1; j <= m; ++j) {         inp[i][j] = s[j - 1] ==  X ;       }     }     pref(inp);     ll lef = 0, rig = N;     while (rig - lef > 1) {       ll mid = (lef + rig) / 2;       if (check(mid)) {         lef = mid;       } else {         rig = mid;       }     }     assert(check(lef));     cout << lef <<   n ;     for (ll i = 1; i <= n; ++i) {       for (ll j = 1; j <= m; ++j) {         cout <<  .X [sum(ans, i, i, j, j)];       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const int N = 1e3 + 5;   int f[N][N];   struct node {     long long x, y;   } a[N], b[N];   bool cmp(node x, node y) { return x.y < y.y; }   long long area(node a, node b, node c) {     return a.x * b.y - a.y * b.x + b.x * c.y - b.y * c.x + c.x * a.y - c.y * a.x;   }   bool toleft(node a, node b, node c) {     if (c.y <= a.y || c.y > b.y) return 0;     return area(a, b, c) > 0;   }   int n, m;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) scanf( %lld%lld , &a[i].x, &a[i].y);     for (int i = 1; i <= m; ++i) scanf( %lld%lld , &b[i].x, &b[i].y);     sort(a + 1, a + n + 1, cmp);     int ans = 0;     for (int i = 1; i < n; ++i)       for (int j = i + 1; j <= n; ++j)         for (int k = 1; k <= m; ++k)           if (toleft(a[i], a[j], b[k])) f[i][j]++;     for (int i = 1; i < n; ++i)       for (int j = i + 1; j < n; ++j)         for (int k = j + 1; k <= n; ++k)           if (f[i][j] + f[j][k] == f[i][k]) ans++;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int INF = 2000000000;   const long long BIG = 1446803456761533460LL;   const int maxn = 5010;   int n, m, k, dp[maxn][maxn];   int poww(int a, int b) {     int r = 1;     while (b) {       if (b & 1) r = (1LL * (r) * (a)) % MOD;       a = (1LL * (a) * (a)) % MOD;       b >>= 1;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     int mi = poww(m, MOD - 2);     dp[0][0] = 1;     for (int i = 0; i < k; ++i) {       for (int j = 0; j < k + 1; ++j) {         dp[i + 1][j] = ((dp[i + 1][j]) + (1LL * dp[i][j] * j % MOD)) % MOD;         dp[i + 1][j + 1] =             ((dp[i + 1][j + 1]) + (1LL * dp[i][j] * (n - j) % MOD * mi % MOD)) %             MOD;       }     }     int ans = 0;     for (int i = 0; i < k + 1; ++i) ans = ((ans) + (dp[k][i])) % MOD;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400000;   int a[N], t[N], type[N], us[N];   int main() {     ios::sync_with_stdio(0);     int n, w, k;     cin >> n >> w >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> t[i];     }     int r = -1;     int curr_time = 0;     int earn = 0;     set<pair<int, int> > half, full;     int ans = 0;     for (int i = 0; i < n; i++) {       r = max(r, i - 1);       while (r < n - 1) {         r++;         int temp = curr_time;         vector<pair<int, int> > pers_full, pers_half, pers_type;         half.insert(make_pair(t[r], r));         pers_half.push_back(make_pair(+1, r));         pers_type.push_back(make_pair(r, type[r]));         type[r] = 0;         curr_time += (t[r] + 1) / 2;         if (half.size() > w) {           auto p = *half.begin();           curr_time -= (p.first + 1) / 2;           half.erase(half.find(p));           pers_half.push_back(make_pair(-1, p.second));           curr_time += p.first;           full.insert(p);           pers_full.push_back(make_pair(+1, p.second));           pers_type.push_back(make_pair(p.second, type[p.second]));           type[p.second] = 1;         }         if (curr_time > k) {           while (pers_full.size()) {             auto p = pers_full.back();             pers_full.pop_back();             if (p.first == -1)               full.insert(make_pair(t[p.second], p.second));             else               full.erase(make_pair(t[p.second], p.second));           }           while (pers_half.size()) {             auto p = pers_half.back();             pers_half.pop_back();             if (p.first == -1)               half.insert(make_pair(t[p.second], p.second));             else               half.erase(make_pair(t[p.second], p.second));           }           while (pers_type.size()) {             auto p = pers_type.back();             pers_type.pop_back();             type[p.first] = p.second;           }           curr_time = temp;           r--;           break;         } else {           earn += a[r];           us[r] = 1;         }       }       ans = max(earn, ans);       if (us[i] == 1) {         if (type[i] == 0) {           half.erase(make_pair(t[i], i));           curr_time -= (t[i] + 1) / 2;         } else {           full.erase(make_pair(t[i], i));           curr_time -= t[i];         }         earn -= a[i];         us[i] = 0;         while (full.size() && half.size() < w) {           auto p = *full.rbegin();           full.erase(full.find(p));           half.insert(p);           curr_time -= p.first;           curr_time += (p.first + 1) / 2;           type[p.second] = 0;         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sePuede(int rango[], int x) {     if (x % 2 == 1 && rango[0] == 1 && rango[x - 1] == 1) return true;     return false;   }   int main() {     int x = 0;     int impar = 0;     cin >> x;     int rango[x];     for (int y = 0; y < x; y++) {       cin >> rango[y];       rango[y] = rango[y] % 2;     }     if (sePuede(rango, x))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }