malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int INF = 10000000000;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m;     cin >> n >> m;     long long int chestOdd = 0, chestEven = 0;     long long int i;     for (i = 0; i < n; i++) {       long long int temp;       cin >> temp;       if (temp % 2 == 0) {         chestEven++;       } else {         chestOdd++;       }     }     long long int keyOdd = 0, keyEven = 0;     for (i = 0; i < m; i++) {       long long int temp;       cin >> temp;       if (temp % 2 == 0) {         keyEven++;       } else {         keyOdd++;       }     }     long long int ans = 0;     ans = min(keyEven, chestOdd);     ans += min(keyOdd, chestEven);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   const int mod = 998244353;   int n;   long long jc[N], inv[N], ans = 0, an = 0;   long long poww(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) {         ans = ans * x % mod;       }       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long C(long long n, long long m) {     return jc[n] * inv[m] % mod * inv[n - m] % mod;   }   int main() {     scanf( %d , &n);     jc[0] = inv[0] = 1;     for (int i = 1; i <= n; i++) {       jc[i] = jc[i - 1] * i % mod;       inv[i] = poww(jc[i], mod - 2);     }     for (int i = 1; i <= n; i++) {       ans = (ans +              poww(3, 1ll * n * (n - i) + i) * C(n, i) % mod * ((i & 1) ? 1 : -1) +              mod) %             mod;     }     ans = ans * 2 % mod;     for (int i = 0; i < n; i++) {       long long t = -poww(3, i);       an = (an +             C(n, i) * ((i & 1) ? 1 : -1) * (poww(t + 1, n) - poww(t, n) + mod) %                 mod +             mod) %            mod;     }     ans = (ans + 3 * an) % mod;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int p, q;     cin >> p >> q;     string s;     int **b = new int *[p];     for (long long int i = 0; i < p; i++) b[i] = new int[q];     for (long long int i = 0; i < p; i++) {       cin >> s;       for (long long int j = 0; j < q; j++) {         b[i][j] = int(s[j]);       }     }     for (long long int j = 0; j < q; j++) {       int c = b[0][j];       for (long long int i = 0; i < p; i++) {         if (b[i][j] > c) {           c = b[i][j];         }       }       for (long long int i = 0; i < p; i++) {         if (b[i][j] == c) {           b[i][j] = 0;         }       }     }     int e = 0;     for (long long int i = 0; i < p; i++) {       for (long long int j = 0; j < q; j++) {         if (b[i][j] == 0) {           e += 1;           break;         }       }     }     cout << e <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pole {     int a, b;     long long odp;     int nr;   };   bool porownanie1(pole a, pole b) {     if (a.b < b.b) return true;     if (a.b > b.b) return false;     if (a.nr < b.nr) return true;     return false;   }   bool porownanie2(pole a, pole b) {     if (a.nr < b.nr) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> w(n);     for (int i = 0; i < n; ++i) cin >> w[i];     int p;     cin >> p;     vector<pole> a(p);     for (int i = 0; i < p; ++i) {       cin >> a[i].a >> a[i].b;       --a[i].a;       a[i].odp = 0;       a[i].nr = i;     }     sort(a.begin(), a.end(), porownanie1);     for (int le = 0; le < p;) {       int pr = le;       while (pr < p && a[pr].b == a[le].b) ++pr;       --pr;       if (a[le].b <= 540) {         vector<long long> s(n, 0);         for (int i = n - 1; i >= 0; --i) {           s[i] = w[i];           if (i + a[le].b < n) s[i] += s[i + a[le].b];         }         for (int i = le; i <= pr; ++i) a[i].odp = s[a[i].a];       } else {         for (int i = le; i <= pr; ++i)           for (int j = a[i].a; j < n; j += a[i].b) a[i].odp += w[j];       }       le = pr + 1;     }     sort(a.begin(), a.end(), porownanie2);     for (int i = 0; i < p; ++i) cout << a[i].odp << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   bool check(long long l, long long r) {     for (long long i = l; i < (r + l) / 2; i++) {       if (s[i] != s[r - i - 1]) {         return false;       }     }     return true;   }   long long sulganlox(long long l, long long r) {     if (r - l == 1) {       if (s[l] == s[l + 1]) {         cout <<  Impossible  << endl;         exit(0);       }       return 2;     }     if ((r - l) % 2 == 0) {       if (check(l, (r + l) / 2)) {         return sulganlox(l, (r + l) / 2);       } else {         return 1;       }     } else {       if (check(l, (r + l) / 2)) {         return sulganlox(l, (r + l) / 2);       } else {         return 2;       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     long long n = s.size();     if (n == 1) {       cout <<  Impossible  << endl;       return 0;     }     cout << sulganlox(0, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 19391;   long long a[maxn];   namespace FAST_IO {   template <typename T>   void read(T &a) {     a = 0;     long long f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) {         f = -1;       }       c = getchar();     }     while (isdigit(c)) {       a *= 10;       a += c -  0 ;       c = getchar();     }     a = a * f;   }   template <typename T>   void write(T a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a > 9) {       write(a / 10);     }     putchar(a % 10 +  0 );   }   template <typename T>   void writeln(T) {     write(a);     puts(  );   }   }  // namespace FAST_IO   long long ans, ans1;   priority_queue<long long> big;   priority_queue<long long, vector<long long>, greater<long long> > small;   signed main() {     long long n;     FAST_IO::read(n);     for (long long i = 1; i <= n; i++) {       FAST_IO::read(a[i]);       a[i] -= i;     }     for (long long i = 1; i <= n; i++) {       big.push(a[i]);       if (a[i] < big.top()) {         ans += big.top() - a[i];         big.pop();         big.push(a[i]);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int nmax = 1e5 + 42;   int n;   long long k;   int arr[nmax];   void compress() {     set<int> seen = {};     for (int i = 1; i <= n; i++) seen.insert(arr[i]);     map<int, int> c = {};     int val = 0;     for (auto k : seen) {       val++;       c[k] = val;     }     for (int i = 1; i <= n; i++) arr[i] = c[arr[i]];   }   int fenwick[nmax][2];   int sum(int pos, int index) {     int ret = 0;     while (pos) {       ret = ret + fenwick[pos][index];       pos = pos - (pos & (-pos));     }     return ret;   }   int query(int l, int r, int index) { return sum(r, index) - sum(l - 1, index); }   void update(int pos, int add, int index) {     while (pos <= n) {       fenwick[pos][index] += add;       pos = pos + (pos & (-pos));     }   }   int main() {     scanf( %i%lld , &n, &k);     for (int i = 1; i <= n; i++) scanf( %i , &arr[i]);     compress();     int r = n + 1;     long long now = 0;     while (r > 1 && now <= k) {       r--;       now = now + query(1, arr[r] - 1, 1);       if (now > k) {         now = now - query(1, arr[r] - 1, 1);         r++;         break;       }       update(arr[r], 1, 1);     }     long long ans = 0;     for (int l = 1; l < n; l++) {       now = now + query(arr[l] + 1, n, 0) + query(1, arr[l] - 1, 1);       update(arr[l], 1, 0);       while (l >= r || (now > k && r <= n)) {         now = now - query(arr[r] + 1, n, 0) - query(1, arr[r] - 1, 1);         update(arr[r], -1, 1);         r++;       }       ans = ans + (n - r + 1);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   std::vector<int> ch[1005];   bool dfs(const int &u) {     if (!ch[u].size()) return true;     int res = 0;     if (ch[u].size()) {       for (auto it = ch[u].begin(); it != ch[u].end(); it++) {         if (!(ch[*it].size())) res++;       }     }     if (res >= 3)       return true;     else       return false;   }   int main() {     cin >> n;     for (int i = 2; i <= n; i++) {       int u;       cin >> u;       ch[u].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!dfs(i)) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   typedef long long ll;   typedef long double ld;   using namespace std;   vector<ll> prime_factors(ll num) {     vector<ll> ans;     while (num % 2) {       ans.push_back(2);       num /= 2;     }     for (int i = 3; i * i <= num; i += 2) {       while (num % i == 0) {         ans.push_back(i);         num /= i;       }     }     if (num > 2) ans.push_back(num);     return ans;   }   void tests() {     int n;     cin >> n;     map<int, vector<int>> data;     vector<pair<int, int>> ans;     ans.reserve(n);     for (int i = 1; i < n + 1; i++) {       int x;       cin >> x;       data[x].push_back(i);     }     for (auto &i : data) {       int len = i.second.size();       if (len == 1)         ans.push_back(make_pair(i.first, 0));       else if (len == 2)         ans.push_back(make_pair(i.first, i.second[1] - i.second[0]));       else {         int cd = i.second[1] - i.second[0];         for (int pos = 2; pos < len; ++pos) {           if (i.second[pos] - i.second[pos - 1] != cd) goto end;         }         ans.push_back(make_pair(i.first, cd));       }     end:;     }     cout << ans.size() << char(10);     for (auto &i : ans) cout << i.first << char(32) << i.second << char(10);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       tests();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100010];   int b[100010];   int cha[100010];   vector<int> lis;   int inc[100010];   int decr[100010];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       cha[x]++;       cha[y + 1]--;     }     for (int i = 1; i <= m; i++) {       a[i] = a[i - 1] + cha[i];     }     lis.push_back(-100);     lis.push_back(a[1]);     inc[1] = 1;     for (int i = 2; i <= m; i++) {       int temp = upper_bound(lis.begin(), lis.end(), a[i]) - lis.begin();       if (temp == lis.size()) lis.push_back(a[i]);       inc[i] = temp;       lis[temp] = a[i];     }     for (int i = m; i >= 1; i--) b[m + 1 - i] = a[i];     for (int i = m; i >= 1; i--) a[i] = b[i];     lis.clear();     lis.push_back(-100);     lis.push_back(a[1]);     decr[1] = 1;     for (int i = 2; i <= m; i++) {       int temp = upper_bound(lis.begin(), lis.end(), a[i]) - lis.begin();       if (temp == lis.size()) lis.push_back(a[i]);       decr[i] = temp;       lis[temp] = a[i];     }     for (int i = 1; i <= m; i++) inc[i] += decr[m + 1 - i];     cout << *max_element(inc + 1, inc + m + 1) - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     pair<char, bool> ar[100][100];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> ar[i][j].first;         ar[i][j].second = false;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < m; k++) {           if (k == j) continue;           if (ar[i][j].first == ar[i][k].first) {             ar[i][j].second = true;             ar[i][k].second = true;           }         }         for (int k = 0; k < n; k++) {           if (k == i) continue;           if (ar[i][j].first == ar[k][j].first) {             ar[i][j].second = true;             ar[k][j].second = true;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ar[i][j].second == false) cout << ar[i][j].first;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 100007;   const int maxM = 300007;   const long long INF = (1LL << 60);   const long long M = 1000000007;   long long C[maxN];   vector<int> G[maxN];   vector<int> H[maxN];   int V[maxN];   stack<int> S;   vector<int> SSS[maxN];   void DFSG(int x) {     V[x] = 1;     for (int g : G[x])       if (V[g] == 0) DFSG(g);     S.push(x);   }   void DFSH(int x, int y) {     V[x] = 2;     SSS[y].push_back(x);     for (int h : H[x])       if (V[h] == 1) DFSH(h, y);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, a, b, k;     long long ans = 0, cmb = 1, tans, tcmb;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> C[i];     }     cin >> m;     for (int i = 1; i <= m; ++i) {       cin >> a >> b;       G[a].push_back(b);       H[b].push_back(a);     }     for (int i = 1; i <= n; ++i) {       if (V[i] == 0) DFSG(i);     }     k = 0;     while (!S.empty()) {       a = S.top();       S.pop();       if (V[a] == 1) {         ++k;         DFSH(a, k);       }     }     for (int i = 1; i <= k; ++i) {       tans = INF;       tcmb = 1;       for (int s : SSS[i]) {         if (C[s] < tans) {           tans = C[s];           tcmb = 1;         } else if (C[s] == tans) {           ++tcmb;         }       }       ans += tans;       cmb *= tcmb;       cmb %= M;     }     cout << ans <<     << cmb <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N], b[N];   int main() {     int n, ans = 0, x;     cin >> n >> x;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     sort(a + 1, a + 1 + n);     sort(b + 1, b + 1 + n);     for (int i = 1, j = n; i <= n && j >= 1; i++) {       if (a[i] + b[j] >= x) ans++, j--;     }     cout <<  1   << ans;   }
#include <bits/stdc++.h>   using namespace std;   void check(vector<vector<long long> >& a, vector<vector<long long> >& b) {     long long n = a.size(), m = a[0].size();     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++)         if (a[i][j] > b[i][j]) swap(a[i][j], b[i][j]);   }   bool correct(vector<vector<long long> > a) {     long long n = a.size(), m = a[0].size();     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if ((i + 1 < n && a[i][j] >= a[i + 1][j]) ||             (j + 1 < m && a[i][j] >= a[i][j + 1]) ||             (i - 1 >= 0 && a[i][j] <= a[i - 1][j]) ||             (j - 1 >= 0 && a[i][j] <= a[i][j - 1]))           return false;       }     }     return true;   }   int32_t main() {     long long n, m;     cin >> n >> m;     vector<vector<long long> > a(n, vector<long long>(m, 0)),         b(n, vector<long long>(m, 0));     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> a[i][j];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> b[i][j];     check(a, b);     if (correct(a) && correct(b))       cout <<  Possible n ;     else       cout <<  Impossible n ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long n, m, a, b, c, k, temp, x, y;   const int MAXN = 100000 + 11;   inline long long max(long long a, long long b) { return ((a > b) ? a : b); }   inline long long min(long long a, long long b) { return ((a > b) ? b : a); }   inline long long gcd(long long a, long long b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   inline vector<long long> read(int n) {     vector<long long> v(n);     for (int i = 0; i < v.size(); i++) cin >> v[i];     return v;   }   vector<int> tree[200000];   void bfst() {     for (int i = n - 1; i > 0; --i)       merge(tree[i << 1].begin(), tree[i << 1].end(), tree[i << 1 | 1].begin(),             tree[i << 1 | 1].end(), back_inserter(tree[i]));   }   long long qfstgreater(int l, int r, int val) {     long long res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1)         res += tree[l].end() - upper_bound(tree[l].begin(), tree[l].end(), val),             l++;       if (r & 1)         res += tree[r - 1].end() -                upper_bound(tree[r - 1].begin(), tree[r - 1].end(), val),             r--;     }     return res;   }   long long qfstlesser(int l, int r, int val) {     long long res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1)         res += lower_bound(tree[l].begin(), tree[l].end(), val) - tree[l].begin(),             l++;       if (r & 1)         res += lower_bound(tree[r - 1].begin(), tree[r - 1].end(), val) -                tree[r - 1].begin(),             r--;     }     return res;   }   void solveforthiscase(const int& test) {     cin >> n >> k;     vector<long long> v = read(n);     for (int i = 0; i < n; i++) tree[i + n].push_back(v[i]);     bfst();     long long inv = 0, ans = 0, r = n - 1;     for (; r > 0; r--) {       long long ti = 0;       if (v[r] < v[0]) ti++;       ti += qfstlesser(r + 1, n, v[r]);       if (inv + ti > k) break;       inv += ti;     }     r++;     if (r == 1) {       cout << (n * (n - 1)) / 2;       return;     }     ans += (n - r);     for (int l = 1; l < n; l++) {       inv += qfstgreater(0, l, v[l]) + qfstlesser(r, n, v[l]);       while (r < n && inv > k) {         inv -= qfstlesser(r + 1, n, v[r]);         inv -= qfstgreater(0, l + 1, v[r++]);       }       if (r == n) break;       ans += n - r;     }     cout << ans;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     clock_t start, end;     start = clock();     int test = 1;     for (int i = 1; i <= test; i++) solveforthiscase(i);     end = clock();     long double t_t = (long double)(end - start) / (long double)(CLOCKS_PER_SEC);     if (false) cerr << (long double)t_t * 1000 <<   ms  ;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 200010;   inline void solve() {     int x = read();     for (int i = 2; i <= 30; i++)       if (x % ((1 << i) - 1) == 0) {         printf( %d n , x / ((1 << i) - 1));         return;       }   }   int main() {     for (int Cas = read(); Cas; Cas--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> sz[1001];   vector<int> s[1001];   vector<int> l;   bool v[1001];   int dist[1001][1001];   vector<pair<int, pair<int, int> > > t;   void bfs(int a, int f) {     for (int i = 0; i < sz[a].size(); i++) {       int x = sz[a][i];       if (dist[x][f] == 0) {         dist[x][f] = dist[a][f] + 1;         bfs(x, f);       }     }   }   void solve(int a, int b, int y) {     if (y == 0) {       return;     }     if (sz[a].size() == 1) {       swap(a, b);     }     if (sz[a].size() == 1) {       t.push_back({a, {b, y}});       return;     }     int esz, msz, besz = 0, bmsz = 0;     for (int i = 0; i < sz[a].size(); i++) {       int x = sz[a][i];       if (x != b) {         esz = x;         swap(esz, msz);       }     }     int c, d, e, f;     if (sz[b].size() == 1) {       e = b;       f = b;     } else {       for (int i = 0; i < sz[b].size(); i++) {         int x = sz[b][i];         if (x != a) {           besz = x;           swap(besz, bmsz);         }       }     }     for (int i = 0; i < l.size(); i++) {       int x = l[i];       if (dist[a][x] < dist[b][x]) {         if (dist[esz][x] < dist[msz][x]) {           c = x;         } else {           d = x;         }       } else {         if (besz != 0) {           if (dist[besz][x] < dist[bmsz][x]) {             e = x;           } else {             f = x;           }         } else {           e = x;           swap(e, f);         }       }     }     y /= 2;     t.push_back({c, {e, y}});     t.push_back({d, {f, y}});     t.push_back({c, {d, -y}});     if (e != f) {       t.push_back({e, {f, -y}});     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       sz[a].push_back(b);       sz[b].push_back(a);       s[a].push_back(c);       s[b].push_back(c);     }     for (int i = 1; i <= n; i++) {       if (sz[i].size() == 2) {         cout <<  NO ;         return 0;       }       if (sz[i].size() == 1) {         l.push_back(i);       }     }     for (int i = 1; i <= n; i++) {       dist[i][i] = 1;       bfs(i, i);     }     cout <<  YES           <<   n ;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < sz[i].size(); j++) {         int x = sz[i][j];         int y = s[i][j];         if (i < x) {           solve(i, x, y);         }       }     }     cout << t.size() <<   n ;     for (int i = 0; i < t.size(); i++) {       cout << t[i].first <<     << t[i].second.first <<     << t[i].second.second            <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[44], b[44], PP[44], PPP[44], PHI[44];   long long dp[1 << 22], DP[1 << 22];   pair<int, int> P[44];   void is_ok() {     dp[0] = 0;     DP[0] = 0;     int st = 0;     for (int i = 0; i < n; ++i) {       int dr = st + (1 << i);       while (st < dr) {         ++st;         dp[st] = dp[st - (1 << i)] + a[i + 1];         DP[st] = DP[st - (1 << i)] + b[i + 1];         if (dp[st] == DP[st] && st != (1 << n) - 1) return;       }     }     for (int i = 1; i <= n; ++i) cout << b[i] <<    ;     exit(0);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       P[i] = make_pair(a[i], i);     }     sort(P + 1, P + n + 1);     P[n + 1] = P[1];     for (int i = 2; i <= n + 1; ++i) PHI[P[i].second] = PP[P[i].second] = i - 1;     for (int t = 1; t <= n; ++t) {       for (int i = 1; i <= n; ++i) b[i] = P[PP[i]].first;       is_ok();       for (int i = 1; i <= n; ++i) PPP[i] = PP[PHI[i]];       for (int i = 1; i <= n; ++i) PP[i] = PPP[i];     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n, q;   string s;   int dp[251][251][251];   int nxt[26][112345];   int len[3];   int chs[3][250];   template <class T, class U>   inline void smax(T &a, U b) {     a = a > b ? a : b;   }   template <class T, class U>   inline void smin(T &a, U b) {     a = a < b ? a : b;   }   int main() {     std::ios::sync_with_stdio(false), std::cin.tie(0);     cin >> n >> q;     cin >> s;     for (int i = 0; i < 26; i++) {       nxt[i][n] = nxt[i][n + 1] = n;       for (int j = n - 1; j >= 0; j--)         if (s[j] ==  a  + i)           nxt[i][j] = j;         else           nxt[i][j] = nxt[i][j + 1];     }     dp[0][0][0] = -1;     for (int t = 0; t < q; t++) {       char c;       int group;       cin >> c >> group;       group -= 1;       if (c ==  + ) {         char ch;         cin >> ch;         chs[group][len[group]] = ch -  a ;         len[group]++;         int i[3];         for (i[0] = group == 0 ? len[0] : 0; i[0] <= len[0]; i[0]++)           for (i[1] = group == 1 ? len[1] : 0; i[1] <= len[1]; i[1]++)             for (i[2] = group == 2 ? len[2] : 0; i[2] <= len[2]; i[2]++) {               if (!i[0] && !i[1] && !i[2]) continue;               dp[i[0]][i[1]][i[2]] = n;               for (int k = 0; k < 3; k++) {                 if (i[k] > 0) {                   smin(dp[i[0]][i[1]][i[2]],                        nxt[chs[k][i[k] - 1]]                           [dp[i[0] - (0 == k)][i[1] - (1 == k)][i[2] - (2 == k)] +                            1]);                 }               }             }       } else {         len[group]--;       }       cout << ((dp[len[0]][len[1]][len[2]] < n) ?  Yes  :  No ) <<   n ;     }     cout << flush;     return 0;   }