malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>      using namespace std;      int main() {     ios::sync_with_stdio(0);     cout.tie(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> ar(n);       long long cnt = 0;       vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));       for (int i = 0; i < n; i++) {         cin >> ar[i];         for (int j = 0; j < m; j++) {           dp[i][j] = (ar[i][j] ==  * );           cnt += (ar[i][j] ==  * );         }       }       for (int i = 0; i < n; i++) {         for (int j = 1; j < m; j++) {           dp[i][j] += dp[i][j - 1];         }       }       // 1st Sol. : from base to head but with binary search on answer - O(N^3 . Log(N)).       // 2nd Sol. : let * in position [i, j] be the head of k-tree and try to go downward - O(N^3).       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (ar[i][j] ==  * ) {             int rows = i + 1;             int cols_left = j - 1;             int cols_right = j + 1;             int temp = 0;             bool ok = true;             while (rows < n && ok) {               int cur = dp[rows][cols_right];               if (cols_left - 1 >= 0) {                 cur -= dp[rows][cols_left - 1];               }               if (cur == cols_right - cols_left + 1) {                 temp++;                 rows++;                 cols_left--;                 cols_right++;               } else {                 ok = false;               }             }             cnt += temp;           }         }       }       cout << cnt <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   struct pt {     long long x, y;   } a[3005];   long long n, m, q, lim, las, pre[3005], suf[3005], rc[3005][3005], c, x, y, z,       v, ans;   long long cmp(pt x, pt y) { return x.y < y.y || (x.y == y.y && x.x < y.x); }   long long cb(long long x) { return (x + 1) * x >> 1; }   int main() {     scanf( %lld , &n), scanf( %lld , &m), scanf( %lld , &q), scanf( %lld , &lim);     for (long long i = 1; i <= q; i++)       scanf( %lld , &a[i].x), scanf( %lld , &a[i].y);     sort(a + 1, a + q + 1, cmp);     for (long long i = 1; i <= q; i++) rc[a[i].x][++rc[a[i].x][0]] = i;     a[q + 1].y = m + 1;     for (long long i = 1; i <= n; i++) {       memset(pre, 255, sizeof pre), memset(suf, 255, sizeof suf), las = 0;       for (long long j = 1; j <= q; j++)         if (a[j].x >= i) suf[pre[j] = las] = j, las = j;       suf[pre[q + 1] = las] = q + 1, v = cb(m), x = y = suf[0], c = 1;       while (suf[x] > -1) {         while (c + 1 < lim && suf[suf[y]] > -1) c++, y = suf[y];         if (c < lim) v -= (a[x].y - a[pre[x]].y) * (a[suf[y]].y - a[x].y);         x = suf[x], c--;       }       x = suf[0];       while (x) v -= cb(a[x].y - a[pre[x]].y - 1), x = suf[x];       for (long long j = n; j >= i; j--) {         ans += v;         if (!v) break;         if (j > i)           for (long long u = 1; u <= rc[j][0]; u++)             if (x = y = z = rc[j][u]) {               c = 1;               while (c < lim && pre[pre[x]] > -1) x = pre[x], c++;               while (pre[x] != z) {                 while (c < lim && suf[suf[y]] > -1) y = suf[y], c++;                 if (c == lim)                   v -= (a[x].y - a[pre[x]].y) * (a[suf[y]].y - a[y].y);                 if (c < lim) break;                 x = suf[x], c--;               }               x = pre[z], y = suf[z], suf[pre[y] = x] = y;             }       }     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long int a[1000005], b[1000005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, i;     cin >> n;     a[1] = 1;     b[1] = 0;     for (i = 2; i <= n; i++) {       if (i % 2 == 0) {         a[i] = a[i - 1];         b[i] = (b[i - 1] + (a[i] + 1));         a[i] %= 1000000007;         b[i] %= 1000000007;       } else {         b[i] = b[i - 1];         a[i] = (a[i - 1] + (b[i] + 1));         a[i] %= 1000000007;         b[i] %= 1000000007;       }     }     long long int ans = b[n] + a[n];     ans %= 1000000007;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300 * 1000 + 10;   long long dist[MAX_N], dist1[MAX_N];   vector<pair<int, int>> adj[MAX_N];   set<pair<long long, int>> s;   bool inPath[MAX_N];   pair<int, int> mx;   int nxt[MAX_N];   bool dfs_path(int u, int par = -1) {     for (auto x : adj[u]) {       int v = x.first;       if (v != par && dfs_path(v, u)) inPath[u] = true, nxt[u] = v;     }     return inPath[u];   }   long long dfs_dist(int u, int par = -1) {     if (inPath[u])       for (auto x : adj[u]) {         int v = x.first, w = x.second;         if (v == nxt[u]) dist1[v] = dist1[u] + w, dist[u] = dfs_dist(v, u) + w;       }     for (auto x : adj[u]) {       int v = x.first, w = x.second;       if (v != par && !inPath[v])         dist1[v] = dist1[u] + w, dist[v] = dist[u] + w, dfs_dist(v, u);     }     return dist[u];   }   bool cmp(pair<int, int> a, pair<int, int> b) {     if (min(a.first, b.first) < 0) return a.first < 0 ? true : false;     return dist1[a.first] + dist[a.second] < dist1[b.first] + dist[b.second];   }   void rem_block(int u, int par = -1) {     s.erase({dist[u], u});     for (auto x : adj[u]) {       int v = x.first;       if (v != par) rem_block(v, u);     }   }   void add_block(int u, int par = -1) {     s.insert({dist[u], u});     for (auto x : adj[u]) {       int v = x.first;       if (v != par) add_block(v, u);     }   }   void dfs(int u, int par = -1) {     if (inPath[u]) {       s.erase({dist[u], u});       for (auto x : adj[u]) {         int v = x.first;         if (v != par && v != nxt[u]) rem_block(v, u), dfs(v, u), add_block(v, u);       }       for (auto x : adj[u]) {         int v = x.first;         if (v != par && v != nxt[u]) rem_block(v, u);       }       for (auto it = s.rbegin(); it != s.rend(); it++)         if (it->second != nxt[u]) {           mx = max(make_pair(u, it->second), mx, cmp);           break;         }       if (nxt[u] != u) dfs(nxt[u], u);     } else if (!s.empty()) {       mx = max(make_pair(u, (*s.rbegin()).second), mx, cmp);       for (auto x : adj[u]) {         int v = x.first;         if (v != par) dfs(v, u);       }     }   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 1; i < n; i++) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       adj[u].push_back({v, w});       adj[v].push_back({u, w});     }     inPath[n - 1] = true, nxt[n - 1] = n - 1, mx = {-1, -1};     dfs_path(0), dfs_dist(0), add_block(0), dfs(0);     for (int i = 0; i < m; i++) {       int x;       cin >> x;       cout << min(dist1[mx.first] + dist[mx.second] + x, dist[0]) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i = -1, k, l;     cin >> k >> l;     while (l % k == 0) {       l /= k;       i++;     }     if (i >= 0 && l == 1)       cout <<  YES  << endl << i << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       int a, b;       cin >> a >> b;       int sum = 0;       int h;       for (int i = 1; i < a; i++) {         sum += i;         if (sum >= b) {           sum -= i;           h = i - 1;           break;         }       }       int s = a - h - 1;       int sb = a - (b - sum) + 1;       for (int i = 1; i <= a; i++) {         if (i == s || i == sb)           cout <<  b ;         else           cout <<  a ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int c1, c2, x, y, l, r, mid;   int main() {     ios::sync_with_stdio(false);     cin >> c1 >> c2 >> x >> y;     l = c1 + c2;     r = 2000000009;     while (l < r) {       mid = (l + r) / 2;       if ((mid - (mid / x) >= c1) && (mid - (mid / y) >= c2) &&           (mid - (mid / (x * y)) >= (c1 + c2)))         r = mid;       else         l = mid + 1;     }     cout << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<long long> h[1000005];   int main() {     int q;     scanf( %d , &q);     while (q--) {       char op, s[20];       long long a;       scanf(  %c , &op);       if (op ==  + ) {         scanf( %lld , &a);         int idx = 0, k = 0;         for (long long x = a; x > 0; x /= 10, k++) {           int d = x % 10;           idx |= (d & 1) << k;         }         h[idx].insert(a);       } else if (op ==  - ) {         scanf( %lld , &a);         int idx = 0, k = 0;         for (long long x = a; x > 0; x /= 10, k++) {           int d = x % 10;           idx |= (d & 1) << k;         }         h[idx].erase(h[idx].find(a));       } else {         scanf( %s , s);         reverse(s, s + strlen(s));         int idx = 0;         for (int k = 0; s[k]; k++) idx |= (s[k] -  0 ) << k;         printf( %d n , (int)h[idx].size());       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, pre = -1;   priority_queue<pair<int, int> > q;   const int M = 3000000 * 4, N = 1e9;   int tree[M], lson[M], rson[M], val[M], size, k, root;   void updata(int &root, int l, int r, int x, int v) {     if (!root) root = ++size;     if (l == r) {       val[root] = tree[root] = v;       return;     }     int mid = (l + r) / 2;     if (x <= mid)       updata(lson[root], l, mid, x, v);     else       updata(rson[root], mid + 1, r, x, v);     tree[root] = max(tree[lson[root]], tree[rson[root]]) + val[root];   }   void add(int &root, int l, int r, int x, int y) {     if (!root || y < l || r < x) return;     if (x <= l && r <= y) {       tree[root]++;       val[root]++;       return;     }     int mid = (l + r) / 2;     add(lson[root], l, mid, x, y);     add(rson[root], mid + 1, r, x, y);     tree[root] = max(tree[lson[root]], tree[rson[root]]) + val[root];   }   int ask(int &root, int l, int r, int x, int y) {     if (!root || y < l || r < x) return 0;     if (x <= l && r <= y) return tree[root];     int mid = (l + r) / 2;     return max(ask(lson[root], l, mid, x, y), ask(rson[root], mid + 1, r, x, y)) +            val[root];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       int l, r;       scanf( %d%d , &l, &r);       l = max(0, l);       q.push(make_pair(-r, -l));       q.push(make_pair(-l, 1));     }     while (!q.empty()) {       int l = -q.top().second, r = -q.top().first;       q.pop();       if (l >= 0)         add(root, 0, N, l, r);       else {         if (r == pre) continue;         int u = ask(root, 0, N, pre, pre), v = ask(root, 0, N, 0, r - k);         if (l == -1 || u < v) {           pre = r;           updata(root, 0, N, r, v);           if (r + root <= N) q.push(make_pair(-r - k, 2));         }       }     }     cout << tree[1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int p;     cin >> p;     for (long long int z = 0; z < p; z++) {       long long int n;       cin >> n;       while (1) {         break;       }       string a;       cin >> a;       long long int re = 0, ro = 0, be = 0, bo = 0;       for (long long int i = 0; i < n; i++) {         if (i % 2 == 0) {           if (a[i] % 2 == 0) {             re++;           } else             ro++;         } else {           if (a[i] % 2 == 0) {             be++;           } else             bo++;         }       }       while (1) {         break;       }       if (n % 2 == 0) {         if (be > 0)           cout <<  2 n ;         else           cout <<  1 n ;         while (1) {           break;         }       } else {         while (1) {           break;         }         if (ro > 0)           cout <<  1 n ;         else           cout <<  2 n ;         while (1) {           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     int l = -1, r = -1;     for (int i = 0; i < n; i++) {       int cnt1 = 0, cnt2 = 0;       if (s[i] ==  a )         ++cnt1;       else         ++cnt2;       for (int j = i + 1; j < n; j++) {         if (s[j] ==  a )           ++cnt1;         else           ++cnt2;         if (cnt1 == cnt2) {           l = i + 1, r = j + 1;           break;         }       }     }     cout << l <<     << r <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tt;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int tam[200005], ans[200005];   map<pair<int, int>, bool> ex;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> N >> M;     for (int m = 0; m < M; m++) {       int u, v;       cin >> u >> v;       tam[u]++;       tam[v]++;       ex[{u, v}] = 1;       ex[{v, u}] = 1;     }     for (int i = 1; i <= N; i++)       if (tam[i] < N - 1) {         cout <<  YES n ;         for (int j = 1; j <= N; j++)           if (i != j && !ex[{i, j}]) {             ans[i] = 1;             ans[j] = 2;             int id = 3;             for (int k = 1; k <= N; k++)               if (!ans[k]) ans[k] = id++;             for (int i = 1; i <= N; i++) cout << ans[i] <<    n [i == N];             for (int i = 1; i <= N; i++)               cout << (ans[i] == 2 ? 1 : ans[i]) <<    n [i == N];             exit(0);           }       }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, d[101], b, f, g, h, j, k, l, n, i;   string s, x;   int main() {     cin >> s >> x;     a = s.size();     b = x.size();     if (s == x) {       cout <<  YES ;       return 0;     }     if (a != b) {       cout <<  NO ;       return 0;     }     for (i = 0; i < a; i++) {       if (s[i] ==  1 ) {         k++;       }       if (x[i] ==  1 ) {         j++;       }     }     if (k > 0 && j > 0)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1505;   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   int n, m;   pair<int, int> start;   char a[MAXN][MAXN];   bool vis[MAXN][MAXN];   pair<int, int> sm[MAXN][MAXN];   bool dfs(int x, int y, pair<int, int> shift) {     if (vis[x][y]) {       return !(sm[x][y] == shift);     }     vis[x][y] = true;     sm[x][y] = shift;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       pair<int, int> nshift = shift;       if (nx >= n) {         nx = 0;         nshift.first++;       }       if (ny >= m) {         ny = 0;         nshift.second++;       }       if (nx < 0) {         nx = n - 1;         nshift.first--;       }       if (ny < 0) {         ny = m - 1;         nshift.second--;       }       if (a[nx][ny] !=  # )         if (dfs(nx, ny, nshift)) return true;     }     return false;   }   int main() {     scanf( %d %d%*c , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %c , &a[i][j]);         if (a[i][j] ==  S ) start.first = i, start.second = j;       }       scanf(  n );     }     if (dfs(start.first, start.second, pair<int, int>(0, 0)))       printf( Yes );     else       printf( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int deg[1001];   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       deg[a]++;       deg[b]++;     }     int ans = 0;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[100100];   vector<long long> v, v2;   int main() {     int n, i;     cin >> n;     long long Answer = 0;     for (i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       v.push_back(a[i].first);       v2.push_back(a[i].second);     }     sort(v.rbegin(), v.rend());     sort(v2.rbegin(), v2.rend());     for (i = 0; i < n; i++) {       Answer += max(v[i], v2[i]) + 1;     }     cout << Answer;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[10005], B[10005];   long long int dp[10005];   int main() {     int n, C;     scanf( %d %d , &n, &C);     for (int i = 0; i < n; i++) scanf( %d , &A[i]);     for (int i = 0; i < n; i++) scanf( %d , &B[i]);     for (int i = n - 1; i >= 0; i--) {       for (int j = n; j >= 0; j--) {         dp[j] += (long long int)j * (long long int)C + B[i];         if (j > 0) dp[j] = min(dp[j], dp[j - 1] + A[i]);       }     }     long long int ret = dp[0];     for (int j = 0; j <= n; j++) ret = min(ret, dp[j]);     printf( %lld n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   char hh[25];   string s;   map<string, int> ma;   int fr[100005];   int ax[100005];   int bx[100005];   int main() {     scanf( %d%d%d , &n, &k, &m);     int i, j, a, b;     for (i = 1; i <= n; i++) {       scanf( %s , hh);       s = hh;       ma[s] = i;     }     for (i = 1; i <= n; i++) scanf( %d , &ax[i]);     for (i = 1; i <= k; i++) {       scanf( %d , &a);       bx[i] = 1e9;       for (j = 1; j <= a; j++) {         scanf( %d , &b);         bx[i] = min(bx[i], ax[b]);         fr[b] = i;       }     }     long long res = 0;     for (i = 1; i <= m; i++) {       scanf( %s , hh);       s = hh;       res += bx[fr[ma[s]]];     }     printf( %lld , res);     return 0;   }
#include <bits/stdc++.h>   long long MOD = 1e9 + 7;   using namespace std;   int main() {     long long n, t;     cin >> n >> t;     long long a[200010], x[200010], b[200010];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       cin >> x[i];       x[i]--;       if ((i > 0 && x[i] < x[i - 1]) || x[i] < i) {         cout <<  No ;         return 0;       }     }     int c[200010] = {};     for (int i = 0; i < n; i++) {       long long temp = x[i];       c[x[i]] = 1;       if (temp == i) {         if (i > 0)           b[i] = max(a[i] + t, b[i - 1] + 1);         else           b[i] = a[i] + t;         if (i < n - 1 && b[i] >= a[i + 1] + t) {           cout <<  No ;           return 0;         }       } else {         if (i > 0)           b[i] = max(a[i + 1] + t, b[i - 1] + 1);         else           b[i] = a[i + 1] + t;       }       if (i < n - 1 && c[i] && b[i] >= a[i + 1] + t) {         cout <<  No ;         return 0;       }     }     cout <<  Yes  << endl;     for (int i = 0; i < n; i++) {       printf( %lld  , b[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int counts[26];   int main() {     string s;     cin >> s;     int N = s.size();     for (int i = 0; i < N; i++) counts[s[i] -  a ]++;     for (int i = 0; i < 26; i++) {       if (counts[i] % 2 == 1) {         int k = -1;         for (int j = 25; j >= 0 && k < 0; j--)           if (counts[j] % 2 == 1) k = j;         if (k != -1) counts[i]++, counts[k]--;       }     }     int pos = 0;     int middle = -1;     for (int i = 0; i < 26; i++) {       if (counts[i] % 2 == 1) {         middle = i;       }       for (int j = 0; j + 1 < counts[i]; j += 2) {         s[pos++] =  a  + i;         s[N - pos] =  a  + i;       }     }     if (middle != -1) s[N / 2] = middle +  a ;     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   void bset(int &b, int i) { b |= (1 << i); }   void bunset(int &b, int i) { b = (b & ~(1 << i)); }   int bget(int b, int i) { return b & (1 << i); }   int bcnt(int b) { return __builtin_popcount(b); }   map<char, int> color2id = {{ R , 0}, { G , 1}, { B , 2}, { Y , 3}, { W , 4}};   int pos(int col, int val) { return 5 * col + val; }   int best;   int cards;   int stepmask[10];   int group[12][25], gn[12];   const int maxN = 100;   int N;   void check(int step, int hints) {     if (best <= hints) return;     for (int g = int(gn[step]) - 1; g >= (0); g--) {       if (bcnt(group[step][g]) > 1) continue;       group[step][g] = group[step][--gn[step]];     }     if (gn[step] == 0) {       best = min(best, hints);       return;     }     if (step >= 10) return;     gn[step + 1] = gn[step];     for (int g = (0); g < (gn[step]); g++) {       group[step + 1][g] = group[step][g];     }     check(step + 1, hints);     gn[step + 1] = gn[step];     for (int g = (0); g < (gn[step]); g++) {       int a = group[step][g] & stepmask[step];       int b = group[step][g] & ~stepmask[step];       if (!a || !b) {         group[step + 1][g] = group[step][g];       } else {         group[step + 1][g] = a;         group[step + 1][gn[step + 1]++] = b;       }     }     check(step + 1, hints + 1);   }   int main() {     ios::sync_with_stdio(false);     for (int c = (0); c < (5); c++) {       for (int v = (0); v < (5); v++) bset(stepmask[c], pos(c, v));       for (int v = (0); v < (5); v++) bset(stepmask[v + 5], pos(c, v));     }     cin >> N;     for (int i = (0); i < (N); i++) {       char c;       int v;       cin >> c >> v;       int a = color2id.at(c), b = v - 1;       bset(cards, pos(a, b));     }     best = 8;     gn[0] = 1;     group[0][0] = cards;     check(0, 0);     cout << best << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &a, T b) {     if (a < b) a = b;   }   const int maxn = 100 + 10;   const int INF = 1e9 + 7;   char a[maxn][maxn];   int c[maxn], d[maxn];   inline void solve(void) {     int n;     cin >> n;     for (int i = (0); i < (n); i++) cin >> a[i];     for (int i = (0); i < (n); i++) cin >> c[i];     vector<int> ans;     for (int i = (0); i < (n); i++) {       if (d[i] != c[i]) continue;       queue<int> v;       v.push(i);       while (!v.empty()) {         int node = v.front();         ans.push_back(node);         v.pop();         for (int j = (0); j < (n); j++) {           if (a[node][j] ==  1 ) {             d[j]++;             if (d[j] == c[j]) v.push(j);           }         }       }     }     cout << ans.size() << endl;     for (int i = (0); i < (ans.size()); i++) cout << ans[i] + 1 <<    ;   }   void init() {     ios::sync_with_stdio(false);     cin.tie(nullptr);   }   int main(int argc, const char *argv[]) {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, xC = 0, XC = 0, i, f = 0;     char c;     char remain;     cin >> n;     string o =   ;     for (i = 0; i < n; i++) {       cin >> c;       if (c ==  x ) {         xC++;         o = o +  x ;         if (xC == n / 2) {           remain =  X ;           i++;           break;         }       } else {         XC++;         o = o +  X ;         if (XC == n / 2) {           remain =  x ;           i++;           break;         }       }     }     while (i < n) {       cin >> c;       if (c != remain) {         f++;       }       o = o + remain;       i++;     }     cout << f << endl;     cout << o;     return 0;   }
#include <bits/stdc++.h>   template <class T>   bool MX(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   bool MN(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   using namespace std;   const long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, a, b, ans = 0, c;     cin >> n >> a >> b;     vector<int> s(n / 2);     for (int i = 0; i < (int)n / 2; ++i) cin >> s[i];     reverse(s.begin(), s.end());     if (n % 2) {       cin >> c;       if (c == 2) ans += min(a, b);     }     for (int i = 0; i < (int)n / 2; ++i) {       cin >> c;       if (s[i] == 0) {         if (c == 2) ans += a;         if (c == 1) {           cout << -1 << endl;           return 0;         }       } else if (s[i] == 1) {         if (c == 2) ans += b;         if (c == 0) {           cout << -1 << endl;           return 0;         }       } else {         if (c == 2) ans += 2 * min(a, b);         if (c == 1) ans += b;         if (c == 0) ans += a;       }     }     cout << ans << endl;     return 0;   }