malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int h, t;   vector<vector<int> > graph;   vector<int> lvl;   int edges[100005][2];   int stat[100005];   int check(int u, int v) {     int len = h + t;     int ht = 0;     int tt = 0;     stat[u] = -1;     stat[v] = -1;     int i = 0;     while (ht < len) {       int a = graph[u][i++];       if (a == -1) break;       if (stat[a] == -1) continue;       stat[a] = 1;       ht++;     }     i = 0;     while (tt < t) {       int a = graph[v][i++];       if (a == -1) break;       if (stat[a] == -1) continue;       if (stat[a] == 1) {         if (ht > h)           ht--;         else           continue;       }       stat[a] = 2;       tt++;     }     if (ht >= h && tt >= t) return 1;     stat[u] = 0;     stat[v] = 0;     i = 0;     while (ht > 0) {       int a = graph[u][i++];       if (stat[a] == 1) {         ht--;         stat[a] = 0;       }     }     i = 0;     while (tt > 0) {       int a = graph[v][i++];       if (stat[a] == 2) tt--;       stat[a] = 0;     }     return 0;   }   void print(int n) {     for (int i = 0; i <= n && h > 0; i++) {       if (stat[i] == 1) {         cout << i <<    ;         h--;       }     }     cout << endl;     for (int i = 0; i <= n && t > 0; i++) {       if (stat[i] == 2) {         cout << i <<    ;         t--;       }     }   }   int main() {     int n, m;     cin >> n >> m >> h >> t;     for (int i = 0; i <= n; i++) {       lvl.push_back(0);       graph.push_back(vector<int>());     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);       edges[i][0] = a;       edges[i][1] = b;     }     for (int i = 0; i <= n; i++) {       graph[i].push_back(-1);     }     for (int i = 0; i < m; i++) {       if (check(edges[i][0], edges[i][1])) {         cout <<  YES  << endl;         cout << edges[i][0] <<     << edges[i][1] << endl;         print(n);         return 0;       }       if (check(edges[i][1], edges[i][0])) {         cout <<  YES  << endl;         cout << edges[i][1] <<     << edges[i][0] << endl;         print(n);         return 0;       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[3010];   pair<int, long long> dp[3010][3010], tmp[3010];   int v[3010], sz[3010];   void merge(int x, int y) {     for (int i = 0; i < sz[x] + sz[y]; i++) tmp[i] = pair<int, long long>(-1, 0);     for (int i = 0; i < sz[x]; i++)       for (int j = 0; j < sz[y]; j++) {         tmp[i + j] = max(tmp[i + j],                          pair<int, long long>(dp[x][i].first + dp[y][j].first,                                               dp[x][i].second + dp[y][j].second));         tmp[i + j + 1] = max(             tmp[i + j + 1], pair<int, long long>(dp[x][i].first + dp[y][j].first +                                                      (dp[y][j].second > 0),                                                  dp[x][i].second));       }     sz[x] += sz[y];     for (int i = 0; i < sz[x]; i++) dp[x][i] = tmp[i];   }   void dfs(int x, int p) {     sz[x] = 1;     dp[x][0] = pair<int, long long>(0, v[x]);     for (int i = 0; i < adj[x].size(); i++) {       int y = adj[x][i];       if (y == p) continue;       dfs(y, x);       merge(x, y);     }   }   void solve() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) v[i] = 0, adj[i].clear();     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       v[i] -= x;     }     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       v[i] += x;     }     for (int i = 1, x, y; i < n; i++) {       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs(1, 0);     cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << endl;   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   bool DEB = false;   void MP() {     ios::sync_with_stdio(false);     cin.tie(0);   }   #pragma comment(linker,  /STACK:256000000 )   const long long inf = (long long)1e13 + 9;   const int MAX = (int)3e5 + 10;   int a[MAX];   long long t[4 * MAX][2][2];   inline void f(int v, int a, int b) {     t[v][0][0] = min({t[a][0][0], t[b][0][0], t[a][0][1] + t[b][0][0],                       t[a][0][0] - t[b][1][1]});     t[v][0][1] = min({t[a][0][1], t[b][0][1], t[a][0][1] + t[b][0][1],                       t[a][0][0] - t[b][1][0]});     t[v][1][0] = max({t[a][1][0], t[b][1][0], t[a][1][1] + t[b][1][0],                       t[a][1][0] - t[b][0][1]});     t[v][1][1] = max({t[a][1][1], t[b][1][1], t[a][1][1] + t[b][1][1],                       t[a][1][0] - t[b][0][0]});   }   inline void build(int v, int lv, int rv) {     if (lv + 1 == rv) {       t[v][0][0] = a[lv];       t[v][0][1] = inf;       t[v][1][0] = a[lv];       t[v][1][1] = -inf;       return;     }     int m = lv + rv >> 1;     build(v << 1, lv, m);     build((v << 1) + 1, m, rv);     f(v, v << 1, (v << 1) + 1);   }   inline void update(int v, int lv, int rv, int id, int val) {     if (lv + 1 == rv) {       t[v][0][0] = val;       t[v][0][1] = inf;       t[v][1][0] = val;       t[v][1][1] = -inf;       return;     }     int m = lv + rv >> 1;     if (id < m)       update(v << 1, lv, m, id, val);     else       update((v << 1) + 1, m, rv, id, val);     f(v, v << 1, (v << 1) + 1);   }   void solve() {     int n, q;     cin >> n >> q;     for (int i = 0; i < (n); ++i) cin >> a[i];     build(1, 0, n);     cout << (max(t[1][1][0], t[1][1][1])) <<   n ;     while (q--) {       int l, r;       cin >> l >> r;       --l, --r;       swap(a[l], a[r]);       update(1, 0, n, l, a[l]);       update(1, 0, n, r, a[r]);       cout << (max(t[1][1][0], t[1][1][1])) <<   n ;     }   }   signed main() {     MP();     int T;     for (cin >> T; T--;) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y;     cin >> n >> m;     vector<pair<int, int>> v;     for (int i = 0; i < m; i++) {       cin >> x >> y;       v.push_back({y, x});     }     sort(v.begin(), v.end());     int ans = 0, counter = 0;     for (int i = m - 1; i >= 0; i--) {       if (counter + v[i].second <= n) {         ans += v[i].first * v[i].second;         counter += v[i].second;       } else {         ans += v[i].first * (n - counter);         break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int val[300005];   long long num[300005];   int main() {     int n;     scanf( %d , &n);     long long s = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%lld , &val[i], &num[i]);       s += val[i];     }     long long ans = 0;     for (int i = 61; i >= 0; i--) {       long long s0 = 0, s1 = 0;       for (int j = 1; j <= n; j++)         if ((num[j] & (1LL << i)) && (num[j] >> i << i) == num[j]) {           bool v = (val[j] > 0) ^ (s > 0);           for (int k = 0; k < 62; k++)             if ((num[j] & ans) & (1LL << k)) v ^= 1;           if (v)             s0 += abs(val[j]);           else             s1 += abs(val[j]);         }       if (s1 > s0) ans ^= (1LL << i);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     while (n--) {       cout << 1 <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   const int N = 5054, mod = 1000000007;   int n, K;   int f[N];   long long PowerMod(long long a, int n, long long c = 1) {     for (; n; n >>= 1, a = a * a % mod)       if (n & 1) c = c * a % mod;     return c;   }   int main() {     int i, j, x, in, ans = 0;     std::ios::sync_with_stdio(false), cin.tie(NULL);     cin >> n >> K, *f = 1, in = PowerMod(n, mod - 2);     for (i = 0; i < n; ++i) {       cin >> x;       for (j = i + 1; j; --j) f[j] = ((long long)f[j] * x + mod - f[j - 1]) % mod;       *f = (long long)*f * x % mod;     }     for (x = mod - 1, i = 1; i <= n && i <= K; ++i)       x = x * (K - i + 1ll) % mod * in % mod,       ans = (ans + (long long)x * f[i]) % mod;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int seq[100050];   int n;   int l[40], r[40];   int dp[100050];   bool chk() {     for (int i = 1; i <= n; ++i)       if (seq[i] != i) return false;     return true;   }   void dfs(int dep) {     if (chk()) {       printf( %d n , dep);       for (int i = dep; i >= 1; --i) printf( %d %d n , l[i], r[i]);       exit(0);     }     if (dep == 3) return;     for (int i = 1; i <= n - 1; ++i) {       if (seq[i] != i &&           (abs(seq[i] - seq[i - 1]) != 1 || abs(seq[i] - seq[i + 1]) != 1)) {         for (int j = i + 1; j <= n; ++j)           if (seq[j] != j &&               (abs(seq[j] - seq[j + 1]) != 1 || abs(seq[j] - seq[j - 1]) != 1)) {             l[dep + 1] = i;             r[dep + 1] = j;             reverse(seq + i, seq + j + 1);             dfs(dep + 1);             reverse(seq + i, seq + j + 1);           }       }     }   }   int main() {     seq[0] = -1;     scanf( %d , &n);     seq[n + 1] = -1;     for (int i = 1; i <= n; ++i) scanf( %d , &seq[i]);     dfs(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> Height(n);     vector<int> count(n, 0);     for (int i = 0; i < n; i++) {       cin >> Height[i];     }     int x = 0, after = 1, befor = 0;     while (after < n && Height[x] >= Height[after]) {       count[0]++;       x++;       after++;     }     for (int i = 1; i < n - 1; i++) {       x = i, after = i + 1, befor = i - 1;       while (befor >= 0 && Height[x] >= Height[befor]) {         count[i]++;         x--;         befor--;       }       x = i;       while (after < n && Height[x] >= Height[after]) {         count[i]++;         x++;         after++;       }     }     x = n - 1;     befor = n - 2;     while (befor >= 0 && Height[x] >= Height[befor]) {       count[n - 1]++;       x--;       befor--;     }     sort(count.begin(), count.end());     cout << count[count.size() - 1] + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, fl = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch -  0 );     return x * fl;   }   const int NN = 500000 + 17;   const int MM = 10000000 + 17;   void open() {     freopen( a.in ,  r , stdin);     freopen( a.out ,  w , stdout);   }   int n, maxx;   int pw[NN], miu[MM], pri[NN * 4], cnt;   int tax[MM], bs[MM], f[MM], has[MM];   bool notp[MM];   const int mod = 1e9 + 7;   int add(int x, int y) { return (x + y) % mod; }   int getmod(int x) { return (x + mod) % mod; }   void prework() {     pw[0] = 1;     for (int i = 1; i <= n; i++) pw[i] = add(pw[i - 1], pw[i - 1]);     miu[1] = 1;     for (int i = 2; i <= maxx; i++) {       if (!notp[i]) {         pri[++cnt] = i;         miu[i] = -1;       }       for (int j = 1; j <= cnt && i * pri[j] <= maxx; j++) {         notp[i * pri[j]] = true;         if (i % pri[j] == 0) {           miu[i * pri[j]] = 0;           break;         }         miu[i * pri[j]] = -miu[i];       }     }   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       int x = read();       maxx = max(maxx, x);       tax[x]++;     }     prework();     for (int i = maxx; i; i--)       for (int j = i; j <= maxx; j += i) {         bs[i] += tax[j];       }     for (int i = maxx; i; i--) {       f[i] = (pw[bs[i]] - 1 + mod) % mod;       for (int j = i + i; j <= maxx; j += i) {         f[i] = (f[i] - f[j] + mod) % mod;       }     }     for (int i = 1; i <= maxx; i++)       for (int j = i; j <= maxx; j += i) {         has[j] = add(has[j], 1LL * getmod(miu[i]) * bs[i] % mod);       }     int ans = 0;     for (int i = 2; i <= maxx; i++) {       ans = add(ans, 1LL * has[i] * f[i] % mod);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Segment {     int x1, y1, x2, y2;   };   struct Line {     long long a, b, c;   };   int n;   Segment seg[1005];   map<pair<int, int>, int> intersectCount;   unordered_map<int, int> toSubtract;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long det(long long a11, long long a12, long long a21, long long a22) {     return a11 * a22 - a12 * a21;   }   pair<int, int> intersectLines(const Line &l1, const Line &l2) {     long long detS = det(l1.a, l1.b, l2.a, l2.b);     if (detS == 0) return make_pair(0x3f3f3f3f, 0x3f3f3f3f);     long long detX = det(l1.c, l1.b, l2.c, l2.b);     long long detY = det(l1.a, l1.c, l2.a, l2.c);     if (detX % detS || detY % detS) return make_pair(0x3f3f3f3f, 0x3f3f3f3f);     return make_pair(detX / detS, detY / detS);   }   Line segmentToLine(const Segment &s) {     Line l;     l.a = s.y1 - s.y2;     l.b = s.x2 - s.x1;     l.c = l.a * s.x1 + l.b * s.y1;     return l;   }   pair<int, int> intersectSegments(const Segment &s1, const Segment &s2) {     return intersectLines(segmentToLine(s1), segmentToLine(s2));   }   bool pointInSegment(const pair<int, int> &A, const Segment &s) {     return min(s.x1, s.x2) <= A.first && A.first <= max(s.x1, s.x2) &&            min(s.y1, s.y2) <= A.second && A.second <= max(s.y1, s.y2);   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> seg[i].x1 >> seg[i].y1 >> seg[i].x2 >> seg[i].y2;     }     long long sol = 0;     for (int i = 1; i <= n; ++i) {       sol += gcd(abs(seg[i].x1 - seg[i].x2), abs(seg[i].y1 - seg[i].y2)) + 1;     }     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         pair<int, int> A = intersectSegments(seg[i], seg[j]);         if (A.first == 0x3f3f3f3f) continue;         if (pointInSegment(A, seg[i]) && pointInSegment(A, seg[j])) {           ++intersectCount[A];         }       }     }     int S = 0;     for (int i = 1; i <= n; ++i) {       S += i;       toSubtract[S] = i;     }     for (auto first : intersectCount) {       assert(toSubtract.count(first.second));       sol -= toSubtract[first.second];     }     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long C[1007][1007];   int main() {     long long n, m, k;     memset(C, 0, sizeof(C));     C[0][0] = 1;     for (long long i = 1; i <= 1000; i++) {       C[i][0] = 1;       for (long long j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;     }     while (cin >> n >> m >> k) {       long long a = n - 2 * k - 1;       long long b = m - 2 * k - 1;       if (a < 0 || b < 0)         cout << 0 << endl;       else         cout << (C[2 * k + a][a] * C[2 * k + b][b]) % 1000000007 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct _IO {     _IO() {       ios::sync_with_stdio(0);       cin.tie(0);     }   } _io;   using ll = long long;   using db = long double;   using pi = pair<int, int>;   using mi = map<int, int>;   const int N = 6e5 + 5, M = 1e9 + 7;   using vi = vector<int>;   ll ri() {     ll x;     cin >> x;     return x;   }   void prl() { cout <<   n ; }   template <class T, class... U>   void prl(T x, U... y) {     cout << x <<    , prl(y...);   }   template <class T, class U>   ostream &operator<<(ostream &out, pair<T, U> p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <class T>   ostream &operator<<(ostream &out, vector<T> &v) {     cout <<  { ;     for (int i = (0); i < (v.size()); ++i) {       if (i) cout <<  ,  ;       cout << v[i];     }     cout <<  } ;     return out;   }   struct cp {     db x, y;     cp(db a = 0, db b = 0) : x(a), y(b) {}     cp operator-(const cp &b) const { return cp(x - b.x, y - b.y); }     cp operator+(const cp &b) const { return cp(x + b.x, y + b.y); }     cp operator*(const cp &b) const {       return cp(x * b.x - y * b.y, x * b.y + y * b.x);     }     cp operator/(const int &b) const { return cp(x / b, y / b); }   };   const db PI = acos(-1);   int rev[N];   void init(int n) {     for (int i = 0, lim = __builtin_ctz(n); i < n; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (lim - 1));   }   void fft(cp *a, int n, int f) {     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int l = 2, m = 1; l <= n; m = l, l <<= 1)       for (cp *p = a, wn(cos(2 * PI / l), sin(f * 2 * PI / l)); p != a + n;            p += l)         for (cp *q = p, w(1, 0); q != p + m; q++, w = w * wn) {           cp t = *(q + m) * w;           *(q + m) = *q - t;           *q = *q + t;         }     if (f == -1)       for (int i = 0; i < n; i++) a[i] = a[i] / n;   }   cp a[N];   signed main() {     int n = ri(), m = ri(), k = ri();     string s, t, p =  ATCG ;     cin >> s >> t;     int len = 1;     while (len < n + m) len *= 2;     init(len);     vi ans(len), sum(n + 1);     for (int c = (0); c < (4); ++c) {       memset(a, 0, sizeof a);       for (int i = (0); i < (n); ++i) {         if (s[i] == p[c]) {           sum[i + 1] = 1;         } else {           sum[i + 1] = 0;         }         sum[i + 1] = sum[i] + sum[i + 1];       }       for (int i = (0); i < (n); ++i) {         if (sum[min(n, i + k + 1)] - sum[max(0, i - k)] >= 1) {           a[i].x = 1;         }       }       for (int i = (0); i < (m); ++i) {         if (t[i] == p[c]) {           a[m - i - 1].y = 1;         }       }       fft(a, len, 1);       for (int i = (0); i < (len); ++i) {         a[i] = a[i] * a[i];       }       fft(a, len, -1);       for (int i = (0); i < (len); ++i) {         ans[i] += (int)(a[i].y / 2 + 0.5);       }     }     int cnt = 0;     for (int i = (0); i < (n); ++i)       if (ans[i] == m) ++cnt;     prl(cnt);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200010, M = 2000010, INF = 0x3f3f3f3f;   inline long long max(long long x, long long y) { return x > y ? x : y; }   inline long long min(long long x, long long y) { return x < y ? x : y; }   inline void swap(long long &x, long long &y) { x ^= y ^= x ^= y; }   long long head[N], ver[M], Next[M], tot;   long long n, m, k, t, top, num, d[N], id[N], st[N], vis[N], size[N], f[N][20];   vector<long long> v[N];   bool cmp(long long x, long long y) { return id[x] < id[y]; }   void add(long long x, long long y) {     ver[++tot] = y, Next[tot] = head[x], head[x] = tot;   }   void dfs(long long x, long long fa) {     d[x] = d[fa] + 1;     id[x] = ++num;     for (long long i = head[x]; i; i = Next[i]) {       long long y = ver[i];       if (y == fa) continue;       f[y][0] = x;       for (long long j = 1; j <= t; j++) f[y][j] = f[f[y][j - 1]][j - 1];       dfs(y, x);     }   }   long long lca(long long x, long long y) {     if (d[x] > d[y]) swap(x, y);     for (long long i = t; i >= 0; i--)       if (d[f[y][i]] >= d[x]) y = f[y][i];     if (x == y) return x;     for (long long i = t; i >= 0; i--)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   long long dp(long long x, long long fa) {     long long res = 0;     size[x] = vis[x];     for (long long i = 0; i < (long long)v[x].size(); i++)       if (v[x][i] != fa) res += dp(v[x][i], x);     if (size[x]) {       for (long long i = 0; i < (long long)v[x].size(); i++)         if (v[x][i] != fa) res += (size[v[x][i]]);     } else {       long long cnt = 0;       for (long long i = 0; i < (long long)v[x].size(); i++)         if (v[x][i] != fa) cnt += (size[v[x][i]]);       if (cnt == 1)         size[x] = 1;       else if (cnt > 1)         res++;     }     return res;   }   int main() {     scanf( %lld , &n);     t = (long long)(log(n) / log(2)) + 1;     for (long long i = 1; i < n; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       add(x, y), add(y, x);     }     dfs(1, 0);     scanf( %lld , &m);     while (m--) {       scanf( %lld , &k);       top = 0;       for (long long i = 1; i <= k; i++) {         long long x;         scanf( %lld , &x);         st[++top] = x;         vis[x] = 1;       }       long long flag = 0;       for (long long i = 1; i <= top; i++) flag |= vis[f[st[i]][0]];       sort(st + 1, st + top + 1, cmp);       for (long long i = 1; i < k; i++) {         long long l = lca(st[i], st[i + 1]);         if (l != st[i] && l != st[i + 1]) st[++top] = l;       }       st[++top] = 1;       sort(st + 1, st + top + 1);       top = unique(st + 1, st + top + 1) - st - 1;       sort(st + 1, st + top + 1, cmp);       for (long long i = 2; i <= top; i++) {         long long l = lca(st[i - 1], st[i]);         v[l].push_back(st[i]);       }       if (flag)         puts( -1 );       else         printf( %lld n , dp(st[1], 0));       for (long long i = 1; i <= top; i++) v[st[i]].clear();       for (long long i = 1; i <= top; i++) vis[st[i]] = 0;     }     return 0;   }
#include <bits/stdc++.h>   int inp() {     char c = getchar();     int neg = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * neg;   }   int a[110];   int f[110][110][110][2];   bool flg[110];   int main() {     int n = inp();     int l1 = (n >> 1), l2 = (n >> 1);     if (n & 1) l2++;     int ans = 0;     for (int i = 1; i <= n; i++) {       a[i] = inp();       if (a[i] != 0) {         if (a[i] & 1)           l2--;         else           l1--;         if (a[i - 1] && ((a[i] ^ a[i - 1]) & 1)) ans++;       } else         flg[i] = true;     }     memset(f, 0x3f, sizeof(f));     f[1][l1][l2][0] = f[1][l1][l2][1] = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= n; j++)         for (int u = 0; u <= n; u++) {           for (int k = 0; k <= 1; k++) {             if (f[i][j][u][k] > 1e9) continue;             if (flg[i - 1]) a[i - 1] = k;             if (a[i] != 0) {               if (i > 1 && ((a[i] ^ a[i - 1]) & 1)) f[i][j][u][k]++;               f[i + 1][j][u][k] = f[i][j][u][k];               continue;             }             if (j) {               int ret = f[i][j][u][k];               if (i > 1) ret += (a[i - 1] & 1);               f[i + 1][j - 1][u][0] = std::min(f[i + 1][j - 1][u][0], ret);             }             if (u) {               int ret = f[i][j][u][k];               if (i > 1) ret += (a[i - 1] & 1) ^ 1;               f[i + 1][j][u - 1][1] = std::min(f[i + 1][j][u - 1][1], ret);             }           }         }     printf( %d n , std::min(f[n + 1][0][0][0], f[n + 1][0][0][1]));   }