malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 2;   const long long N = 1e6 + 1;   long long n;   set<int> Q;   int main() {     scanf( %d , &n);     int ans = 1;     while (n--) {       int x;       scanf( %d , &x);       while (!Q.insert(x).second) {         Q.erase(x);         x++;       }     }     printf( %d n , Q.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     while (cin >> a) {       bool f = false;       if (a.length() < 3) {         cout <<  No  << endl;         continue;       }       for (int i = 0; i <= a.length() - 3; i++) {         b = a.substr(i, 3);         if (b[0] !=  .  && b[1] !=  .  && b[2] !=  . ) {           if (b[0] != b[1] && b[1] != b[2] && b[2] != b[0]) {             f = true;             break;           }         }         b.clear();       }       if (f)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     ll n, k;     cin >> n >> k;     if (k == 1 || k == n) {       cout << (3 * n);     } else {       cout << min(2 + 3 * (k - 1) + k + 3 + 3 * (n - k - 1),                   6 + 3 * (n - k - 1) + n - k + 3 * (k - 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[110];   int n, ans, len;   bool arr[110][220][55][2];   int main() {     scanf( %s%d , str + 1, &n);     len = strlen(str + 1);     arr[0][100][0][0] = true;     for (int i = 1; str[i]; ++i)       for (int j = 100 - i; j <= 100 + i; ++j)         for (int k = 0; k <= i && k <= n; ++k)           for (int l = 0; l <= 1; ++l) {             if (str[i] ==  T ) {               if (arr[i - 1][j][k][l ^ 1]) arr[i][j][k][l] = true;               if (k > 0 && (arr[i - 1][j + ((l == 0) ? -1 : 1)][k - 1][l]))                 arr[i][j][k][l] = true;             } else {               if (arr[i - 1][j + ((l == 0) ? -1 : 1)][k][l])                 arr[i][j][k][l] = true;               if (k > 0 && arr[i - 1][j][k - 1][l ^ 1]) arr[i][j][k][l] = true;             }           }     for (int j = 100 - len; j <= 100 + len; ++j)       for (int k = n; k >= 0; k -= 2)         for (int l = 0; l <= 1; ++l)           if (arr[len][j][k][l]) ans = max(ans, abs(100 - j));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4010;   const int T = 20010;   int n, p, q, c[N], h[N], t[N], cs[T], cd[T], b[T], rez[T];   int d[10010][N];   vector<int> v[T], v2[T], v3[T];   void sol(int pozs) {     int pozd = min(T - 1, pozs + 2 * p), mid = pozs + p;     vector<int>::iterator it;     int i, j;     for (i = pozs; i <= mid; ++i) memset(d[i - pozs], 0, sizeof(d[i - pozs]));     int din[N];     memset(din, 0, sizeof(din));     for (i = mid - 1; i >= pozs; --i) {       for (it = v[i].begin(); it != v[i].end(); ++it)         for (j = N - 1; j >= c[*it]; --j)           din[j] = max(din[j], din[j - c[*it]] + h[*it]);       memcpy(d[i - pozs], din, sizeof(din));     }     memset(din, 0, sizeof(din));     for (i = mid; i <= pozd; ++i) {       for (it = v[i].begin(); it != v[i].end(); ++it)         for (j = N - 1; j >= c[*it]; --j)           din[j] = max(din[j], din[j - c[*it]] + h[*it]);       for (it = v2[i - p].begin(); it != v2[i - p].end(); ++it)         for (j = 0; j <= b[*it]; ++j)           rez[*it] = max(rez[*it], d[i - p - pozs][j] + din[b[*it] - j]);     }   }   void sol1() {     int i, j;     int din[N];     memset(din, 0, sizeof(din));     vector<int>::iterator it;     for (i = 1; i <= p + 1; ++i) {       for (it = v[i].begin(); it != v[i].end(); ++it)         for (j = N - 1; j >= c[*it]; --j)           din[j] = max(din[j], din[j - c[*it]] + h[*it]);       for (it = v3[i].begin(); it != v3[i].end(); ++it) rez[*it] = din[b[*it]];     }   }   int main() {     int i, j, k;     cin >> n >> p;     --p;     for (i = 1; i <= n; ++i) {       cin >> c[i] >> h[i] >> t[i];       v[t[i]].push_back(i);     }     cin >> q;     for (i = 1; i <= q; ++i) {       cin >> cd[i] >> b[i];       cs[i] = max(1, cd[i] - p);       if (cs[i] == 1) {         v3[cd[i]].push_back(i);         continue;       }       v2[cs[i]].push_back(i);     }     sol1();     for (int t = 0; t + p < T; t += p) sol(t);     for (i = 1; i <= q; ++i) cout << rez[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     long long a[n];     long long maxi = LONG_LONG_MIN, mini = LONG_LONG_MAX;     map<long long, stack<long long> > ma;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (i < 5) {         maxi = max(maxi, a[i]);         mini = min(mini, a[i]);       }       ma[a[i]].push(i);     }     sort(a, a + n);     long long dp[n];     long long parent[n];     dp[0] = a[0];     dp[1] = a[1] - a[0];     dp[2] = a[2] - a[0];     dp[3] = a[3] - a[0];     dp[4] = a[4] - a[0];     long long ctr = 2;     memset(parent, -1, sizeof(parent));     for (long long i = 5; i < n; i++) {       long long temp1, temp2, temp3;       if (i >= 7) {         temp1 = dp[i - 3] + a[i] - a[i - 2];         temp2 = dp[i - 4] + a[i] - a[i - 3];         temp3 = dp[i - 5] + a[i] - a[i - 4];       } else if (i == 6) {         temp1 = dp[i - 3] + a[i] - a[i - 2];         temp2 = dp[i - 4] + a[i] - a[i - 3];         temp3 = LONG_LONG_MAX;       } else if (i == 5) {         temp1 = dp[i - 3] + a[i] - a[i - 2];         temp2 = LONG_LONG_MAX;         temp3 = LONG_LONG_MAX;       }       if ((temp1 <= temp2) && (temp1 <= temp3)) {         parent[i] = i - 3;       } else if ((temp2 <= temp3) && (temp2 <= temp1)) {         parent[i] = i - 4;       } else {         parent[i] = i - 5;       }       dp[i] = min(temp1, min(temp2, temp3));     }     vector<long long> res;     long long x = n - 1;     while (parent[x] != -1) {       res.push_back(x);       x = parent[x];     }     res.push_back(x);     long long ans[n];     long long team[n];     ctr = 1;     long long j = 0;     reverse(res.begin(), res.end());     for (long long i = 0; i < n; i++) {       team[i] = ctr;       if (i == res[j]) {         j++;         ctr++;       }     }     for (long long i = 0; i < n; i++) {       ans[ma[a[i]].top()] = team[i];       ma[a[i]].pop();     }     cout << dp[n - 1] <<     << ctr - 1 <<   n ;     for (long long i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   const int mod = 1000000007;   long long f[2005][2005], g[2005][2005];   int main() {     for (int n, m; scanf( %d%d , &n, &m) != EOF;) {       memset(f, 0, sizeof(f));       memset(g, 0, sizeof(g));       for (int i = 1; i <= n; i++) {         long long sum = 0;         for (int j = 2; j <= m; j++) {           f[i][j] = (g[i - 1][j] + 1) % mod;           sum = (sum + f[i][j]) % mod;           g[i][j] = (g[i][j - 1] + sum) % mod;         }       }       long long ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 2; j <= m; j++) {           ans = ans + (f[i][j] * (g[n - i][j] - f[n - i][j] + 1) % mod) *                           (m - j + 1) % mod;           ans = ans % mod;         }       }       printf( %I64d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   long long int _xor(long long int a, long long int b) { return a ^ b; }   long long int _and(long long int a, long long int b) { return a & b; }   long long int _or(long long int a, long long int b) { return a | b; }   long long int _not(long long int a) { return ~a; }   long long int ai[1000], pi[2005];   long long int dp[100001];   int main() {     long long int b, c = 0, x, y, z, t, i, j, k, l1, l2, m, n, c1 = 0, c2 = 0, q,                      f = 0, ans = 0;     string str;     cin >> str;     dp[0] = 0;     for (i = 1; i < str.length(); i++) {       if (str[i] == str[i - 1]) {         dp[i] = dp[i - 1] + 1;       } else         dp[i] = dp[i - 1];     }     scanf( %lld , &m);     long long int low, up;     for (i = 0; i < m; i++) {       scanf( %lld , &low);       scanf( %lld , &up);       up--;       low--;       cout << dp[up] - dp[low] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void affiche(int t[], int n) {     for (int i = 0; i < n; i++) cout << t[i] <<    ;     cout <<   n ;   }   void afficheV(vector<int> t) {     for (int i = 0; i < t.size(); i++) cout << t[i] <<    ;   }   vector<vector<int> > adj(50005);   vector<bool> visited(50005, false);   int ans[50005];   int dp[50005];   int r1, r2;   void DFS(int node) {     visited[node] = true;     for (int i = 0; i < adj[node].size(); i++) {       int child = adj[node][i];       if (!visited[child]) {         ans[child] = node;         DFS(child);       }     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n >> r1 >> r2;     memset(dp, -1, sizeof dp);     for (int i = 1; i < n + 1; i++) {       if (i == r1) continue;       int x;       cin >> x;       adj[x].push_back(i);       adj[i].push_back(x);     }     DFS(r2);     for (int i = 1; i < n + 1; i++) {       if (i == r2) continue;       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   namespace FGF {   int n, m;   const int N = 2e5 + 5;   const double eps = 1e-10;   struct Node {     double x, t;   } a[N];   double sum, ans;   bool cmp(Node u, Node v) { return u.t < v.t; }   void work() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i].x);     for (int i = 1; i <= n; i++) {       scanf( %lf , &a[i].t), a[i].t -= m;       sum += a[i].x * a[i].t;     }     sort(a + 1, a + n + 1, cmp);     if (a[1].t > 0 || a[n].t < 0) {       puts( 0 );       return;     }     if (sum > 0) {       sum = 0;       for (int i = 1; i <= n; i++) {         if (sum + a[i].x * a[i].t > 0) {           ans = ans + sum / (-a[i].t);           break;         } else           ans += a[i].x, sum += a[i].x * a[i].t;       }     } else {       sum = 0;       for (int i = n; i; i--) {         if (sum + a[i].x * a[i].t < 0) {           ans = ans + sum / (-a[i].t);           break;         } else           ans += a[i].x, sum += a[i].x * a[i].t;       }     }     printf( %.12f , ans);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   struct modint {     long long x;     modint(long long o = 0) { x = o; }     modint &operator=(long long o) { return x = o, *this; }     modint &operator+=(modint o) {       return x = x + o.x >= 1000000007 ? x + o.x - 1000000007 : x + o.x, *this;     }     modint &operator-=(modint o) {       return x = x - o.x < 0 ? x - o.x + 1000000007 : x - o.x, *this;     }     modint &operator*=(modint o) { return x = 1ll * x * o.x % 1000000007, *this; }     modint &operator^=(long long b) {       modint a = *this, c = 1;       for (; b; b >>= 1, a *= a)         if (b & 1) c *= a;       return x = c.x, *this;     }     modint &operator/=(modint o) { return *this *= o ^= 1000000007 - 2; }     modint &operator+=(long long o) {       return x = x + o >= 1000000007 ? x + o - 1000000007 : x + o, *this;     }     modint &operator-=(long long o) {       return x = x - o < 0 ? x - o + 1000000007 : x - o, *this;     }     modint &operator*=(long long o) {       return x = 1ll * x * o % 1000000007, *this;     }     modint &operator/=(long long o) {       return *this *= ((modint(o)) ^= 1000000007 - 2);     }     template <class I>     friend modint operator+(modint a, I b) {       return a += b;     }     template <class I>     friend modint operator-(modint a, I b) {       return a -= b;     }     template <class I>     friend modint operator*(modint a, I b) {       return a *= b;     }     template <class I>     friend modint operator/(modint a, I b) {       return a /= b;     }     friend modint operator^(modint a, long long b) { return a ^= b; }     friend bool operator==(modint a, long long b) { return a.x == b; }     friend bool operator!=(modint a, long long b) { return a.x != b; }     bool operator!() { return !x; }     modint operator-() { return x ? 1000000007 - x : 0; }   };   long long n, m, k;   modint x, p[1505], sump[1505], fr[1505][1505], s[1505][1505], tmp[1505][1505];   modint fac[1000005], iv[1000005];   void pre(long long n) {     fac[0] = iv[0] = 1;     for (register long long i = (1); i <= (n); ++i)       fac[i] = fac[i - 1] * i, iv[i] = iv[i - 1] / i;   }   inline modint C(long long n, long long m) { return fac[n] * iv[m] * iv[n - m]; }   signed main() {     n = read(), m = read(), x = read(), x /= read(), k = read();     pre(1e6);     for (register long long i = (0); i <= (min(m, k)); ++i)       p[i] = C(k, i) * (x ^ i) * ((-x + 1) ^ (k - i));     for (register long long i = (1); i <= (m); ++i)       sump[i] = sump[i - 1] + p[i - 1];     fr[0][m] = s[0][m] = 1;     for (register long long i = (1); i <= (n); ++i)       for (register long long r = (1); r <= (m); ++r) {         fr[i][r] = p[m - r] *                    (sump[r] * (s[i - 1][m] - s[i - 1][m - r]) - tmp[i - 1][r]);         s[i][r] = s[i][r - 1] + fr[i][r];         tmp[i][r] = tmp[i][r - 1] + p[r - 1] * s[i][r - 1];       }     cout << s[n][m].x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<510> reach[510];   int n, p[510], use[510], i, j, wz[510];   char s[510];   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &p[i]), wz[p[i]] = i;     for (i = 1; i <= n; i++) {       scanf( %s , s + 1);       reach[i][i] = 1;       for (j = 1; j <= n; j++)         if (s[j] ==  1 ) reach[i][j] = 1;     }     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (reach[j][i]) reach[j] |= reach[i];     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++)         if (!use[j] && reach[i][wz[j]]) break;       use[j] = 1;       printf( %d  , j);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a, flag = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       if (a == 1) flag = 1;     }     if (flag == 1)       cout <<  HARD  << endl;     else       cout <<  EASY  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int cnt[maxn], a[maxn], n, q;   signed main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         cnt[i] = 0;       }       vector<int> res;       for (int i = 1; cnt[i] < 3; i -= a[i])         if ((++cnt[i]) == 2)           res.push_back(i);         else if (cnt[i] == 3)           break;       printf( %d n , (int)res.size());       for (int u : res) printf( %d  , u);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c[1003];   char s[1003];   int sign[1003];   int fi[1003];   int main() {     int n, m;     cin >> n >> m;     getchar();     int num = 0;     int ans = 1001;     for (int i = 0; i < n; i++) {       scanf( %c , &c[i]);     }     getchar();     for (int i = 0; i < m; i++) {       scanf( %c , &s[i]);     }     for (int j = 0; j < m - n + 1; j++) {       memset(sign, 0, sizeof(sign));       num = 0;       for (int q = 0; q < n; q++) {         if (s[j + q] != c[q]) {           sign[num++] = q + 1;         }       }       if (ans > num) {         ans = num;         memcpy(fi, sign, sizeof(int) * num);       }     }     printf( %d n , ans);     for (int i = 0; i < ans; i++) {       printf( %d  , fi[i]);     }     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const int MAXN = 1e5 + 10;   int v[MAXN];   int lis[MAXN];   int main() {     int n;     scanf( %d , &n);     for (int a = 0; a < n; ++a) scanf( %d , &v[a]);     memset(lis, INF, sizeof(lis));     for (int a = 0; a < n; ++a) {       int i = lower_bound(lis, lis + n, v[a]) - lis;       lis[i] = v[a];     }     int hi = 0;     for (int a = 0; a < n; ++a)       if (lis[a] != INF) hi = a;     printf( %d n , hi + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct road {     int x, next;   } r[100005 * 2];   int N, M, D, ans;   int vis[100005], p[100005];   int down[100005], up[100005];   int st[100005], w;   void add(int x, int y) {     r[++w].x = y, r[w].next = st[x];     st[x] = w;   }   void Make_Down(int x, int fr) {     int i, tmp;     if (vis[x])       down[x] = 0;     else       down[x] = -0x7ffffff;     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (tmp == fr) continue;       Make_Down(tmp, x);       down[x] = max(down[x], down[tmp] + 1);     }   }   void Dfs(int x, int fr) {     int i, tmp;     int m1 = 0, m2 = 0;     if (vis[x]) up[x] = max(up[x], 0);     if (max(down[x], up[x]) <= D) ans++;     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (tmp == fr) continue;       if (down[m1] <= down[tmp])         m2 = m1, m1 = tmp;       else if (down[m2] <= down[tmp])         m2 = tmp;     }     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (tmp == fr) continue;       if (tmp == m1)         up[tmp] = max(up[x] + 1, down[m2] + 2);       else         up[tmp] = max(up[x] + 1, down[m1] + 2);       Dfs(tmp, x);     }   }   int main() {     int i, j;     int fr, to;     scanf( %d %d %d , &N, &M, &D);     for (i = 1; i <= M; i++) scanf( %d , &p[i]), vis[p[i]] = 1;     for (i = 1; i < N; i++) {       scanf( %d %d , &fr, &to);       add(fr, to), add(to, fr);     }     down[0] = up[0] = -0x7ffffff;     memset(up, 200, sizeof(up));     Make_Down(1, 0);     Dfs(1, 0);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(0);     int cases, caseno = 0, n, i, j, k, cnt, sum;     cin >> n >> j >> k;     for (i = 1; i <= 10000; i++) {       if (n == 2) {         cout <<  Final! ;         return 0;       }       if ((j + 1) / 2 == (k + 1) / 2) {         cout << i;         return 0;       }       j = (j + 1) / 2;       k = (k + 1) / 2;       n /= 2;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       int tot = 0;       vector<int> v;       for (int i = 1; i < n + 1; i++) {         if (tot + i > n) {           v.back() += n - tot;           break;         } else {           tot += i;           v.push_back(i);         }       }       cout << v.size() <<   n ;       for (int i = 0; i < v.size(); i++) {         cout << v[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   int n, m;   int main(void) {     while (cin >> n >> m && n && m) {       priority_queue<long long, vector<long long>, greater<long long> > que;       for (int i = 0; i < n; i++) {         long long a;         que.push((cin >> a, a));       }       for (int i = 0; i < m; i++) {         long long b;         cin >> b;         if (!que.empty() && que.top() <= b) que.pop();       }       cout << que.size() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e7 + 7;   const long long mo = 1e9 + 7;   long long n, m, k, p, q, r, mod, i, j, d = 0, ans;   long long wz;   int main() {     scanf( %lld %lld %lld , &n, &m, &k);     r = n - 1;     ans = r * m;     wz = 1;     if (ans < k || m > k)       printf( NO n );     else {       printf( YES n );       while (k - r > m - 1) {         if (d == 0)           wz = n;         else           wz = 1;         printf( %lld  , wz);         k -= r;         d ^= 1;         m--;       }       p = k - m + 1;       if (m > 0 && p != 0) {         m--;         if (d == 0)           wz = wz + p;         else           wz = wz - p;         printf( %lld  , wz);         d ^= 1;       }       while (m--) {         if (d == 0)           wz = wz + 1;         else           wz = wz - 1;         printf( %lld  , wz);         d ^= 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   long long pow_mod(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       n >>= 1;       x = x * x % mod;     }     return res;   }   long long inv(long long x) { return pow_mod(x, mod - 2); }   int main() {     long long n, a, b, k;     string s;     while (cin >> n >> a >> b >> k) {       cin >> s;       long long ans = 0;       for (long long i = 0; i < k; i++) {         if (s[i] ==  + )           ans = ((ans + pow_mod(a, n - i) * pow_mod(b, i)) % mod + mod) % mod;         else           ans = ((ans - pow_mod(a, n - i) * pow_mod(b, i)) % mod + mod) % mod;       }       long long m = (n + 1) / k;       long long q = pow_mod(b, k) * inv(pow_mod(a, k)) % mod;       if (q == 1)         ans = ans * m % mod;       else {         ans = ans * (1 - pow_mod(q, m)) % mod;         ans = ans * inv(1 - q) % mod;       }       cout << (ans + mod) % mod << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int find(vector<int>& par, int x) {     if (x != par[x]) return find(par, par[x]);     return x;   }   bool same(vector<int>& par, int x, int y) {     return find(par, x) == find(par, y);   }   void merge(vector<int>& par, vector<int>& sz, int x, int y) {     int X = find(par, x);     int Y = find(par, y);     if (sz[X] < sz[Y]) swap(X, Y);     par[Y] = X;     sz[X] += sz[Y];     return;   }   int main(int argc, char const* argv[]) {     cin.sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> sz(n);     vector<int> par(n);     for (int i = 0; i < n; i++) {       sz[i] = 1;       par[i] = i;     }     vector<vector<int> > l(m);     int maxk = -1;     int ind = -1;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       if (maxk < k) {         maxk = k;         ind = i;       }       for (int j = 0; j < k; j++) {         int lng;         cin >> lng;         lng--;         l[lng].push_back(i);       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < l[i].size(); j++) {         if (!same(par, l[i][0], l[i][j])) {           merge(par, sz, l[i][0], l[i][j]);         }       }     }     int ret = 0;     if (maxk == 0) {       cout << n;       return 0;     }     for (int i = 0; i < n; i++) {       if (!same(par, ind, i)) {         merge(par, sz, ind, i);         ret++;       }     }     cout << ret;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 200000;   int n;   int a[mxn], b[mxn], first[mxn], ff[mxn];   vector<int> v[mxn];   auto cmp = [](int x, int y) { return b[x] > b[y]; };   priority_queue<int, vector<int>, decltype(cmp)> pq(cmp);   map<int, int> second;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];       a[i]--, b[i]--;       v[a[i]].push_back(i);     }     int p = -1, q = -1;     for (int i = 0; i < n; i++) {       for (int j : v[i]) pq.push(j);       int x = pq.top();       pq.pop();       first[i] = x, ff[x] = i + 1;       if (!~p) {         auto it = second.lower_bound(i);         if (it != second.end() && it->second >= a[x]) {           p = first[it->second], q = x;         } else {           it = second.insert({b[x], i}).first;           if (it->second < i) {             if (next(it) != second.end() && i <= next(it)->second)               it = second.erase(it);             while (it != second.begin() && (--it)->second <= i)               it = second.erase(it);           }         }       }     }     cout << (!~p ?  YES  :  NO ) <<   n ;     for (int i = 0; i < 1 + !!~p; i++) {       cout << ff[0];       for (int i = 1; i < n; i++) cout <<     << ff[i];       cout <<   n ;       if (~p) swap(ff[p], ff[q]);     }     return 0;   }