malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   map<int, string> g;   int n, k, cnt;   char name1[10100][30], name2[10100][30];   int mark[1010][1010];   int x[10100], y[10100], tt[10100];   int ans[10100], num;   struct Node {     int l, r;   } node[10100];   struct Mark {     int l, r;     Mark() {}     Mark(int a, int b) {       if (a > b) swap(a, b);       l = a;       r = b;     }     bool operator<(const Mark a) const {       if (l == a.l) return r < a.r;       return l < a.l;     }   };   map<Mark, int> vis;   int vv;   int main() {     string s1, s2;     int u, v, t;     while (scanf( %d%d , &n, &k) == 2) {       cnt = 0;       num = 0;       vv = 0;       vis.clear();       mp.clear();       for (int i = 0; i < n; i++) {         scanf( %s%s%d , name1[i], name2[i], &t);         s1 = name1[i];         s2 = name2[i];         if (!mp.count(s1)) {           mp[s1] = ++cnt;           g[cnt] = s1;         }         u = mp[s1];         if (!mp.count(s2)) {           mp[s2] = ++cnt;           g[cnt] = s2;         }         v = mp[s2];         x[i] = u;         y[i] = v;         tt[i] = t;         for (int j = 0; j < n; j++) {           if (tt[i] != tt[j] && tt[i] - tt[j] <= k) {             if (x[i] == y[j] && x[j] == y[i]) {               if (!vis.count(Mark(x[i], y[i]))) {                 node[num].l = x[i];                 node[num++].r = y[i];                 vis[Mark(x[i], y[i])] = vv++;               }             }           }         }       }       printf( %d n , num);       for (int i = 0; i < num; i++)         cout << g[node[i].l] <<     << g[node[i].r] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int a[maxn], n, s, b[maxn], num[maxn], len;   int ufs[maxn], meme[maxn];   inline int find(int u) {     if (ufs[u] == u)       return u;     else       return ufs[u] = find(ufs[u]);   }   inline void join(int u, int v, int e) {     u = find(u), v = find(v);     if (u == v) return;     ufs[v] = u;     meme[u] = e;   }   vector<vector<int> > mema;   vector<pair<int, int> > adj[maxn];   vector<int> curm;   inline void dfs(int u) {     while (adj[u].size()) {       int v = adj[u].back().first, id = adj[u].back().second;       adj[u].pop_back();       dfs(v);       curm.push_back(id);     }   }   int main() {     cin >> n >> s;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       num[++len] = a[i];     }     sort(num + 1, num + len + 1);     len = unique(num + 1, num + len + 1) - num - 1;     for (int i = 1; i <= n; i++) {       a[i] = lower_bound(num + 1, num + len + 1, a[i]) - num;       b[i] = a[i];       ufs[i] = i;     }     sort(b + 1, b + n + 1);     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (a[i] != b[i]) {         cnt++;         join(a[i], b[i], i);       }     }     if (cnt > s) {       cout <<  -1  << endl;       return 0;     }     if (cnt == 0) {       cout <<  0  << endl;       return 0;     }     if (s - cnt > 1) {       for (int i = 1; i <= len; i++) {         if (ufs[i] == i && meme[i] != 0) {           curm.push_back(meme[i]);           if (curm.size() == s - cnt) break;         }       }       if (curm.size() > 1) {         mema.push_back(curm);         int lstv = a[curm.back()];         for (int i = curm.size() - 1; i >= 1; i--) {           a[curm[i]] = a[curm[i - 1]];         }         a[curm[0]] = lstv;       }     }     for (int i = 1; i <= n; i++) {       if (a[i] != b[i]) {         adj[a[i]].push_back(make_pair(b[i], i));       }     }     for (int i = 1; i <= len; i++) {       if (adj[i].size() != 0) {         curm.clear();         dfs(i);         mema.push_back(curm);       }     }     cout << mema.size() << endl;     for (int i = 0; i < mema.size(); i++) {       cout << mema[i].size() << endl;       for (int j = 0; j < mema[i].size(); j++) {         printf( %d  , mema[i][j]);       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   struct poke {     double p, q;   } srt[N];   inline bool cmp1(poke a, poke b) {     return a.p > b.p || a.p == b.p && a.q > b.q;   }   inline bool cmp2(poke a, poke b) { return a.p - a.p * a.q > b.p - b.p * b.q; }   double f[N];   int n, a, b;   double ans, sum;   multiset<double> heap;   void calc() {     ans = 0., sort(srt + 1, srt + 1 + n, cmp1);     for (int i = a; i <= n; ++i) {       if (i - a > b) break;       sort(srt + 1, srt + 1 + i, cmp2), heap.clear();       double cur = sum = f[i + 1] = 0.;       for (int j = i; j >= 1; --j) {         heap.insert(srt[j].q - srt[j].p), sum += srt[j].q - srt[j].p;         if ((int)heap.size() > i - a)           sum -= *heap.begin(), heap.erase(heap.begin());         f[j] = sum, cur += srt[j].p;       }       heap.clear();       for (int j = i + 1; j <= n; ++j) {         heap.insert(srt[j].q), cur += srt[j].q;         if ((int)heap.size() > b - (i - a))           cur -= *heap.begin(), heap.erase(heap.begin());       }       for (int j = 0; j <= i; ++j) {         if (j > a) break;         if (j)           heap.insert(srt[j].q - srt[j].p * srt[j].q),               cur += srt[j].q - srt[j].p * srt[j].q;         if ((int)heap.size() > b - (i - a))           cur -= *heap.begin(), heap.erase(heap.begin());         if ((int)heap.size() == b - (i - a)) ans = max(ans, cur + f[j + 1]);       }     }   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 1; i <= n; ++i) scanf( %lf , &srt[i].p);     for (int i = 1; i <= n; ++i) scanf( %lf , &srt[i].q);     calc(), printf( %.6lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       char c;       cin >> c;       string str;       cin >> str;       long long ctr = 0;       long long k = 0;       for (long long i = 0; i < n; i++) {         if (str[i] != c) {           ctr++;           k = i;         }       }       if (ctr == 0) {         cout << 0;       } else if (ctr == 1) {         if (k == n - 1) {           cout << 1 <<   n ;           cout << k;         } else {           cout << 1 <<   n ;           cout << k + 2;         }       } else {         long long flag = 0;         for (long long i = n - 1; i >= n / 2; i--) {           if (str[i] == c) {             flag = i;             break;           }         }         if (flag) {           cout << 1 <<   n ;           cout << flag + 1;         } else {           cout << 2 <<   n ;           cout << n <<     << n - 1;         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105], b[105];   long long tinh(long long x, int n, int nc) {     long long i, cnt = 0;     for ((i) = (1); (i) <= (n); (i)++) {       cnt += (((long long)a[i] * x) / b[i]) + 1;       if (cnt > nc) return 1001001001;     }     return cnt;   }   void input() {     int i, n, nc;     int dau, giua, cuoi;     int l, r;     scanf( %d %d , &n, &nc);     for ((i) = (1); (i) <= (n); (i)++) scanf( %d %d , &a[i], &b[i]);     dau = 1, cuoi = 1001001001;     while (dau <= cuoi) {       giua = (dau + cuoi) >> 1;       long long val = tinh(giua, n, nc);       if (val > nc)         cuoi = giua - 1;       else         dau = giua + 1;     }     r = cuoi;     dau = 1, cuoi = 1001001001;     while (dau <= cuoi) {       giua = (dau + cuoi) >> 1;       long long val = tinh(giua, n, nc);       if (val < nc)         dau = giua + 1;       else         cuoi = giua - 1;     }     l = dau;     if (r < l)       printf( 0 n );     else if (r == 1001001001)       printf( -1 n );     else       printf( %d n , r - l + 1);   }   int main() {     input();     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   using namespace std;   const bool db = false;   int n, m, x, y;   int a[1010][1010], b[1010][1010];   long long s[1010][1010], cs[1010][1010];   vector<pair<int, int> > ans;   char mark[1010][1010];   pair<long long, pair<int, int> > st[1010 * 1010];   int sz = 0;   long long sum(int lx, int ly, int rx, int ry) {     return s[rx][ry] + s[lx - 1][ly - 1] - s[rx][ly - 1] - s[lx - 1][ry];   }   int main() {     scanf( %d%d%d%d , &n, &m, &x, &y);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scanf( %d , &a[i][j]);         s[i][j] = a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];       }     }     for (int i = 1; i <= n; ++i) {       deque<int> dq;       for (int j = 1; j < y; ++j) {         while (!dq.empty() && dq.back() > a[i][j]) dq.pop_back();         dq.push_back(a[i][j]);       }       for (int j = 1; j + y - 1 <= m; ++j) {         if (j != 1) {           if (a[i][j - 1] == dq.front()) dq.pop_front();         }         while (!dq.empty() && dq.back() > a[i][j + y - 1]) dq.pop_back();         dq.push_back(a[i][j + y - 1]);         b[i][j] = dq.front();       }     }     for (int i = 1; i + y - 1 <= m; ++i) {       deque<int> dq;       for (int j = 1; j < x; ++j) {         while (!dq.empty() && dq.back() > b[j][i]) dq.pop_back();         dq.push_back(b[j][i]);       }       for (int j = 1; j + x - 1 <= n; ++j) {         if (j != 1) {           if (b[j - 1][i] == dq.front()) dq.pop_front();         }         while (!dq.empty() && dq.back() > b[j + x - 1][i]) dq.pop_back();         dq.push_back(b[j + x - 1][i]);         cs[j][i] = dq.front();       }     }     long long tot = 1LL << 60;     for (int i = 1; i + x - 1 <= n; ++i) {       for (int j = 1; j + y - 1 <= m; ++j) {         st[sz].first = cs[i][j] =             sum(i, j, i + x - 1, j + y - 1) - 1LL * x * y * cs[i][j];         st[sz].second.first = i;         st[sz++].second.second = j;       }     }     sort(st, st + sz);     ans.reserve(n * m);     for (int it = 0; it < sz; ++it) {       int i = st[it].second.first, j = st[it].second.second;       if (mark[i][j] || mark[i + x - 1][j] || mark[i][j + y - 1] ||           mark[i + x - 1][j + y - 1]) {         continue;       }       ans.emplace_back(make_pair(i, j));       for (int di = 0; di < x; ++di) {         for (int dj = 0; dj < y; ++dj) {           mark[i + di][j + dj] = 1;         }       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); ++i)       printf( %d %d %lld n , ans[i].first, ans[i].second,              cs[ans[i].first][ans[i].second]);     getchar();     getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void _p(T a) {     cout << a <<   n ;   }   template <class T>   void _pa(T a) {     cout << a <<    ;   }   template <class T1, class T2>   void _p(T1 a, T2 b) {     cout << a <<     << b <<   n ;   }   template <class T1, class T2, class T3>   void _p(T1 a, T2 b, T3 c) {     cout << a <<     << b <<     << c <<   n ;   }   template <class T1, class T2, class T3, class T4>   void _p(T1 a, T2 b, T3 c, T4 d) {     cout << a <<     << b <<     << c <<     << d <<     <<   n ;   }   template <class T1, class T2, class T3, class T4, class T5>   void _p(T1 a, T2 b, T3 c, T4 d, T5 e) {     cout << a <<     << b <<     << c <<     << d <<     << e <<     <<   n ;   }   template <class T>   void _pa(T a[], long long n) {     long long i;     for (i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   template <class T>   void _p(vector<T> v) {     for (auto x : v) cout << x <<    ;     cout <<   n ;   }   template <class T>   void _p(list<T> l) {     for (auto x : l) cout << x <<    ;     cout <<   n ;   }   template <class T>   void _p(set<T> s) {     for (auto x : s) cout << x <<    ;     cout <<   n ;   }   template <class T>   void _p(multiset<T> s) {     for (auto x : s) cout << x <<    ;     cout <<   n ;   }   template <class T>   void _p(unordered_set<T> s) {     for (auto x : s) cout << x <<    ;     cout <<   n ;   }   template <class T1, class T2>   void _p(map<T1, T2> m) {     for (auto x : m) cout << x.first <<  ->  << x.second <<   n ;     cout <<   n ;   }   template <class T1, class T2>   void _p(unordered_map<T1, T2> m) {     for (auto x : m) cout << x.first <<  ->  << x.second <<   n ;     cout <<   n ;   }   template <class T1, class T2>   void _p(map<T1, vector<T2>> m) {     for (auto x : m) {       cout << x.first <<  -> ;       _p(x.second);     }     cout <<   n ;   }   template <class T1, class T2>   void _p(unordered_map<T1, vector<T2>> m) {     for (auto x : m) {       cout << x.first <<  -> ;       _p(x.second);     }     cout <<   n ;   }   void solution() {     string a, b;     int i, n, c = 0;     cin >> a >> b;     map<char, int> mp;     n = b.length();     for (i = 0; i < 26; i++) mp[a[i]] = i;     for (i = 1; i < n; i++) c += abs(mp[b[i]] - mp[b[i - 1]]);     _p(c);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tcse;     cin >> tcse;     while (tcse--) solution();   }
#include <bits/stdc++.h>   using namespace std;   bool pd[5005][5005];   char str[5005];   int n;   bool vis[5050];   bool dfs(int u, int lst) {     vis[u] = 1;     for (int i = 1; i <= n; ++i) {       if (!pd[u][i]) continue;       if (lst != -1 && pd[i][lst]) {         printf( %d %d %d n , lst, u, i);         return 1;       }       if (!vis[i] && dfs(i, u)) return 1;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %s , str + 1);       for (int j = 1; j <= n; ++j)         if (str[j] ==  1 ) pd[i][j] = 1;     }     for (int i = 1; i <= n; ++i)       if (!vis[i] && dfs(i, -1)) {         return 0;       }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, n, m, count = 0;     scanf( %d%d , &n, &m);     while (n > 0 && m > 0) {       if (n > m && n >= 2) {         n -= 2;         m--;         count++;       } else if (m > n && m >= 2) {         m -= 2;         n--;         count++;       } else if (n == m && m >= 2) {         m -= 2;         n--;         count++;       } else         break;     }     printf( %d , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m, k;     cin >> n >> m >> k;     long long s = 2 * n * m;     if (s % k != 0) {       cout <<  NO ;       return 0;     }     s /= k;     long long x2, x3, y2, y3;     x2 = n;     if (s % n == 0)       y3 = s / n;     else       y3 = s / n + 1;     long long r = y3 * n - s;     y2 = 1, x3 = r;     cout <<  YES n ;     cout <<  0 0 n ;     cout << x2 <<     << y2 <<   n ;     cout << x3 <<     << y3 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void prepare() {}   void solve() {     string s;     cin >> s;     set<int> ss[26];     for (int i = 0; i < s.size(); ++i) ss[s[i] -  a ].insert(i);     int i = 25;     int cur = -1;     while (i != -1) {       if (ss[i].empty()) {         --i;         continue;       }       while (!ss[i].empty() && *ss[i].begin() < cur) ss[i].erase(ss[i].begin());       if (ss[i].empty()) {         --i;         continue;       }       for (int j = 0; j < ss[i].size(); ++j) printf( %c , i +  a );       cur = *(--ss[i].end());       --i;     }   }   int main() {     prepare();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 200005;   const int N = 900005;   struct node {     int son[27];     int fa;   } a[N];   int sz;   char s[N];   int mat[M];   vector<int> over[N];   inline int new_id() {     ++sz;     over[sz].clear();     for (int i = (1); i <= (26); i++) a[sz].son[i] = -1;     return sz;   }   int np, ans;   void ins(int pos, int x, int y) {     over[pos].push_back(np);     if (x == y) return;     int cur = s[x] -  a  + 1;     if (a[pos].son[cur] == -1) {       a[pos].son[cur] = new_id();       a[a[pos].son[cur]].fa = pos;     }     ins(a[pos].son[cur], ++x, y);     return;   }   int u[M], n;   void dfs(int x, int dep) {     for (int i = (1); i <= (26); i++)       if (a[x].son[i] != -1) dfs(a[x].son[i], dep + 1);     vector<int> g1, g2;     g1.clear();     g2.clear();     for (int i = 0; i < over[x].size(); i++) {       int j = over[x][i];       if (u[j]) continue;       if (j <= n)         g1.push_back(j);       else         g2.push_back(j);     }     for (int i = 0; i < min(g1.size(), g2.size()); i++) {       ans += dep;       u[g1[i]] = u[g2[i]] = 1;       mat[g1[i]] = g2[i] - n;     }   }   int main() {     scanf( %d , &n);     sz = -1;     new_id();     for (int i = (1); i <= (n * 2); i++) {       np = i;       scanf( %s , &s);       int len = strlen(s);       ins(0, 0, len);     }     dfs(0, 0);     printf( %d n , ans);     for (int i = (1); i <= (n); i++) printf( %d %d n , i, mat[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     double s, x, y, z;     cin >> s >> x >> y >> z;     if ((x == y) && (y == z) && (z == 0.0)) {       cout <<  0 0   << s << endl;       return 0;     }     double k = x + y + z, x0 = x * s / k, y0 = y * s / k, z0 = z * s / k;     if (x0 + y0 + z0 >= s) z0 -= (x0 + y0 + z0 - s);     cout << setprecision(14) << x0 <<     << y0 <<     << z0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double xx[10], yy[10];   int main() {     double px, py, vx, vy, a, b, c, d;     cin >> px >> py >> vx >> vy >> a >> b >> c >> d;     double x = vx / sqrt(vx * vx + vy * vy);     double y = vy / sqrt(vx * vx + vy * vy);     xx[1] = b * x + px;     yy[1] = b * y + py;     xx[2] = px - (y * a / 2);     yy[2] = py + (x * a / 2);     xx[3] = px - (y * c / 2);     yy[3] = py + (x * c / 2);     xx[4] = xx[3] - (d * x);     yy[4] = yy[3] - (d * y);     xx[6] = px + (y * c / 2);     yy[6] = py - (x * c / 2);     xx[5] = xx[6] - (x * d);     yy[5] = yy[6] - (d * y);     xx[7] = px + (y * a / 2);     yy[7] = py - (x * a / 2);     cout.precision(20);     for (int i = 1; i <= 7; i++) cout << xx[i] <<     << yy[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int b, l, k = 0, p, m;     cin >> b >> l;     int n[l];     for (int i = 0; i < l; i++) {       n[i] = 0;     }     for (int i = 0; i < b; i++) {       cin >> p;       for (int j = 0; j < p; j++) {         cin >> m;         n[m - 1]++;       }     }     for (int i = 0; i < l; i++) {       if (n[i] == 0) {         k++;       }     }     if (k > 0) {       cout <<  NO ;     } else {       cout <<  YES ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int pwr(long long int base, long long int p, long long int mod) {     long long int ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long int k, a, b;     scanf( %lld , &k);     scanf( %lld , &a);     scanf( %lld , &b);     long long int ans = (a / k) + (b / k);     if ((a < k && b % k != 0) || (b < k && a % k != 0)) {       printf( -1 n );       return 0;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 22;   int d, p, q;   int c[N][N], s[5555];   int a[N][N], b[N][N], f[N];   int fpow(int x, int y = p - 2) {     if (!y) return 1;     long long z = fpow(x, y >> 1);     z = z * z % p;     if (y & 1) z = z * x % p;     return z;   }   int w;   void pr(int x, int y, int z = 0) {     if (z)       printf( + %d %d %d n , x, y, z);     else       printf( ^ %d %d n , x, y);   }   void mul(int r, int x) {     int t = 100, i;     if (x % 2 == 0) x += p;     pr(r, r, t);     x--;     for (i = 2; x; i = i + i) {       if (x & i) pr(r, t, r), x -= i;       pr(t, t, t);     }   }   void go(int r) {     int t = 10, i;     mul(9, 0);     for (i = t; i <= t + d; i = i + 1) {       pr(8, 9, i);       mul(i, i - t);       pr(i, r, i);       pr(i, i);       mul(i, b[q][i - t]);     }     pr(9, 9, r);     for (i = t; i <= t + d; i = i + 1) pr(r, i, r);   }   int main() {     int i, j, k, e, x;     cin >> d >> p;     for (i = 0; i < N; i = i + 1) {       c[i][0] = 1;       for (j = 1; j <= i; j = j + 1)         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % p;     }     for (i = 0; i <= d; i = i + 1) {       for (j = 0; j <= d; j = j + 1)         a[i][j] = (long long)fpow(i, d - j) * c[d][j] % p;       b[i][i] = 1;     }     for (i = 0; i <= d; i = i + 1) {       for (j = 0; j <= d; j = j + 1)         if (!f[j] && a[j][i]) break;       e = j;       f[e] = 1;       if (i == 2) q = j;       x = fpow(a[j][i]);       for (k = 0; k <= d; k = k + 1) {         a[e][k] = (long long)a[e][k] * x % p;         b[e][k] = (long long)b[e][k] * x % p;       }       for (j = 0; j <= d; j = j + 1) {         if (j == e || !a[j][i]) continue;         x = a[j][i];         for (k = i; k <= d; k = k + 1)           a[j][k] = (a[j][k] - (long long)a[e][k] * x % p + p) % p;         for (k = 0; k <= d; k = k + 1)           b[j][k] = (b[j][k] - (long long)b[e][k] * x % p + p) % p;       }     }     pr(1, 2, 3);     go(1);     go(2);     go(3);     mul(1, p - 1);     mul(2, p - 1);     pr(1, 2, 1);     pr(1, 3, 1);     mul(1, fpow(2));     printf( f 1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1ll << 18;   long long a, b, top, now;   queue<long long> q;   map<long long, int> mp;   long long rev(long long x) {     long long y = 0;     while (x != 0) {       y = (y << 1) | (x & 1);       x >>= 1;     }     return y;   }   void push(long long &x) {     if (x > b && rev(x) > b) return;     if (mp.find(x) == mp.end()) {       q.push(x);       mp[x] = 1;     }   }   string solve() {     if (a == b) return  YES ;     q.push(a);     mp[a] = 1;     while (!q.empty()) {       top = q.front();       q.pop();       now = rev(top << 1);       if (now == b) return  YES ;       push(now);       now = rev((top << 1) | 1);       if (now == b) return  YES ;       push(now);     }     return  NO ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> a >> b;     cout << solve() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& v) {     os <<  (  << v.first <<     << v.second <<  ) ;     return os;   }   template <typename T, typename U = typename T::value_type,             typename = typename enable_if<!is_same<T, string>::value>::type>   ostream& operator<<(ostream& os, const T& v) {     os <<  [ ;     for (const auto& it : v) os << it <<    ;     if (!v.empty()) os <<   b ;     os <<  ] ;     return os;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int n, x;     cin >> n;     int cnt[6] = {0, 0, 0, 0, 0, 0};     for (int i = 0; i < (n); i++) {       cin >> x;       if (x == 4) {         cnt[0]++;         continue;       }       if (x == 8 && cnt[0]) {         cnt[0]--;         cnt[1]++;         continue;       }       if (x == 15 && cnt[1]) {         cnt[1]--;         cnt[2]++;         continue;       }       if (x == 16 && cnt[2]) {         cnt[2]--;         cnt[3]++;         continue;       }       if (x == 23 && cnt[3]) {         cnt[3]--;         cnt[4]++;         continue;       }       if (x == 42 && cnt[4]) {         cnt[4]--;         cnt[5]++;         continue;       }     }     cout << n - 6 * cnt[5] << endl;     return 0;   }