malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long x[1000005], r, cur[1000005];   long long len;   bool check(long long cnt) {     long long res = 0, s = 0;     for (int i = (1); i < (n + 1); i++) cur[i] = 0;     for (int i = (1); i < (r + 1); i++) s += x[i];     for (int i = 1; i <= n; i++) {       s += x[i + r];       if (i > r) {         s = s - x[i - r - 1] - cur[i - r - 1];       }       if (s < cnt) {         long long d = cnt - s;         res += d;         cur[i + r] += d;         s += d;         if (res > k) return 0;       }     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> r >> k;     for (int i = 1; i <= n; i++) {       cin >> x[i];     }     long long l = 0, r = 2e18, mid, ans = 0;     while (l <= r) {       mid = (l + r) >> 1ll;       if (check(mid)) {         l = mid + 1;         ans = max(ans, mid);       } else {         r = mid - 1;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 6 * 1e5;   const long long Q = 1e9 + 7;   int ans;   int a[10];   bool used[10];   void dfs(int i) {     used[i] = true;     if (!used[a[i]]) dfs(a[i]);   }   void gen(int i, int n) {     if (i == n + 1) {       bool ok = true;       for (int j = 1; j <= n; j++) {         for (int f = 1; f <= n; f++) used[f] = false;         dfs(j);         if (!used[1]) {           ok = false;           break;         }       }       if (ok) ans++;       return;     }     for (int j = 1; j <= n; j++) {       a[i] = j;       gen(i + 1, n);     }   }   int cnt(int n) {     ans = 0;     gen(1, n);     int tmp = ans;     return tmp;   }   int main() {     srand(time(NULL));     int n, k;     scanf( %d%d , &n, &k);     long long x = 1;     for (int i = 0; i < (n - k); i++) x = (x * (n - k)) % Q;     long long y = cnt(k);     cout << (x * y) % Q;     cerr << clock() / (CLOCKS_PER_SEC + 0.);     return 0;   }
#include <bits/stdc++.h>   int ans = 2, n, t;   double m;   struct T {     int x, t;   } a[1111];   bool my(T a, T b) { return (a.x < b.x); }   int main() {     scanf( %d%d , &n, &t);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].t);     std::sort(a + 1, a + n + 1, &my);     for (int i = 2; i <= n; i++) {       m = a[i].x - a[i - 1].x - (double)a[i].t / 2 - (double)a[i - 1].t / 2;       if (m > t)         ans += 2;       else if (m == t)         ++ans;     }     printf( %d n , ans);     return 0;   }
#include  bits/stdc++.h        using int64 = long long;   const int N = 305;   const int Q = 998244353;       inline void add(int &x, int y) {     x += y;     if (x >= Q) x -= Q;   }       int n, dep[N];   std::vector<int> e[N];   int f[N][N];  // x , y : max uncovered depth   int g[N][N];  // x , y : max extended length       void dfs(int x, int fa, int K) {     dep[x] = 0;     int nf[2][N];     int ng[2][N];     int cur = 0, nxt = 1;     memset(nf[cur], 0, sizeof(nf[cur]));     memset(ng[cur], 0, sizeof(ng[cur]));     ng[cur][0] = 1;         for (auto &y : e[x]) {       if (y == fa) {         continue;       }       dfs(y, x, K);       memset(nf[nxt], 0, sizeof(nf[nxt]));       memset(ng[nxt], 0, sizeof(ng[nxt]));       for (int i = 0; i <= dep[x]; ++i) {         if (nf[cur][i]) {           for (int j = 0; j <= dep[y]; ++j) {             int depth = std::max(i, j);             if (depth <= K) {               add(nf[nxt][depth], (int64)nf[cur][i] * f[y][j] % Q);             }           }           for (int j = 0; j <= K; ++j) {             if (j - 2 >= i) {               add(ng[nxt][j], (int64)nf[cur][i] * g[y][j] % Q);             } else {               add(nf[nxt][i], (int64)nf[cur][i] * g[y][j] % Q);             }           }         }       }       for (int i = 0; i <= K; ++i) {         if (ng[cur][i] > 0) {           for (int j = 0; j <= dep[y]; ++j) {             if (i - 2 >= j) {               add(ng[nxt][i], (int64)ng[cur][i] * f[y][j] % Q);             } else {               add(nf[nxt][j], (int64)ng[cur][i] * f[y][j] % Q);             }           }           for (int j = 0; j <= K; ++j) {             int depth = std::max(i, j);             add(ng[nxt][depth], (int64)ng[cur][i] * g[y][j] % Q);           }         }       }       std::swap(cur, nxt);       dep[x] = std::max(dep[x], dep[y]);     }         for (int i = 0; i <= dep[x]; ++i) {       if (i + 1 < K) {         add(f[x][i + 1], nf[cur][i]);       }       if (i + 1 <= K) {         add(g[x][K], nf[cur][i]);       }     }     for (int i = 0; i <= K; ++i) {       if (i > 0) {         add(g[x][i - 1], ng[cur][i]);       } else {         add(f[x][0], ng[cur][i]);       }       add(g[x][std::max(i - 1, K)], ng[cur][i]);     }     // printf( === %d n , x);     // for (int i = 0; i <= dep[x]; ++i) {     //   printf( %d  , f[x][i]);     // }     // puts(  );     // for (int i = 0; i <= K; ++i) {     //   printf( %d  , g[x][i]);     // }     // puts(  );         ++dep[x];   }       int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x = i, y = i + 1;       scanf( %d%d , &x, &y);       e[x].emplace_back(y);       e[y].emplace_back(x);     }     int res = Q - 1, pow2 = 1, inv = (Q + 1) / 2, inv2 = 1;     for (int i = 1; i <= n; ++i) {       add(pow2, pow2);       inv2 = (int64)inv2 * inv % Q;     }     for (int i = 1; i <= n; ++i) {       memset(f, 0, sizeof(f));       memset(g, 0, sizeof(g));       dfs(1, 0, i);       add(res, pow2);       for (int j = 0; j <= i; ++j) {         add(res, Q - g[1][j]);       }       // std::cout <<  :   << i <<     << res << std::endl;     }     printf( %d n , (int)((int64)res * inv2 % Q));   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   const long long o5 = 716327852;   const int N = 2e5 + 34;   long long f[N], o[N];   long long ans, n, w, h;   long long dp[N];   pair<long long, long long> a[N];   long long c(long long h, long long w) {     return (((f[h + w] * o[h]) % md) * o[w]) % md;   }   int main() {     o[0] = f[0] = 1;     o[100000] = o5;     for (long long i = 1; i < N; i++) f[i] = (f[i - 1] * i) % md;     for (long long i = 99999; i > 0; i--) o[i] = (o[i + 1] * (i + 1)) % md;     cin >> h >> w >> n;     ans = c(h - 1, w - 1);     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       a[i].first--;       a[i].second--;     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       dp[i] = c(a[i].second, a[i].first);       for (int j = 0; j < i; j++)         if (a[j].first <= a[i].first && a[j].second <= a[i].second)           dp[i] = (dp[i] -                    dp[j] * c(a[i].first - a[j].first, a[i].second - a[j].second) +                    md * md) %                   md;       ans = (ans + md * md - dp[i] * c(w - a[i].second - 1, h - a[i].first - 1)) %             md;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int k;   long long pa, pb;   long long A, B, C;   long long f[N][N];   void exgcd(int a, int b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   long long inv(int x) {     long long res, y;     exgcd(x, 1000000007, res, y);     res = ((res % 1000000007) + 1000000007) % 1000000007;     return res;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k >> pa >> pb;     A = pa * inv(pa + pb) % 1000000007;     B = pb * inv(pa + pb) % 1000000007;     C = pa * inv(pb) % 1000000007;     for (int i = k; i >= 1; i--)       for (int j = k; j >= 0; j--) {         if (i + j >= k) {           f[i][j] = i + C;           continue;         }         f[i][j] = (A * f[i + 1][j] + B * (f[i][i + j] + i)) % 1000000007;       }     cout << (f[1][0] + 1000000007) % 1000000007;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[202];   int height[202], best[202][3];   int N;   int getHeight(int ind, int parent) {     if (height[ind] != -1) return height[ind];     int ret = 1;     for (int i = 0; i < (int)adj[ind].size(); i++) {       if (adj[ind][i] == parent) continue;       ret = max(ret, getHeight(adj[ind][i], ind) + 1);     }     return height[ind] = ret;   }   int solve(int ind, int parent, int f) {     if (best[ind][f] != -1) return best[ind][f];     int ret = 0;     if (!f) {       for (int i = 0; i < (int)adj[ind].size(); i++) {         if (adj[ind][i] == parent) continue;         int a = 0, b = 0;         for (int j = 0; j < (int)adj[ind].size(); j++) {           if (adj[ind][j] == parent || j == i) continue;           int h = getHeight(adj[ind][j], adj[ind][j]);           if (h > a)             b = a, a = h;           else if (h > b)             b = h;         }         ret = max(ret, (a + b) * solve(adj[ind][i], ind, f + 1));       }     } else {       int a = 0, b = 0;       for (int j = 0; j < (int)adj[ind].size(); j++) {         if (adj[ind][j] == parent) continue;         int h = getHeight(adj[ind][j], adj[ind][j]);         if (h > a)           b = a, a = h;         else if (h > b)           b = h;         ret = max(ret, solve(adj[ind][j], ind, f));       }       ret = max(ret, a + b);     }     return best[ind][f] = ret;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     int ret = 0;     for (int i = 0; i < N; i++) {       memset(height, -1, sizeof height);       memset(best, -1, sizeof best);       getHeight(i, i);       ret = max(ret, solve(i, i, 0));     }     printf( %d n , ret);   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans[100001], curr, deg[100001] = {0};   vector<pair<int, int>> adj[100001];   void dfs(long long u, long long p) {     for (auto v : adj[u]) {       if (v.first == p) {         continue;       }       if (ans[v.second] == -1) {         ans[v.second] = curr++;       }       dfs(v.first, u);     }   }   void solve() {     long long n;     cin >> n;     long long m;     cin >> m;     if (n > m || n % 2 != m % 2) {       cout << -1 << endl;       return;     }     if (n == m && n == 0) {       cout << n << endl;       return;     }     if (n == m) {       cout << 1 << endl << n << endl;       return;     }     long long x = (m - n) / 2;     if ((x & n) == 0) {       cout << 2 << endl << n + x <<     << x << endl;       return;     }     {       cout << 3 << endl << n <<     << x <<     << x << endl;       return;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ans;   void merge(int l, int r, int lev) {     if (lev == 0) {       ans.push_back({l, r});       return;     }     int mid = (l + r) >> 1;     merge(l, mid, lev - 1);     merge(mid + 1, r, lev - 1);     int j = mid + 1;     for (int i = l; i <= mid; i++) {       ans.push_back({i, j});       j++;     }   }   int main(int argc, char** argv) {     int n;     scanf( %d , &n);     if (n == 1) {       printf( 0 );       return 0;     }     int t = 1;     int lev = -1;     while (t * 2 <= n) t *= 2, lev++;     merge(1, t, lev);     merge(n - t + 1, n, lev);     cout << ans.size() << endl;     for (int i = 0; i <= ans.size() - 1; i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxK = 53, MaxN = 2000005;   int N, K;   char A[MaxN];   char B[MaxN];   int id(char c) { return ( a  <= c && c <=  z ) ? c -  a  : c -  A  + 26; }   namespace KuhnMunkres {   const int MAX_N = 505;   const int INF = 100000000;   const int BASE = 1000;   int n;   int graph[MAX_N][MAX_N];   bool usedX[MAX_N];   bool usedY[MAX_N];   int linkTo[MAX_N];   int labelX[MAX_N];   int labelY[MAX_N];   bool findPath(int i) {     usedX[i] = true;     for (int j = 0; j < n; j++)       if (!usedY[j] && labelX[i] + labelY[j] == graph[i][j] && linkTo[j] == -1) {         usedY[j] = true;         linkTo[j] = i;         return true;       }     for (int j = 0; j < n; j++)       if (!usedY[j] && labelX[i] + labelY[j] == graph[i][j]) {         usedY[j] = true;         if (linkTo[j] == -1 || findPath(linkTo[j])) {           linkTo[j] = i;           return true;         }       }     return false;   }   int KuhnMunkres() {     memset(linkTo, -1, sizeof(linkTo));     memset(labelX, 0, sizeof(labelX));     memset(labelY, 0, sizeof(labelY));     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) labelX[i] = max(labelX[i], graph[i][j]);     for (int k = 0; k < n; k++)       while (true) {         memset(usedX, 0, sizeof(usedX));         memset(usedY, 0, sizeof(usedY));         if (findPath(k)) break;         int delta = INF;         for (int i = 0; i < n; i++)           if (usedX[i])             for (int j = 0; j < n; j++)               if (!usedY[j])                 delta = min(delta, labelX[i] + labelY[j] - graph[i][j]);         if (delta == 0 || delta == INF) break;         for (int i = 0; i < n; i++)           if (usedX[i]) labelX[i] -= delta;         for (int i = 0; i < n; i++)           if (usedY[i]) labelY[i] += delta;       }     int maxTotal = 0;     for (int i = 0; i < n; i++) maxTotal += labelX[i] + labelY[i];     return maxTotal;   }   };  // namespace KuhnMunkres   int main() {     cin.sync_with_stdio(false);     cin >> N >> K;     cin >> A;     cin >> B;     KuhnMunkres::n = K;     for (int i = 0; i < N; i++) {       int u = id(A[i]);       int v = id(B[i]);       KuhnMunkres::graph[u][v]++;     }     cout << KuhnMunkres::KuhnMunkres() << endl;     int array[MaxK];     for (int i = 0; i < K; i++) {       array[KuhnMunkres::linkTo[i]] = i;     }     for (int i = 0; i < K; i++) {       int b = array[i];       if (b < 26)         cout << (char)( a  + b);       else         cout << (char)( A  + b - 26);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[500500], y[500500];   long long minl[500500], maxl[500500], minr[500500], maxr[500500], ll, rr;   int n;   pair<long long, long long> a[500500];   bool ok(long long M) {     int j = 0;     for (int i = 0; i < n; i++) {       while ((j < n) && (a[j].first - a[i].first <= M)) j++;       if (max((i > 0) ? maxl[i - 1] : -10000000000LL,               (j < n) ? maxr[j] : -10000000000LL) -               min((i > 0) ? minl[i - 1] : 10000000000LL,                   (j < n) ? minr[j] : 10000000000LL) <=           M)         return 1;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 0; i < n; i++) a[i] = make_pair(x[i] - y[i], x[i] + y[i]);     sort(a, a + n);     for (int i = 0; i < n; i++) {       minl[i] = min((i > 0) ? minl[i - 1] : 10000000000LL, a[i].second);       maxl[i] = max((i > 0) ? maxl[i - 1] : -10000000000LL, a[i].second);     }     for (int i = n - 1; i >= 0; i--) {       minr[i] = min((i + 1 < n) ? minr[i + 1] : 10000000000LL, a[i].second);       maxr[i] = max((i + 1 < n) ? maxr[i + 1] : -10000000000LL, a[i].second);     }     ll = 0;     rr = 3e9;     for (int it = 0; it < 40; it++)       if (ok((ll + rr) / 2))         rr = (ll + rr) / 2;       else         ll = (ll + rr) / 2;     if (!ok(ll)) ll = rr;     printf( %.10lf n , ll * 1.0 / 2);   }
#include <bits/stdc++.h>   const int maxi = 2000000000;   const int maxq = 1000000000;   const double eps = 1e-10;   const double pi = 3.1415926535897932;   const double inf = 1e+18;   const int mo = 1000000007;   using namespace std;   int stn, ms[1111][1111], n, k, t, st[1111111], x, y, z, sum;   bool f[11111];   void rec(int x, int y) {     sum += ms[x][y];     if (x == n) {       stn++;       st[stn] = sum;     }     if (y) f[y] = true;     if (x < n)       for (int i = 0; i <= n; i++)         if (f[i] == false && (ms[x + 1][i] || i == 0)) rec(x + 1, i);     sum -= ms[x][y];     f[y] = false;   }   int main() {     cin >> n >> k >> t;     for (int i = 0; i < k; i++) {       cin >> x >> y >> z;       ms[x][y] = z;     }     for (int i = 0; i <= n; i++)       if (ms[1][i] || i == 0) rec(1, i);     sort(st + 1, st + stn + 1);     cout << st[t] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > dp;   const long long mod = 1e9 + 7;   bool used[1005][1005];   int n;   long long dfs(int opening, int closing) {     if (dp[opening][closing] != -1) return dp[opening][closing];     if (opening > n or closing >= n) return 0;     long long ans = 0;     if (opening < n) {       ans += dfs(opening + 1, closing);       if (!used[opening + 1][closing] and !used[opening][closing]) {         ans++;         used[opening][closing] = 1;       }     }     if (closing < opening) {       ans += dfs(opening, closing + 1);       if (!used[opening][closing + 1] and !used[opening][closing]) {         ans++;         used[opening][closing] = 1;       }     }     return dp[opening][closing] = ans % mod;   }   int main() {     dp = vector<vector<long long> >(1005, vector<long long>(1005, -1));     cin >> n;     cout << dfs(0, 0) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; ++i) v[i] = i + 2;     int n_colors = 1;     vector<bool> prime(n, true);     vector<int> colors(n);     for (int i = 0; v[i] <= sqrt(n + 1); ++i) {       if (prime[i]) {         for (int j = v[i] * v[i] - 2; j < n; j += v[i]) {           prime[j] = false;         }       }     }     for (int i = 0; i < n; ++i) {       if (prime[i]) {         colors[i] = 1;       } else {         n_colors = 2;         colors[i] = 2;       }     }     cout << n_colors << endl;     for (auto c : colors) cout << c <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_map<long long int, long long int> mp;   long long int n, m, k, ans;   long long int a[22][22];   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   void dfs1(int ex, int ey, int sx, int sy, long long int cur) {     if (sx == ex and sy == ey) mp[cur]++;     if (sx < ex) dfs1(ex, ey, sx + 1, sy, cur ^ (a[sx][sy]));     if (sy < ey) dfs1(ex, ey, sx, sy + 1, cur ^ (a[sx][sy]));   }   void dfs(int x, int y, long long int cur) {     if (x == n - 1 and y == m - 1) cur ^= a[x][y], ans += mp[cur ^ k];     if (x < n - 1) dfs(x + 1, y, cur ^ (a[x][y]));     if (y < m - 1) dfs(x, y + 1, cur ^ (a[x][y]));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     int mid = (n + m - 2) / 2;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i + j == mid) {           dfs1(i, j, 0, 0, 0);           dfs(i, j, 0);           mp.clear();         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2000050];   int b[2000050];   int c[2000050];   struct node {     int x, y;     node() {}     node(int xx, int yy) { x = xx, y = yy; }   } q[2000050];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       scanf( %d , &b[i]);       c[b[i]] = i;     }     for (int i = 1; i <= n; ++i) a[i] = c[a[i]];     int tail = 0;     int ans = 0;     for (int i = n; i > 0; --i) {       int p = -1;       for (int j = n; j > 0; --j)         if (a[j] == i) {           p = j;           break;         }       if (p == i) continue;       int now = p + 1;       while (p != i) {         while (now < n && a[now] > p) now++;         q[tail++] = node(p, now);         swap(a[p], a[now]);         ans += now - p;         p = now;         now++;       }     }     printf( %d n , ans);     printf( %d n , tail);     for (int i = 0; i < tail; ++i) {       printf( %d %d n , q[i].x, q[i].y);     }   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int bags[4];     int flag = 0;     for (int i = 0; i < 4; i++) {       cin >> bags[i];     }     if (bags[0] + bags[1] == bags[2] + bags[3]) {       cout <<  YES n ;     } else if (bags[0] + bags[2] == bags[1] + bags[3]) {       cout <<  YES n ;     } else if (bags[0] + bags[3] == bags[1] + bags[2]) {       cout <<  YES n ;     } else if (bags[0] + bags[1] + bags[2] == bags[3] ||                bags[0] + bags[2] + bags[3] == bags[1] ||                bags[0] + bags[1] + bags[3] == bags[2] ||                bags[3] + bags[1] + bags[2] == bags[0]) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     string s, t;     cin >> s >> t;     int ind = -1;     for (int i = 0; i < s.length(); i++) {       if (s[i] !=  0 )         break;       else         ind = i;     }     s = s.substr(ind + 1);     ind = -1;     for (int i = 0; i < t.length(); i++) {       if (t[i] !=  0 )         break;       else         ind = i;     }     t = t.substr(ind + 1);     if (s.length() != t.length()) {       if (s.length() > t.length())         cout <<  > n ;       else         cout <<  < n ;       return 0;     }     for (int i = 0; i < s.length(); i++) {       if (s[i] != t[i]) {         if (s[i] > t[i])           cout <<  > n ;         else           cout <<  < n ;         return 0;       }     }     cout <<  = n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h;     cin >> n >> h;     vector<pair<int, int>> zeros;     int a, b;     for (int i = 0; i < n; i++) {       cin >> a >> b;       zeros.push_back(make_pair(a, b));     }     int sol = 0;     int pa, pb, ib, c1;     pa = zeros[0].first;     pb = zeros[0].second;     ib = 0;     c1 = 0;     while (c1 < h) {       int d = h - c1;       if (ib + 1 >= n) {         pb = pb + d;         c1 = h;         break;       }       if (d <= zeros[ib + 1].first - pb) {         pb = pb + d;         c1 = h;         break;       }       c1 += zeros[ib + 1].first - pb;       pb = zeros[ib + 1].second;       ib++;     }     sol = pb - pa;     for (int i = 1; i < n; i++) {       int ci1 = zeros[i].first - zeros[i - 1].second;       pa = zeros[i].first;       if (h < ci1) {         pb = zeros[i].second;         ib = i;         c1 = 0;         while (c1 < h) {           int d = h - c1;           if (ib + 1 >= n) {             pb = pb + (h - c1);             c1 = h;             break;           }           if (d <= zeros[ib + 1].first - pb) {             pb = pb + (h - c1);             c1 = h;             break;           }           c1 += zeros[ib + 1].first - pb;           pb = zeros[ib + 1].second;           ib++;         }       } else {         c1 = h - ci1;         while (c1 < h) {           int d = h - c1;           if (ib + 1 >= n) {             pb = pb + (h - c1);             c1 = h;             break;           }           if (d <= zeros[ib + 1].first - pb) {             pb = pb + (h - c1);             c1 = h;             break;           }           c1 += zeros[ib + 1].first - pb;           pb = zeros[ib + 1].second;           ib++;         }       }       sol = max(sol, pb - pa);     }     cout << sol;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   int a[105], n, dp[105][105][2], cnt = 0;   int main() {     scanf( %d , &n);     cnt = (n + 1) / 2;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i]) {         if (a[i] & 1) --cnt;       }     }     memset(dp, INF, sizeof(dp));     dp[0][0][0] = 0;     dp[0][0][1] = 0;     for (int i = 1; i <= n; ++i) {       if (a[i]) {         int t = a[i] & 1;         for (int j = 0; j <= min(cnt, i - 1); ++j)           dp[i][j][t] = min(dp[i - 1][j][t], dp[i - 1][j][1 - t] + 1);       } else {         for (int j = 1; j <= min(cnt, i); ++j)           dp[i][j][1] = min(dp[i - 1][j - 1][1], dp[i - 1][j - 1][0] + 1);         for (int j = 0; j <= min(cnt, i - 1); ++j)           dp[i][j][0] = min(dp[i - 1][j][1] + 1, dp[i - 1][j][0]);       }     }     printf( %d n , min(dp[n][cnt][0], dp[n][cnt][1]));   }