malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[200010];   struct seg {     int val, idx;   } tree1[600010], tree2[600010];   void build(int node, int s, int e) {     if (s > e) return;     if (s == e) {       tree1[node].val = a[s];       tree1[node].idx = s;       tree2[node].val = a[s];       tree2[node].idx = s;       return;     }     int mid = (s + e) / 2;     build(2 * node, s, mid);     build(2 * node + 1, mid + 1, e);     if (tree1[2 * node].val > tree1[2 * node + 1].val)       tree1[node].idx = tree1[2 * node + 1].idx;     else       tree1[node].idx = tree1[2 * node].idx;     if (tree2[2 * node].val > tree2[2 * node + 1].val)       tree2[node].idx = tree2[2 * node].idx;     else       tree2[node].idx = tree2[2 * node + 1].idx;     tree1[node].val = min(tree1[2 * node].val, tree1[2 * node + 1].val);     tree2[node].val = max(tree2[2 * node].val, tree2[2 * node + 1].val);   }   seg query1(int node, int s, int end, int l, int r) {     if (s > end || s > r || end < l) {       seg temp;       temp.val = 1000000000;       temp.idx = -1;       return temp;     }     if (s >= l && end <= r) return tree1[node];     seg res1 = query1(2 * node, s, (s + end) / 2, l, r);     seg res2 = query1(2 * node + 1, (s + end) / 2 + 1, end, l, r);     seg res;     if (res1.val < res2.val) {       res.val = res1.val;       res.idx = res1.idx;     } else {       res.val = res2.val;       res.idx = res2.idx;     }     return res;   }   seg query2(int node, int s, int end, int l, int r) {     if (s > end || s > r || end < l) {       seg temp;       temp.val = -1000000000;       temp.idx = -1;       return temp;     }     if (s >= l && end <= r) return tree2[node];     seg res1 = query2(2 * node, s, (s + end) / 2, l, r);     seg res2 = query2(2 * node + 1, (s + end) / 2 + 1, end, l, r);     seg res;     if (res1.val > res2.val) {       res.val = res1.val;       res.idx = res1.idx;     } else {       res.val = res2.val;       res.idx = res2.idx;     }     return res;   }   int main() {     int n;     cin >> n;     int q;     cin >> q;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     build(1, 0, n - 1);     while (q--) {       int l, r, x;       scanf( %d %d %d , &l, &r, &x);       l--;       r--;       seg mx = query1(1, 0, n - 1, l, r);       seg mi = query2(1, 0, n - 1, l, r);       if (mx.val == x && mi.val == x) {         printf( -1 n );       } else if (mx.val == x) {         printf( %d n , mi.idx + 1);       } else         printf( %d n , mx.idx + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 10;   const int inf = 1e9 + 10;   const int N = 1e6 + 10;   vector<int> t[N * 4];   void build(int v, int tl, int tr, vector<int> &a) {     if (tl == tr) {       t[v].push_back(a[tl]);     } else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm, a);       build(v * 2 + 1, tm + 1, tr, a);       t[v] = t[v * 2];       for (auto i : t[v * 2 + 1]) {         t[v].push_back(i);       }       sort(t[v].begin(), t[v].end());     }   }   int get(int v, int tl, int tr, int l, int r, int x) {     if (l > r) {       return 0;     }     if (tl == l && tr == r) {       int ind = lower_bound(t[v].begin(), t[v].end(), x) - t[v].begin();       if (ind != t[v].size() && t[v][ind] == x) {         return 1;       } else {         return 0;       }     }     int tm = (tl + tr) / 2;     int ql = get(v * 2, tl, tm, l, min(r, tm), x);     int qr = get(v * 2 + 1, tm + 1, r, max(l, tm + 1), r, x);     return (ql + qr);   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<int> a(k), last(n + 1, k);     for (int i = 0; i < k; i++) {       cin >> a[i];       if (last[a[i]] == k) {         last[a[i]] = i;       }     }     build(1, 0, k - 1, a);     int ans = 0;     for (int i = 1; i <= n; i++) {       if (last[i] == k) {         ans++;       }       if (i > 1 && get(1, 0, k - 1, last[i], k - 1, i - 1) == 0) {         ans++;       }       if (i < n && get(1, 0, k - 1, last[i], k - 1, i + 1) == 0) {         ans++;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool As;   char c;   int n, m, k;   inline void read(int& a) {     a = 0;     do c = getchar();     while (c <  0  || c >  9 );     while (c <=  9  && c >=  0 ) a = (a << 3) + (a << 1) + c -  0 , c = getchar();   }   int Min[1211];   double A[11][11];   bool Has[11][11];   const double eps = 1e-7;   int Matrix(int n) {     int o = 1;     double res = 1;     if (n < 0) return 0;     for (int i = 0; i < n; i++) {       int j = -1;       for (int t = i; t < n; t++)         if (((A[t][i]) > 0 ? (A[t][i]) : -(A[t][i])) > eps) {           j = t;           break;         }       if (j ^ i) o ^= 1;       if (j == -1) return 0;       for (int t = 0; t < n; t++) swap(A[j][t], A[i][t]);       for (int j = i + 1; j < n; j++)         if (((A[j][i]) > 0 ? (A[j][i]) : -(A[j][i])) > eps) {           double U = A[j][i] / A[i][i];           for (int k = 0; k < n; k++) A[j][k] -= U * A[i][k];         }       res *= A[i][i];     }     if (o)       return res + 0.1;     else       return -res + 0.1;   }   int Build(int S) {     vector<int> Q;     Q.clear();     memset(A, 0, sizeof(A));     while (S) Q.push_back(Min[S]), S ^= 1 << Min[S];     for (int i = 0; i < Q.size(); i++)       for (int j = 0; j < i; j++)         if (Has[Q[i]][Q[j]]) A[i][j]--, A[j][i]--, A[j][j]++, A[i][i]++;     return Q.size() - 1;   }   int Cnt[2002];   int Pow(int a, int x) {     int res = 1;     for (x; x; x >>= 1, a = a * a)       if (x & 1) res = res * a;     return res;   }   int F[2002];   int G[2002];   int main() {     Min[0] = -1;     for (int i = 1; i < 1024; i++)       Cnt[i] = (i & 1) ? Cnt[i >> 1] + 1 : Cnt[i >> 1],       Min[i] = (i & 1) ? 0 : (Min[i >> 1] + 1);     read(n), read(m), read(k);     while (m--) {       int a, b;       read(a), read(b);       a--, b--;       Has[b][a] = Has[a][b] = true;     }     int t = 1 << n;     t--;     for (int i = 1; i <= t; i++) {       int W = 1;       for (int j = 0; j < n; j++)         if ((1 << j) & i) {           int f = 0;           for (int k = 0; k < n; k++)             if (!(i & (1 << k)))               if (Has[j][k]) f++;           W *= f;         }       int df;       G[i] = F[i] = W * (df = Matrix(Build(t ^ i)));     }     int Ans = 0;     for (int i = t; ~i; i--) {       if (Cnt[i] == k) Ans += G[i];       int j = (i - 1) & i;       while (j) {         G[j] += (Cnt[j ^ i] & 1 ? -1 : 1) * F[i];         j = i & (j - 1);       }     }     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans;   float x, dis, t;   struct ponto {     float ini, fim;     bool operator<(const ponto &lhs) const { return lhs.ini > ini; }   } p[1010];   int main() {     scanf( %d%f , &n, &t);     ans = 2;     for (int i = 0; i < n; i++) {       scanf( %f%f , &x, &dis);       dis /= 2.0;       p[i].ini = x - dis;       p[i].fim = x + dis;     }     sort(p, p + n);     for (int i = 1; i < n; i++) {       if (p[i - 1].fim + t < p[i].ini)         ans += 2;       else if (p[i - 1].fim + t == p[i].ini)         ans++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long long int inverse(long long int i) {     if (i == 1) return 1;     return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s;     cin >> s;     long long x = 0, y = 0, ans = 0, len = 0, last;     for (int i = 0; i < n; i++) {       cin >> s;       if (s[i] ==  U )         y++;       else if (s[i] ==  D )         y--;       else if (s[i] ==  R )         x++;       else         x--;       len++;       if (len > (abs(x) + abs(y))) {         x = 0;         y = 0;         len = 0;         ans++;         i--;         last = i;       }     }     if (last != (n - 1)) ans++;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   bool has(int s, int x) {     int i = s / 50 % 475;     for (int ii = (0); ii < int(25); ++ii) {       i = (i * 96 + 42) % 475;       if (i + 26 == x) {         return true;       }     }     return false;   }   void solve(istream& cin, ostream& cout) {     int p, x, y;     cin >> p >> x >> y;     for (int i = 0; x - i * 50 >= y; i++) {       if (has(x - i * 50, p)) {         cout << 0;         return;       }     }     for (int i = 1;; i++) {       if (has(x + i * 100, p) || has(x + i * 100 - 50, p)) {         cout << i;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve(cin, cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct vec {     int to;     int fro;   };   int fa[200010], son[200010][26], mx[200010];   int rt, lst, tot;   int n, m;   char s[200010];   vec mp[200010];   int tai[200010], cnt;   int P[200010];   int ans[200010];   vector<int> qs[200010];   int av[200010];   int len[200010];   int Rt[200010], Son[4000010][2];   int TOT;   inline void be(int x, int y) {     mp[++cnt].to = y;     mp[cnt].fro = tai[x];     tai[x] = cnt;   }   int merge(int x, int y) {     if (!x || !y) {       return x + y;     }     Son[x][0] = merge(Son[x][0], Son[y][0]);     Son[x][1] = merge(Son[x][1], Son[y][1]);     return x;   }   void change(int &x, int y, int z, int p) {     if (!x) {       x = ++TOT;     }     if (y == z) {       return;     }     int mid = y + z >> 1;     if (p <= mid) {       change(Son[x][0], y, mid, p);     } else {       change(Son[x][1], mid + 1, z, p);     }   }   void ins(int x) {     int np = ++tot, p = lst;     mx[np] = mx[p] + 1;     while (p && !son[p][x]) {       son[p][x] = np;       p = fa[p];     }     if (!p) {       fa[np] = rt;     } else {       int q = son[p][x];       if (mx[q] == mx[p] + 1) {         fa[np] = q;       } else {         int nq = ++tot;         mx[nq] = mx[p] + 1;         memcpy(son[nq], son[q], sizeof(son[q]));         fa[nq] = fa[q];         fa[np] = fa[q] = nq;         while (p && son[p][x] == q) {           son[p][x] = nq;           p = fa[p];         }       }     }     lst = np;   }   int L;   int t[200010];   void DFS(int x, int y, int z) {     if (y == z) {       t[++L] = y;       return;     }     int mid = y + z >> 1;     if (Son[x][0]) {       DFS(Son[x][0], y, mid);     }     if (Son[x][1]) {       DFS(Son[x][1], mid + 1, z);     }   }   void dfs(int x) {     int i, y;     for (i = tai[x]; i; i = mp[i].fro) {       y = mp[i].to;       dfs(y);     }     for (i = tai[x]; i; i = mp[i].fro) {       y = mp[i].to;       Rt[x] = merge(Rt[x], Rt[y]);     }     L = 0;     if (qs[x].size()) {       L = 0;       DFS(Rt[x], 1, n);       for (i = 0; i < qs[x].size(); i++) {         int wzh = 1;         int ti = qs[x][i];         int tav = av[qs[x][i]];         if (L < tav) {           ans[ti] = -1;         } else {           ans[ti] = 1000000000;           for (int j = tav; j <= L; j++) {             ans[ti] = min(ans[ti], t[j] - t[j - tav + 1] + len[ti]);           }         }       }     }   }   int main() {     int i, x;     lst = rt = tot = 1;     scanf( %s , s + 1);     n = strlen(s + 1);     int p = rt;     for (i = 1; i <= n; i++) {       ins(s[i] -  a );       p = son[p][s[i] -  a ];       P[i] = p;       change(Rt[p], 1, n, i);     }     for (i = 2; i <= tot; i++) {       be(fa[i], i);     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d%s , &av[i], s + 1);       int p = rt;       for (int j = 1; s[j]; j++) {         p = son[p][s[j] -  a ];       }       len[i] = strlen(s + 1);       if (!p) {         ans[i] = -1;       } else {         qs[p].push_back(i);       }     }     dfs(1);     for (i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool iguales(vector<string>& x, vector<string>& y) {     for (int i = (int)0; i < (int)x.size(); i++) {       if (x[i] ==  T  || y[i] ==  T ) continue;       if (!(x[i] == y[i])) return false;     }     return true;   }   int main() {     map<string, vector<vector<string> > > mapa;     map<string, string> peso;     int n, m, k;     scanf( %d n , &n);     string linea, nom, alfa, beta;     while (n--) {       getline(cin, linea);       for (int i = (int)0; i < (int)linea.size(); i++)         if (linea[i] ==  (  || linea[i] ==  )  || linea[i] ==  , ) linea[i] =    ;       vector<string> x;       stringstream flujo(linea);       while (flujo >> linea) x.push_back(linea);       nom = x[1];       x.erase(x.begin());       x.erase(x.begin());       mapa[nom].push_back(x);     }     cin >> m;     while (m--) {       cin >> alfa >> beta;       peso[beta] = alfa;     }     scanf( %d n , &k);     while (k--) {       getline(cin, linea);       for (int i = (int)0; i < (int)linea.size(); i++)         if (linea[i] ==  (  || linea[i] ==  )  || linea[i] ==  , ) linea[i] =    ;       vector<string> x;       stringstream flujo(linea);       int cc = 0;       while (flujo >> linea) {         if (cc == 0) {           nom = linea;           cc = 1;         } else           x.push_back(peso[linea]);       }       map<string, vector<vector<string> > >::iterator iter;       iter = mapa.find(nom);       if (iter != mapa.end()) {         vector<vector<string> > r = iter->second;         int tot = 0;         for (int i = (int)0; i < (int)r.size(); i++) {           vector<string> second = r[i];           if (x.size() == second.size()) {             if (iguales(x, second)) tot++;           }         }         cout << tot << endl;       } else         cout << 0 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n, k;   int a[200];   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     int e = 0, s = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 1)         e++;       else         s++;     }     int ee = e, ss = s;     int ans = -1;     for (int b = 1; b <= k; b++) {       ee = e;       ss = s;       for (int i = 0; b + i * k <= n; i++) {         int c = b + i * k;         if (a[c] == 1)           ee--;         else           ss--;       }       ans = max(ans, abs(ee - ss));     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, c;     cin >> n >> k >> c;     int p = ((n * k * c) / 100);     int k1 = p / k;     int k2 = p % k;     for (int i = 0; i < n; i++) {       if (i != 0) cout <<    ;       if (i < k1)         cout << k;       else if (i == k1)         cout << k2;       else         cout << 0;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, i, j, a[100005], b[100005];   int main() {     j = 2;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) b[i] = b[i - 1] + a[i];     for (i = n; i >= 1; i--)       if (b[i + 1] + a[i] < b[i]) {         j = i;         b[i] = b[i + 1] + a[i];       } else         break;     cout << j - 1 <<     << n - j + 1;   }
#include <bits/stdc++.h>   const int mo = 1000000007,             x[9][9] = {{0, 0, 0, 0, 1, 1, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 1, 1},                        {0, 0, 0, 0, 1, 1, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 1, 1},                        {1, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 1, 0, 0, 0, 0, 1},                        {0, 1, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 1, 0, 0, 0, 0, 1},                        {0, 0, 0, 0, 0, 0, 0, 0, 1}};   int a[9], t[9], b[9][9], c[9][9], l, r, ans;   void mul(int a[][9], int b[][9], int c[][9]) {     int i, j, k;     for (i = 0; i <= 8; ++i)       for (j = 0; j <= 8; ++j) {         c[i][j] = 0;         for (k = 0; k <= 8; ++k)           c[i][j] = (c[i][j] + (long long)a[i][k] * b[k][j]) % mo;       }   }   int calc(int n) {     if (!n) return 0;     int i, j, v;     for (i = 0; i <= 8; ++i) a[i] = 1;     a[8] = 4;     memcpy(b, x, sizeof x);     --n;     while (n) {       if (n % 2) {         for (i = 0; i <= 8; ++i) {           t[i] = 0;           for (j = 0; j <= 8; ++j) t[i] = (t[i] + (long long)a[j] * b[j][i]) % mo;         }         memcpy(a, t, sizeof t);       }       mul(b, b, c);       memcpy(b, c, sizeof c);       memcpy(c, t, sizeof t);       n /= 2;     }     return a[8];   }   int query(int n) { return (calc(n) + calc((n + 1) / 2)) % mo; }   int main() {     scanf( %d%d , &l, &r);     ans = ((long long)(query(r) - query(l - 1)) * ((mo + 1) / 2) % mo + mo) % mo;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   bool compare(int c, int d) { return a[c - 1] < a[d - 1]; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = i + 1;     }     sort(b, b + n, compare);     cout << (n + 1) / 2 << endl;     for (int i = 0; i < n; i += 2) cout << b[i] <<    ;     cout << endl << n / 2 << endl;     for (int i = 1; i < n; i += 2) cout << b[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e9 + 7;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return (a / gcd(a, b)) * b;   }   long long int sq(long long int x) { return x * x; }   void solve() {     long long int n, x1, x2, y1, y2;     cin >> n >> x1 >> y1 >> x2 >> y2;     long long int ans = 8e18;     vector<pair<long long int, long long int>> v(n);     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       v[i].first = sq(x - x1) + sq(y - y1);       v[i].second = sq(x - x2) + sq(y - y2);     }     v.push_back({0, 0});     for (auto i : v) {       long long int r1 = i.first;       long long int r2 = 0;       for (auto j : v) {         if (j.first > r1) {           r2 = max(r2, j.second);         }       }       ans = min(ans, r1 + r2);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int x1, x2, a, b;   int main() {     while (cin >> x1 >> x2 >> a >> b) {       bool ch = false;       if (x1 > x2) {         swap(x1, x2);         swap(a, b);         a = -a;         b = -b;         ch = true;       }       int dif = abs(x1 - x2);       if (a <= 0) {         if (dif <= b)           cout <<  FIRST  << endl << (ch ? x1 : x2) << endl;         else           cout <<  DRAW  << endl;       } else {         int rem = dif % (a + b);         if (rem == 0)           cout <<  SECOND  << endl;         else if (rem >= a && rem <= b)           cout <<  FIRST  << endl << (ch ? x2 - rem : x1 + rem) << endl;         else           cout <<  DRAW  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> pmax, maxp;     vector<int> g[n + 2];     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       if (pmax.find(a) == pmax.end())         pmax[a] = b;       else         pmax[a] = max(pmax[a], b);     }     for (auto i = pmax.begin(); i != pmax.end(); i++) {       maxp[i->second] = i->first;     }     int q;     cin >> q;     while (q--) {       int k;       cin >> k;       vector<pair<int, int> > maxpaux;       for (int i = 0; i < k; i++) {         int l;         cin >> l;         if (pmax.find(l) == pmax.end()) continue;         maxpaux.push_back(pair<int, int>(pmax[l], l));         maxp.erase(pmax[l]);       }       if (maxp.empty()) {         cout << 0 <<     << 0 <<   n ;       } else if (maxp.size() == 1) {         cout << maxp.begin()->second <<     << g[maxp.begin()->second][0] <<   n ;       } else {         auto en = maxp.end();         en--;         int personmax = en->second;         cout << personmax <<    ;         en--;         int secondperson = en->second;         int pos = upper_bound(g[personmax].begin(), g[personmax].end(),                               pmax[secondperson]) -                   g[personmax].begin();         int answer = g[personmax][pos];         cout << answer <<   n ;       }       for (int i = 0; i < maxpaux.size(); i++) {         maxp[maxpaux[i].first] = maxpaux[i].second;       }     }     return 0;   }
#include <bits/stdc++.h>   int gcd(int x, int y) {     int r1 = x, q, r2 = y, r;     while (r2 > 0) {       q = r1 / r2;       r = r1 - q * r2;       r1 = r2;       r2 = r;     }     return r1;   }   using namespace std;   int main(int argc, char const *argv[]) {     int n, m, x, cnt;     char c;     cin >> n >> m;     char arr[n];     int arr1[n];     map<int, pair<int, int> > arr2;     cnt = 0;     cin >> arr;     arr1[0] = -1;     for (int i = 1; i < n; i++) {       arr1[i] = -1;       if (arr[i] ==  .  && arr[i - 1] ==  . ) {         arr2[cnt] = make_pair(i, i - 1);         arr1[i] = cnt;         cnt++;       }     }     for (int i = 0; i < m; i++) {       cin >> x >> c;       x--;       if (arr[x] ==  .  && c ==  .  || arr[x] !=  .  && c !=  . )         ;       else if (arr[x] !=  .  && c ==  . ) {         if (x != 0 && arr[x - 1] ==  . ) {           arr2[cnt] = make_pair(x, x - 1);           arr1[x] = cnt;           cnt++;         }         if (x != n - 1 && arr[x + 1] ==  . ) {           arr2[cnt] = make_pair(x + 1, x);           arr1[x + 1] = cnt;           cnt++;         }       } else {         if (x == n - 1) {           if (arr1[x] == -1)             ;           else {             arr2.erase(arr2.find(arr1[x]));             arr1[x] = -1;           }         } else {           if (arr1[x] != -1 && arr1[x + 1] != -1) {             arr2.erase(arr2.find(arr1[x + 1]));             arr1[x + 1] = -1;             arr2.erase(arr2.find(arr1[x]));             arr1[x] = -1;           } else if (arr1[x] != -1) {             arr2.erase(arr2.find(arr1[x]));             arr1[x] = -1;           } else if (arr1[x + 1] != -1) {             arr2.erase(arr2.find(arr1[x + 1]));             arr1[x + 1] = -1;           } else {           }         }       }       arr[x] = c;       printf( %d , arr2.size());       printf(  n );       ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   int ans, cnt, tmp;   int main() {     int n;     cin >> n;     int a[] = {0, 0, 0, 0, 0};     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a[x]++;       cnt += x;     }     if (cnt == 5 || cnt < 3) return cout << -1, 0;     ans += min(a[1], a[2]);     a[1] -= ans, a[2] -= ans, a[3] += ans;     if (a[1] != 0) {       ans += a[1] / 3 * 2;       a[3] += a[1] / 3;       a[1] = a[1] % 3;       if (a[1] == 1) {         if (a[3] != 0)           ans += 1;         else           ans += 2;       } else if (a[1] == 2) {         ans += 2;       }       return cout << ans, 0;     } else if (a[2] != 0) {       ans += a[2] / 3 * 2;       a[3] += a[2] / 3 * 2;       a[2] = a[2] % 3;       if (a[2] == 1) {         if (a[4] != 0)           ans++;         else           ans += 2;       } else if (a[2] == 2) {         ans += 2;       }       return cout << ans, 0;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     const int N = 26;     int mas[26];     for (int i = 0; i < N; ++i) mas[i] = 0;     int rez = 0;     for (int i = 0; i < n * 2 - 2; ++i) {       char a;       cin >> a;       if (isupper(a)) {         if (mas[tolower(a) -  a ] > 0)           mas[tolower(a) -  a ]--;         else           rez++;       } else         mas[a -  a ]++;     }     cout << rez << endl;     return 0;   }