malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class S, class T>   ostream& operator<<(ostream& st, pair<S, T> p) {     st <<  (  << p.first <<  ,  << p.second <<  ) ;     return st;   }   template <class T>   ostream& operator<<(ostream& st, vector<T> v) {     st <<  [ ;     for (size_t i = 0; i < v.size(); ++i) {       if (i != 0) {         st <<  ,  ;       }       st << v[i];     }     st <<  ] ;     return st;   }   pair<int, int> get_parent_dsu(int v, vector<pair<int, int> >& parents) {     if (parents[v].first != v) {       pair<int, int> p = get_parent_dsu(parents[v].first, parents);       parents[v] = make_pair(p.first, p.second ^ parents[v].second);     }     return parents[v];   }   void union_dsu(int a, int b, int value, vector<int>& mass,                  vector<pair<int, int> >& parents) {     pair<int, int> a_parent = get_parent_dsu(a, parents);     pair<int, int> b_parent = get_parent_dsu(b, parents);     a = a_parent.first;     int a_dist = a_parent.second;     b = b_parent.first;     int b_dist = b_parent.second;     if (a != b) {       if (mass[a] > mass[b]) {         swap(a, b);         swap(a_dist, b_dist);       }       parents[a].first = b;       parents[a].second = value ^ a_dist ^ b_dist;       mass[b] += mass[a];     }   }   int perform_get_query(int a, int b, vector<pair<int, int> >& parents) {     pair<int, int> a_parent = get_parent_dsu(a, parents);     pair<int, int> b_parent = get_parent_dsu(b, parents);     int result;     if (a_parent.first == b_parent.first) {       result = a_parent.second ^ b_parent.second;     } else {       result = -1;     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(time(0));     int q;     cin >> q;     int mapper_size = 0;     map<int, int> mapper;     vector<int> mass;     vector<pair<int, int> > parents_dsu;     int last = 0;     for (int i = 0; i < q; ++i) {       int t;       cin >> t;       int l, r, value;       cin >> l >> r;       l = l ^ last;       r = r ^ last;       if (l > r) {         swap(l, r);       }       --l;       if (mapper.count(l) == 0) {         mass.push_back(1);         parents_dsu.push_back(make_pair(mapper_size, 0));         mapper[l] = mapper_size++;       }       if (mapper.count(r) == 0) {         mass.push_back(1);         parents_dsu.push_back(make_pair(mapper_size, 0));         mapper[r] = mapper_size++;       }       int a = mapper[l];       int b = mapper[r];       if (t == 1) {         cin >> value;         value = last ^ value;         union_dsu(a, b, value, mass, parents_dsu);       } else {         last = perform_get_query(a, b, parents_dsu);         cout << last << endl;         if (last == -1) {           last = 1;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e5 + 7;   const int Inf = 1 << 30;   const long long INF = 1ll << 60;   int n;   int a[maxx];   vector<int> vec;   int pos[maxx];   map<int, int> mp;   int ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int cnt = 0;     int t = 0;     bool flg = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 1) {         if (!flg) pos[++t] = i;         flg = 1;         cnt++;       } else {         if (cnt) vec.push_back(cnt);         cnt = 0;         flg = 0;       }       if (i == n && a[i] == 1) vec.push_back(cnt);     }     for (int i = 0; i < vec.size(); i++) mp[pos[i + 1]] = vec[i];     int pp = pos[1] - 1;     int minx = min(pp, mp[pos[1]]);     ans = max(ans, 2 * minx);     for (int i = 1; i <= t; i++) {       int tmp;       if (i == 1)         tmp = minx;       else         tmp = pos[i] - (pos[i - 1] + mp[pos[i - 1]]);       int min1 = min(tmp, mp[pos[i]]);       int min2 = min(tmp, mp[pos[i - 1]]);       int minT = max(min1, min2);       ans = max(ans, 2 * minT);     }     int dd = n - (pos[t] + mp[pos[t]] - 1);     int min0 = min(dd, mp[pos[t]]);     ans = max(ans, 2 * min0);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 10;   int fac[MAXN], infac[MAXN];   long long pow_mod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return res;   }   int add(int a, int b) { return (a + b) % MOD; }   int mul(int a, int b) { return 1LL * a * b % MOD; }   int C(int a, int b) { return mul(fac[a], mul(infac[b], infac[a - b])); }   int A(int a, int b) { return mul(fac[a], infac[a - b]); }   int F(int a, int b) {     if (a == b) return 1;     return mul(b, pow_mod(a, a - b - 1));   }   int main() {     int n, m, a, b;     fac[0] = 1;     for (int i = 1; i <= 1000000; i++) {       fac[i] = mul(i, fac[i - 1]);     }     infac[1000000] = pow_mod(fac[1000000], MOD - 2);     for (int i = 1000000; i >= 1; i--) {       infac[i - 1] = mul(infac[i], i);     }     scanf( %d%d%d%d , &n, &m, &a, &b);     int ans = 0;     for (int i = 1; i <= n - 1; i++) {       if (i > m) {         continue;       }       ans = add(ans, mul(mul(pow_mod(m, n - 1 - i), F(n, i + 1)),                          mul(A(n - 2, i - 1), C(m - 1, i - 1))));     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[5000 + 10];   int main() {     int n;     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> a[i];     bool flag = false;     for (int i = 1; i < n; i++) {       if (a[a[a[i]]] == i) {         flag = true;         break;       }     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100004;   unsigned long long a, b, c = 0, x = 0, y = 0;   bool f = 1;   void solve() {     int c = 0;     for (int i = 0; i < 64; i++) {       if (b >> i & 1) y |= 1ll << i;     }     a -= y;     for (int i = 1; i < 64; i++) {       int r = a >> i & 1, s = b >> (i - 1) & 1;       if (r == 1) {         if (s == 0) {           x |= 1ll << (i - 1);           y |= 1ll << (i - 1);         } else {           f = 0;           break;         }       }     }   }   int main() {     cin >> a >> b;     solve();     if (!f)       puts( -1 );     else       printf( %llu %llu , x, y);   }
#include <bits/stdc++.h>   using namespace std;   long long nsd(long long a, long long b) {     while (b != 0) {       a = a % b;       swap(a, b);     }     return a;   }   long long nsk(long long a, long long b) { return a / nsd(a, b) * b; }   bool cmp(long long a, long long b) { return a > b; }   void sorts(string& str) { sort(str.begin(), str.end()); }   long long sumd(long long n) {     if (n < 0) {       n = -n;     }     long long s = 0;     while (n != 0) {       n /= 10;       s++;     }     return s;   }   int suma(long long n) {     int s = 0;     while (n != 0) {       s += n % 10;       n /= 10;     }     return s;   }   long long fact(long long n) {     if (n == 1)       return 1;     else       return n * fact(n - 1);   }   int factnum(int n) {     int c = 0;     for (int i = 5; n / i >= 1; i *= 5) c += n / i;     return c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     cout << abs(count(s.begin(), s.end(),  1 ) - count(s.begin(), s.end(),  0 ));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, n;     cin >> n;     long long int arr[n];     vector<long long int> vec[100010];     for (i = 0; i < n; i++) {       cin >> arr[i];       vec[arr[i]].push_back(i);     }     long long int y = 0, d;     for (i = 0; i < 100010; i++) {       long long int x = 0;       if (vec[i].size() >= 2) {         d = vec[i][1] - vec[i][0];         for (j = 1; j < vec[i].size(); j++) {           if (d == (vec[i][j] - vec[i][j - 1])) {             ++x;           }         }         if ((x + 1) == vec[i].size()) {           ++y;         }       } else if (vec[i].size() == 1) {         ++y;       } else {         continue;       }     }     cout << y << endl;     vector<long long int> vec1[100010];     long long int z = 0;     for (i = 0; i < 100010; i++) {       long long int x = 0;       d = 0;       if (vec[i].size() >= 2) {         d = vec[i][1] - vec[i][0];         for (j = 1; j < vec[i].size(); j++) {           if (d == (vec[i][j] - vec[i][j - 1])) {             ++x;           }         }         if ((x + 1) == vec[i].size()) {           cout << i <<     << d << endl;         }       } else if (vec[i].size() == 1) {         cout << i <<     << d << endl;       } else {         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1005];   int main() {     int n, f = 1;     char *p, *q;     scanf( %s , s);     n = strlen(s);     p = s;     q = s + n - 1;     while (p <= q) {       if (*p == *q) {         p++;         q--;       } else {         f = 0;         break;       }     }     printf( %s , s);     if (!f) {       for (int i = n - 1; i >= 0; i--) printf( %c , s[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(vector<T> &a, long long n) {     T x;     a.clear();     for (long long i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }   }   template <class T>   void write(vector<T> &a) {     for (T x : a) cout << x <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     int T;     cin >> T;     while (T--) {       int n, m;       vector<int> a, b;       cin >> n >> n >> m;       read(a, n);       read(b, m);       sort(a.begin(), a.end());       sort(b.begin(), b.end());       if (a.back() > b.back())         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     long long a[n], sum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % 2 == 1 || n == 1) {       cout <<  NO ;     } else {       sum /= 2;       long long temp1 = 0, temp2;       map<long long, bool> m1, m2;       bool flag = false;       for (int i = 0, j = n - 1; i < n, j >= 0; i++, j--) {         temp1 += a[i];         temp2 += a[j];         if (temp1 == sum || temp2 == sum) {           flag = true;           break;         }         if (temp1 > sum) {           if (m1[temp1 - sum] == 1) {             flag = true;             break;           }         }         if (temp2 > sum) {           if (m2[temp2 - sum] == 1) {             flag = true;             break;           }         }         m1[a[i]] = 1;         m2[a[j]] = 1;       }       if (flag == true) {         cout <<  YES ;       } else {         cout <<  NO ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   using ll = int64_t;   using Pii = pair<int, int>;   using ull = uint64_t;   using Vi = vector<int>;   void run();   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     run();     return 0;   }   int uplg(int n) { return 32 - __builtin_clz(n); }   int uplg(ll n) { return 64 - __builtin_clzll(n); }   int cmp(double a, double b, double eps = 1e-9) {     return (a > b + eps) - (a + eps < b);   }   constexpr ll MOD = 998244353;   struct Zp {     ll first;     Zp(ll a = 0) {       if (a < 0)         a = a % MOD + MOD;       else if (a >= MOD * 2)         a %= MOD;       else if (a >= MOD)         a -= MOD;       first = a;     }     Zp operator+(Zp r) const { return first + r.first; }     Zp operator-(Zp r) const { return first - r.first + MOD; }     Zp operator*(Zp r) const { return first * r.first; }     Zp operator/(Zp r) const { return first * r.inv().first; }     Zp operator-() const { return MOD - first; }     Zp inv() const { return pow(MOD - 2); }     Zp pow(ll e) const {       Zp t = 1, m = *this;       while (e) {         if (e & 1) t = t * m;         e >>= 1;         m = m * m;       }       return t;     }     Zp& operator+=(Zp r) { return *this = *this + r; }     Zp& operator-=(Zp r) { return *this = *this - r; }     Zp& operator*=(Zp r) { return *this = *this * r; }     Zp& operator/=(Zp r) { return *this = *this / r; }     void print() { cerr << first; }   };   struct Vert {     Vi E;     Zp f, g;   };   vector<Vert> G;   void dfs(int v, int par) {     Zp p = 1, sum = 0;     for (auto& e : (G[v].E))       if (e != par) {         dfs(e, v);         p *= Zp(1) - G[e].g / 2;         sum += G[e].f;       }     G[v].f = sum + 1 - p;     G[v].g = p;   }   void run() {     int n;     cin >> n;     G.resize(n);     for (int i = (1); i < (n); i++) {       int a, b;       cin >> a >> b;       G[a - 1].E.push_back(b - 1);       G[b - 1].E.push_back(a - 1);     }     dfs(0, -1);     cout << (G[0].f * Zp(2).pow(n)).first << endl;   }
#include <bits/stdc++.h>   using namespace std;   ifstream input;   ofstream output;   int main(int argc, char *argv[]) {     input.sync_with_stdio(false);     output.sync_with_stdio(false);     int n, tmp, tmp2;     priority_queue<int> y;     set<int> used;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       y.push(tmp);       used.insert(tmp);     }     while (1) {       tmp = y.top();       tmp2 = tmp;       y.pop();       while (tmp > 1) {         if (used.find(tmp / 2) == used.end()) {           used.insert(tmp / 2);           used.erase(tmp2);           y.push(tmp / 2);           break;         }         tmp /= 2;       }       if (tmp == 1) {         y.push(tmp2);         break;       }     }     while (y.size()) {       cout << y.top() <<    ;       y.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = INT_MAX;   const int MAX = 4e6 + 5;   const int N = 1e5 + 5;   long long dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};   long long dy[] = {0, 1, 0, -1, -1, 1, 1, -1};   char dir[] = { U ,  R ,  D ,  L };   long long power(long long a, long long b);   long long powmod(long long a, long long b, long long mod);   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long a[n];       set<long long> s;       for (long long i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       if (s.size() > k)         cout << -1 <<   n ;       else if (n == k) {         cout << k <<   n ;         for (long long i = 0; i < n; i++) cout << a[i] <<    ;         cout <<   n ;       } else {         vector<long long> tmp, res;         for (auto x : s) tmp.push_back(x);         long long m = tmp.size();         if (m < k) {           for (long long i = 0; i < k - m; i++) {             tmp.push_back(tmp[m - 1]);           }         }         m = tmp.size();         long long i = 0, j = 0;         while (i < n && j % m < m) {           if (a[i] == tmp[j % m]) {             res.push_back(a[i]);             i += 1;             j += 1;           } else {             res.push_back(tmp[j % m]);             j += 1;           }         }         cout << res.size() <<   n ;         for (auto x : res) cout << x <<    ;         cout <<   n ;       }     }   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2) res *= a;       b /= 2, a *= a;     }     return res;   }   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b % 2) res *= (a % mod);       b /= 2, a *= (a % mod);     }     return res % mod;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() {}     Point(double _x, double _y) : x(_x), y(_y) {}   };   struct Point p0, p1, p2;   double dist(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   double check(Point s, Point e, Point m, double t) {     if (dist(s, m) + dist(m, e) <= t + dist(s, e))       return dist(s, e) + t - dist(m, e);     double l = 0.0, r = 1.0, mid;     for (int i = 0; i <= 1000; i++) {       mid = (l + r) / 2;       Point p = Point{s.x + mid * (m.x - s.x), s.y + mid * (m.y - s.y)};       if (dist(s, p) + dist(p, e) <= t + dist(s, e))         l = mid;       else         r = mid;     }     return mid * dist(s, m);   }   int main() {     double t1, t2, x, y;     scanf( %lf%lf , &t1, &t2);     scanf( %lf%lf , &x, &y);     p0 = {x, y};     scanf( %lf%lf , &x, &y);     p1 = {x, y};     scanf( %lf%lf , &x, &y);     p2 = {x, y};     double ans = 0.0;     ans = max(ans, min(check(p0, p1, p1, t2), check(p0, p2, p1, t1)));     ans = max(ans, min(check(p0, p1, p2, t2), check(p0, p2, p2, t1)));     if (dist(p0, p2) + dist(p2, p1) <= t2 + dist(p0, p1)) {       ans = max(ans, min(dist(p0, p1) + t2, dist(p0, p2) + dist(p2, p1) + t1));     }     double low = 0.0, high = 1.0, mid, midd;     for (int i = 1; i <= 1000; i++) {       mid = low + (high - low) / 3;       midd = high - (high - low) / 3;       Point a = Point(p1.x + (p2.x - p1.x) * mid, p1.y + (p2.y - p1.y) * mid);       Point b = Point(p1.x + (p2.x - p1.x) * midd, p1.y + (p2.y - p1.y) * midd);       double r1 = min(check(p0, p1, a, t2), check(p0, p2, a, t1));       double r2 = min(check(p0, p1, b, t2), check(p0, p2, b, t1));       if (r1 > r2)         high = midd, ans = max(ans, r1);       else         low = mid, ans = max(ans, r2);     }     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (2 * c < d || 2 * d < c || d >= b)       cout <<  -1 ;     else {       cout << 2 * a << endl << 2 * b << endl;       if (c > d)         cout << c;       else         cout << d;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct _ {     _() { ios_base::sync_with_stdio(0); }   } _;   template <class A, class B>   ostream &operator<<(ostream &o, pair<A, B> t) {     o <<  (  << t.first <<  ,   << t.second <<  ) ;     return o;   }   template <class T>   string tostring(T first, int len = 0, char c =  0 ) {     stringstream ss;     ss << first;     string r = ss.str();     if (r.length() < len) r = string(len - r.length(), c) + r;     return r;   }   template <class T>   void PV(T a, T b, int n = 0, int w = 0, string s =    ) {     int c = 0;     while (a != b) {       cout << tostring(*a++, w,    );       if (a != b && (n == 0 || ++c % n))         cout << s;       else         cout << endl;     }   }   template <class T>   inline bool chmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   inline bool chmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   }   const long long linf = 0x3f3f3f3f3f3f3f3fLL;   const int inf = 0x3f3f3f3f;   const int mod = int(1e9) + 7;   const int N = 111111;   vector<int> prime;   bool isp[N];   vector<int> oddPrime;   void generatePrime(int n = 1000000) {     memset(isp, 1, sizeof(isp));     ;     isp[0] = isp[1] = 0;     for (int i = 2; i <= n; i++) {       if (!isp[i]) continue;       prime.push_back(i);       for (int j = i + i; j <= n; j += i) {         isp[j] = 0;       }     }   }   int cnt[10000];   long long cc;   inline int isPrime(int *a, int n) {     int r = 0;     for (int i = 0; i < n; i++) r = 10 * r + a[i];     return isp[r];   }   int D[5][5], n, res;   void dfs(int r, int c) {     if (n <= 4 && r == n - 1) {       res++;       return;     }     if (n == 5 && r == n - 2) {       res += cnt[D[3][0] * 1000 + D[3][1] * 100 + D[3][2] * 10 + D[3][4]];       return;     }     for (int i = 0; i < 10; i++) {       D[r][c] = D[c][r] = i;       if (c == n - 2) {         if (isPrime(D[r], n)) dfs(r + 1, r + 1);       } else {         dfs(r, c + 1);       }       if (D[r][n - 1] == 2) break;     }   }   int main() {     generatePrime(100000);     for (int i : prime) {       int t = i;       int ok = 1;       while (t > 0) {         if (t % 10 != 2 && t % 2 == 0) ok = 0;         t /= 10;       }       if (ok) oddPrime.push_back(i);       int j = i / 100 * 10 + i % 10;       cnt[j]++;     }     int T;     cin >> T;     while (T--) {       int first;       cin >> first;       string s = tostring(first);       n = s.length();       res = 0;       for (int second : oddPrime) {         if (tostring(second).size() > n) continue;         for (int i = 0; i < n; i++) D[0][i] = D[i][0] = s[i] -  0 ;         string os = tostring(second, n);         if (os[0] != s[n - 1]) continue;         int ok = 1;         for (int i = 0; i < n; i++) {           int t = os[i] -  0 ;           D[i][n - 1] = D[n - 1][i] = t;           if (t % 2 == 0 && D[0][i] != 0) ok = 0;         }         if (ok) dfs(1, 1);       }       cout << res << endl;     }     cerr <<  [               0                ->                clock()               :            << 1e3 * (clock() - 0) / CLOCKS_PER_SEC <<  ms] n ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> a;   vector<int> r;   vector<vector<pair<int, int>>> pre, suf;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       a = vector<vector<int>>(n, vector<int>(m));       r = vector<int>(n);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }         r[i] = i;       }       sort(r.begin(), r.end(), [&](int i, int j) { return a[i][0] > a[j][0]; });       pre = suf = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>(m));       for (int i = 0; i < n; i++) {         pre[i][0].first = pre[i][0].second = a[i][0];         for (int j = 1; j < m; j++) {           pre[i][j].first = min(pre[i][j - 1].first, a[i][j]);           pre[i][j].second = max(pre[i][j - 1].second, a[i][j]);         }         suf[i][m - 1].first = suf[i][m - 1].second = a[i][m - 1];         for (int j = m - 2; j >= 0; j--) {           suf[i][j].first = min(a[i][j], suf[i][j + 1].first);           suf[i][j].second = max(a[i][j], suf[i][j + 1].second);         }       }       for (int j = 0; j + 1 < m; j++) {         vector<pair<int, int>> izq(n), der(n);         izq[r[0]].first = pre[r[0]][j].first;         der[r[0]].second = suf[r[0]][j + 1].second;         for (int i = 1; i + 1 < n; i++) {           izq[r[i]].first = min(izq[r[i - 1]].first, pre[r[i]][j].first);           der[r[i]].second = max(der[r[i - 1]].second, suf[r[i]][j + 1].second);         }         izq[r[n - 1]].second = pre[r[n - 1]][j].second;         der[r[n - 1]].first = suf[r[n - 1]][j + 1].first;         for (int i = n - 2; i > 0; i--) {           izq[r[i]].second = max(izq[r[i + 1]].second, pre[r[i]][j].second);           der[r[i]].first = min(der[r[i + 1]].first, suf[r[i]][j + 1].first);         }         for (int i = 0; i + 1 < n; i++) {           if (izq[r[i]].first > izq[r[i + 1]].second &&               der[r[i + 1]].first > der[r[i]].second) {             cout <<  YES  <<   n ;             string s(n,  R );             for (int j = i + 1; j < n; j++) s[r[j]] =  B ;             cout << s <<     << j + 1 <<   n ;             goto out;           }         }       }       cout <<  NO  <<   n ;     out:;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0)->sync_with_stdio(0);     int n;     cin >> n;     int sp = -1, rmv = 0, ans = 0;     stack<int> st;     while (n--) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         sp = x;       } else if (t == 3) {         int x;         cin >> x;         st.push(x);       } else if (t == 2) {         ans += rmv;         rmv = 0;       } else if (t == 4) {         rmv = 0;       } else if (t == 5) {         while (st.size()) st.pop();       } else if (t == 6) {         rmv++;       }       while (st.size() && st.top() < sp) {         st.pop();         ans++;       }     }     cout << ans <<   n ;   }