malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 200005;   long long fasmul(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b / 2;     }     return res;   }   void solve() {     long long n;     char c;     string s;     cin >> n >> c >> s;     long long d = n / 2;     long long ok = 1;     for (long long i = 0; i < n; i++)       if (s[i] != c) ok = 0;     if (ok) {       cout << 0 <<   n ;       return;     }     for (long long i = d; i < n; i++) {       if (s[i] == c) {         cout << 1 <<   n ;         cout << i + 1 <<   n ;         return;       }     }     cout << 2 <<   n ;     cout << n <<     << n - 1 <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a[n], mx = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > mx) mx = a[i];     }     long long int freq[mx + 1];     for (int i = 0; i < mx + 1; i++) {       freq[i] = 0;     }     for (int i = 0; i < n; i++) {       freq[a[i]]++;     }     long long int dp[mx + 1];     dp[0] = 0;     dp[1] = freq[1];     for (int i = 2; i <= mx; i++) {       dp[i] = max(dp[i - 1], (freq[i] * i) + dp[i - 2]);     }     cout << dp[mx];   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30);   const double eps = 1e-9;   const int mod = 1000000007;   const int MAXN = int(1e5) + 100;   const int dx[] = {-1, +1, 0, 0};   const int dy[] = {0, 0, -1, +1};   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> arr(n);     for (int i = (0); i < int(n); ++i) {       cin >> arr[i];     }     sort((arr).begin(), (arr).end());     for (int i = (1); i < int(n); ++i) {       int x = arr[i - 1];       int y = arr[i];       if (x == y) continue;       if (y < x * 2) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n;   vector<int> dig;   long long cnt[15];   long long C[25][25];   struct cond {     int sum;     int a[20];     string s;     cond() {       for (int i = 0; i < 20; i++) {         a[i] = 0;       }       s =   ;       sum = 0;     }   };   void calculateC() {     for (int i = 0; i <= 20; i++)       for (int j = 0; j <= 20; j++) C[i][j] = 0;     for (int i = 0; i < 20; i++) C[i][0] = 1;     for (int i = 1; i <= 20; i++)       for (int j = 1; j <= 20; j++)         C[i][j] =             ((C[i][j] % MOD) + ((C[i - 1][j] + C[i - 1][j - 1]) % MOD)) % MOD;   }   long long C2(int n, int k) {     if (n < 0 || k < 0 || k > n) return 0;     long long ans = 1;     for (int i = n; i > n - k; i--) ans = (ans * i) % MOD;     return ans % MOD;   }   long long Power2(int n) {     long long k = 1ll;     for (int i = 1; i <= n; i++) k = (k * 2ll) % MOD;     return k;   }   long long Power8(int n) {     long long k = 1ll;     for (int i = 1; i <= n; i++) k = (k * 8ll) % MOD;     return k;   }   bool good(int n) {     if (n == 4 || n == 7) return true;     return false;   }   void findcnt(int pos, int sum) {     if (pos == (int)dig.size()) return;     int p = (int)dig.size() - pos;     long long Q = (long long)dig[pos];     if (p == 1) {       cnt[0]--;       for (int i = 0; i <= Q; i++)         if (good(i))           cnt[sum + 1]++;         else           cnt[sum]++;       return;     }     for (int i = 0; i <= p - 1; i++) {       for (int j = 0; j < Q; j++) {         if (!good(j))           cnt[i + sum] += Power2(i) * C[p - 1][i] * Power8(p - 1 - i);         else           cnt[i + sum + 1] += Power2(i) * C[p - 1][i] * Power8(p - 1 - i);       }     }     if (good(dig[pos]))       findcnt(pos + 1, sum + 1);     else       findcnt(pos + 1, sum);   }   long long ans = 0;   vector<cond> allposib;   void BT(int pos, int sum, string s) {     if (pos == 6) {       cond A;       for (int i = 0; i < (int)s.length(); i++) A.a[(int)s[i] - (int) 0 ]++;       A.sum = sum;       A.s = s;       if (sum <= 10) allposib.push_back(A);     } else       for (int i = 0; i <= 10; i++)         BT(pos + 1, sum + i, s + (char)(i + (int) 0 ));   }   int fac(int n) {     int ans = 1;     for (int i = 1; i <= n; i++) ans *= i;     return ans;   }   int main() {     calculateC();     for (int i = 0; i <= 10; i++) cnt[i] = 0;     cin >> n;     while (n) {       dig.push_back(n % 10);       n /= 10;     }     reverse((dig).begin(), (dig).end());     findcnt(0, 0);     BT(0, 0,   );     long long ans = 0;     for (int i = 0; i < (int)allposib.size(); i++) {       int from = allposib[i].sum + 1;       long long tmp = 1, posfor7 = 0;       for (int j = 0; j <= 10; j++) {         tmp = (tmp * (C2(cnt[j], allposib[i].a[j]))) % MOD;       }       for (int j = from; j <= 10; j++) posfor7 += cnt[j];       posfor7 %= MOD;       tmp = (tmp * posfor7) % MOD;       ans = (ans + tmp) % MOD;     }     cout << ans % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   template <typename T>   inline void rd(T& x) {     int si = 1;     char c = getchar();     x = 0;     while (!isdigit(c)) si = c ==  -  ? -1 : si, c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     x *= si;   }   template <typename T, typename... Args>   inline void rd(T& x, Args&... args) {     rd(x);     rd(args...);   }   const int kN = 4e5 + 5, kInf = 0x3f3f3f3f;   const long long kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;   long long QPow(long long a, long long b) {     long long ans = 1, bas = a;     for (; b; b >>= 1, bas = bas * bas % kMod)       if (b & 1) ans = ans * bas % kMod;     return ans;   }   struct Edge {     int u, v, c;   } E[kN];   int n, m, fa[kN], s[kN], col[kN], cnt[kN];   std::vector<int> pt[2];   bool flag = false;   int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }   void Merge(int x, int y) {     int fx = Find(x), fy = Find(y);     if (fx == fy) return;     s[fx] += s[fy];     fa[fy] = fx;   }   void Solve(int x) {     memset(col, 0xff, sizeof(col));     for (int i = 1; i <= 2 * n; ++i) {       fa[i] = i;       s[i] = (i <= n);     }     for (int i = 1; i <= m; ++i) {       int u = E[i].u, v = E[i].v, c = E[i].c ^ x;       if (c)         Merge(u, v), Merge(u + n, v + n);       else         Merge(u + n, v), Merge(u, v + n);     }     for (int i = 1; i <= n; ++i)       if (Find(i) == Find(i + n)) return;     flag = true;     for (int i = 1; i <= n; ++i)       if (col[Find(i)] == -1) {         col[Find(i)] = (s[Find(i)] < s[Find(i + n)]);         col[Find(i + n)] = !col[Find(i)];       }     cnt[x] = 0;     for (int i = 1; i <= n; ++i)       if (col[Find(i)] == 1) {         ++cnt[x];         pt[x].push_back(i);       }   }   int main() {     int T = 1;     while (T--) {       rd(n, m);       cnt[0] = cnt[1] = kInf;       for (int i = 1; i <= m; ++i) {         char c[5];         rd(E[i].u, E[i].v);         scanf( %s , c + 1);         E[i].c = (c[1] ==  B );       }       for (int i = 0; i < 2; ++i) Solve(i);       if (flag) {         if (cnt[0] < cnt[1]) {           printf( %d n , cnt[0]);           for (auto i : pt[0]) printf( %d  , i);         } else {           printf( %d n , cnt[1]);           for (auto i : pt[1]) printf( %d  , i);         }       } else         printf( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int a[N], c[N], f[N], g[N], n, q, m, len, ans[N];   map<int, int> mp;   inline void read(int &x) {     char c = getchar();     x = 0;     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }   }   inline void write(int x) {     if (x == 0) putchar( 0 );     int a[20];     a[0] = 0;     while (x) {       a[++a[0]] = x % 10;       x /= 10;     }     while (a[0]) putchar(a[a[0]--] +  0 );     putchar(  n );   }   struct data {     int l, r, pos;     bool operator<(const data &a) const {       return l / m == a.l / m ? ((l / m) & 1 ? r > a.r : r < a.r)                               : l / m < a.l / m;     }   } b[N];   inline void add(int x, int y) {     if (f[x] >= m)       mp.erase(x);     else       --g[f[x]];     f[x] += y;     if (f[x] >= m)       mp[x] = f[x];     else       ++g[f[x]];   }   int heap[N];   inline void down(int x) {     int y = x * 2;     if (y > len) return;     if (heap[y] > heap[y + 1] && y + 1 <= len) y = y + 1;     if (heap[x] > heap[y]) {       swap(heap[x], heap[y]);       down(y);     }   }   inline int work() {     int ans = 0, pr = 0;     len = 0;     for (int i = 1; i < m; ++i) c[i] = g[i];     for (int i = 1; i < m; ++i) {       if (!c[i]) continue;       if (pr) {         --c[i];         int p = pr + i;         ans += p;         if (p < m)           ++c[p];         else           heap[++len] = p;         pr = 0;       }       if (c[i] % 2 == 1) pr = i;       ans += i * 2 * (c[i] / 2);       if (i * 2 < m)         c[i * 2] += c[i] / 2;       else {         for (int j = 1; j <= c[i] / 2; ++j) heap[++len] = i * 2;       }     }     if (pr != 0) heap[++len] = pr;     map<int, int>::iterator it;     for (it = mp.begin(); it != mp.end(); ++it) heap[++len] = it->second;     for (int i = len / 2; i >= 1; --i) down(i);     while (len != 1) {       int p = heap[1];       heap[1] = heap[len];       --len;       down(1);       int q = heap[1];       ans += p + q;       heap[1] += p;       down(1);     }     return ans;   }   inline void change(int x, int y) {     if (b[x].l > b[y].l) {       for (int i = b[y].l; i < b[x].l; ++i) add(a[i], 1);     } else {       for (int i = b[x].l; i < b[y].l; ++i) add(a[i], -1);     }     if (b[x].r < b[y].r) {       for (int i = b[x].r + 1; i <= b[y].r; ++i) add(a[i], 1);     } else {       for (int i = b[y].r + 1; i <= b[x].r; ++i) add(a[i], -1);     }   }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(a[i]);     read(q);     for (int i = 1; i <= q; ++i) {       read(b[i].l);       read(b[i].r);       b[i].pos = i;     }     m = (int)sqrt(n);     sort(b + 1, b + 1 + q);     g[0] = n;     for (int i = b[1].l; i <= b[1].r; ++i) add(a[i], 1);     for (int i = 1; i < q; ++i) {       ans[b[i].pos] = work();       change(i, i + 1);     }     ans[b[q].pos] = work();     for (int i = 1; i <= q; ++i) write(ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     string s;     cin >> s;     for (i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) break;     }     if (i == s.length())       cout << s.length();     else       cout << i + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(long long x, long long y) { return x > y; }   int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   int n, k;   char s[100000 + 5];   int prefix[100000 + 5];   bool check(int x, int i) {     int tmp = prefix[min(n - 1, i + x)];     if (i - x > 0) tmp -= prefix[i - x - 1];     if (tmp >= k + 1) return true;     return false;   }   int main() {     cin >> n >> k;     cin >> s;     for (int i = 0; i < n; i++) {       if (i != 0) prefix[i] = prefix[i - 1];       prefix[i] += (s[i] ==  0 );     }     int res = 1e9;     for (int i = 0; i < n; i++) {       int ans = 1e9;       if (s[i] ==  0 ) {         int l = 0, r = 1e9;         while (l != r) {           int mid = (l + r - 1) / 2;           if (check(mid, i)) {             r = mid;             ans = min(ans, mid);           } else             l = mid + 1;         }         res = min(res, ans);       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int maxn = 3000 + 10;   int n, m, A[maxn], B[maxn];   long long f[maxn][maxn];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &A[i]);       A[i] -= i;       B[i] = A[i];     }   }   void solve() {     sort(B + 1, B + n + 1);     m = 1;     for (int i = 2; i <= n; ++i)       if (B[m] != B[i]) B[++m] = B[i];     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= m; ++j) f[i][j] = inf;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         f[i][j] = min(f[i][j - 1], f[i - 1][j] + abs(A[i] - B[j]));     long long ans = inf;     for (int i = 1; i <= m; ++i) ans = min(ans, f[n][i]);     printf( %I64d n , ans);   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[605][605];   int C[605][605];   map<int, int> mp;   int main() {     int n, m, ans = 1;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       for (int j = 2; j * j <= x; j++)         for (; x % (j * j) == 0; x /= j * j)           ;       mp[x]++;     }     for (int i = 0; i <= 2 * n; i++)       for (int j = C[i][0] = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007;     f[0][0] = 1;     n = m = 0;     map<int, int>::iterator it;     for (it = mp.begin(); it != mp.end(); it++) {       int t = it->second;       for (int i = 1; i <= t; i++) ans = 1ll * ans * i % 1000000007;       for (int i = 0; i <= m; i++)         if (f[n][i])           for (int k = 1; k <= t; k++)             for (int j = 0; j <= i && j <= k; j++)               f[n + 1][i - j + t - k] =                   (f[n + 1][i - j + t - k] +                    1ll * f[n][i] * C[t - 1][k - 1] % 1000000007 * C[i][j] %                        1000000007 * C[m + 1 - i][k - j] % 1000000007) %                   1000000007;       n++;       m += t;     }     printf( %d , 1ll * ans * f[n][0] % 1000000007);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i != n; ++i) {       cin >> v[i];       v[i] -= (n - i);     }     sort(v.begin(), v.end());     for (int i = 0; i != n - 1; ++i) {       if (v[i] + 1 > v[i + 1]) {         cout <<  :( n ;         return 0;       }     }     for (int i = 0; i != n; ++i) {       cout << v[i] + (n - i) <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, a[100];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i == 1) m = a[1];       m = min(m, a[i]);     }     for (int i = 1; i <= n; i++) {       x += (a[i] == m);     }     if (x <= n / 2)       printf( Alice );     else       printf( Bob );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   const int mod = 1e9 + 7;   void fwht(long long f[], int n) {     for (int b = 0; b < n; ++b)       for (int i = 0; i < (1 << n); i += (1 << (b + 1)))         for (int j = 0; j < (1 << b); ++j) {           int u = f[i + j];           int v = f[i + j + (1 << b)];           f[i + j] = (u + v) % mod;           f[i + j + (1 << b)] = (u - v + mod) % mod;         }   }   int n;   long long f[N], g[N], mark[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     string s;     cin >> s;     for (int i = 0; i < (1 << n); ++i) mark[i] = f[i] = s[i] -  0 ;     for (int i = 0; i < (1 << n); ++i) g[i] = 1 << (n - __builtin_popcount(i));     fwht(f, n);     fwht(g, n);     for (int i = 0; i < (1 << n); ++i) f[i] = f[i] * g[i] % mod;     fwht(f, n);     long long res = 0;     for (int i = 0; i < (1 << n); ++i) res = (res + mark[i] * f[i]) % mod;     for (int i = 0; i < n; ++i) res = res * ((mod + 1) / 2) % mod;     cout << res * 3 % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double low = 0, high = 0, mid = 0;   int binary_sear(const vector<int>& v, int x) {     while (1) {       mid = floor((low + high) / 2);       if (low > high) break;       if (v[mid] == x) {         return mid;         break;       } else if (v[mid] < x) {         low = mid + 1;       } else {         high = mid - 1;       }     }     return -1;   }   int binary(vector<int> v, int x) {     mid = floor((low + high) / 2);     cout << low <<     << mid <<     << high << endl;     if (low > high) return -1;     if (v[mid] == x)       return mid;     else if (v[mid] < x) {       low = mid + 1;       return binary(v, x);     } else {       high = mid - 1;       return binary(v, x);     }   }   string decToBinary(int n) {     string s = {};     int i = 0;     while (n > 0) {       s += (n % 2) + 48;       n = n / 2;       i++;     }     reverse(s.begin(), s.end());     return s;   }   int main() {     long long int a, b = 0, c = 1, n, m, mx = 0, mn = 0;     vector<int> v;     bool flag = true, flag2 = true;     cin >> n;     while (n--) {       cin >> m;       for (int i = 0; i < m; i++) {         cin >> a;         if (i == 0) {           b = a;           c = a;           continue;         }         b += a;         c ^= a;       }       cout << 2 << endl;       cout << c <<     << c + b << endl;       b = 0;       c = 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int W, N, M;   vector<int> freq;   vector<uint16_t> quick_count;   int needed(char bit_gate, int bit) {     switch (bit_gate) {       case  A :         return bit == 0 ? 2 : 0;       case  O :         return bit == 0 ? 0 : -1;       case  X :         return bit;       case  a :         return bit == 0 ? -1 : 1;       case  o :         return bit == 0 ? 1 : 2;       case  x :         return bit ^ 1;     }     assert(false);   }   int recurse(string &gate, int position, int mask, int extended) {     if (position >= W) return freq[mask] * quick_count[extended];     int opt0 = needed(gate[position], 0);     int opt1 = needed(gate[position], 1);     int answer = 0;     if (opt0 != -1)       answer +=           recurse(gate, position + 1, mask, extended + (opt0 << 2 * position));     if (opt1 != -1)       answer += recurse(gate, position + 1, mask + (1 << position),                         extended + (opt1 << 2 * position));     return answer;   }   int solve(string gate) {     reverse(gate.begin(), gate.end());     return recurse(gate, 0, 0, 0);   }   int main() {     scanf( %d %d %d , &W, &N, &M);     freq.resize(1 << W);     for (int i = 0; i < N; i++) {       int v;       scanf( %d , &v);       freq[v]++;     }     quick_count.resize(1 << 2 * W);     for (int a = 0; a < 1 << W; a++) {       int expanded = 0;       for (int i = 0; i < W; i++)         if (a & 1 << i) expanded += 1 << 2 * i;       quick_count[expanded] = freq[a];     }     int a = 0;     while (a < 1 << 2 * W) {       for (int i = 0; i < W; i++)         if ((a >> 2 * i) % 4 == 2) {           quick_count[a] =               quick_count[a - (2 << 2 * i)] + quick_count[a - (1 << 2 * i)];           break;         }       int index = W;       for (int i = 0; i < W; i++)         if ((a >> 2 * i) % 4 == 2) {           a ^= a & 3 << 2 * i;         } else {           index = i;           break;         }       a += 1 << 2 * index;     }     for (int i = 0; i < M; i++) {       char gate[100];       scanf( %s , gate);       printf( %d n , solve(gate));     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1000000000000000;   string s;   vector<long long> prim;   set<long long> prim2;   void primeFactors(int n) {     while (n % 2 == 0) {       prim.push_back(2);       prim2.insert(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         prim.push_back(i);         prim2.insert(i);         n = n / i;       }     }     if (n > 2) {       prim.push_back(n);       prim2.insert(n);     }   }   long long dp[3001][3001];   long long n;   pair<long long, long long> arr[4000];   long long get_ans(long long i, long long prev) {     if (i > n) {       return 0;     }     if (dp[i][prev] != -inf) return dp[i][prev];     long long x = 0, y = 0;     x = get_ans(i + 1, i) + arr[i].second;     y = abs(arr[prev].first - arr[i].first) + get_ans(i + 1, prev);     return dp[i][prev] = min(x, y);   }   void func() {     cin >> n;     for (int i = 1; i <= n; i++) {       long long a, b;       cin >> a >> b;       arr[i] = {a, b};     }     sort(arr + 1, arr + n + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = -inf;       }     }     cout << get_ans(2, 1) + arr[1].second <<   n ;   }   int main() {     {       ios ::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     }     { func(); }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long s = 0;     for (long long i = 1; i < n; i++) {       if (a[i] == a[i - 1]) s++;     }     if (s)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   int check(long long k) {     long long patsum = 0, nn = n, pat;     while (nn > 0) {       nn = nn - k;       pat = nn / 10;       nn = nn - pat;       patsum += pat;       if (patsum > n / 2) {         return 1;       }     }     return 0;   }   long long bs() {     long long left = 1, right = n, k;     while (left < right) {       k = (right + left) / 2;       if (check(k)) {         left = k + 1;       } else         right = k;     }     return left;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1, k, pat, patsum = 0, ori, flag = 0;     while (t--) {       cin >> n;       long long ans = bs();       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     int32_t n;     std::cin >> n;     std::set<std::pair<int32_t, int32_t> > segments;     for (int32_t i = 0; i < n; i++) {       int32_t left, right;       std::cin >> left >> right;       auto it = segments.lower_bound({left, 0});       if (it != segments.begin()) {         it--;         if (it->second < left) it++;       }       int32_t min_left = left, max_right = right;       while (it != segments.end() &&              ((it->second >= left && it->second <= right) ||               (it->first >= left && it->first <= right) ||               (it->first <= left && it->second >= right))) {         min_left = std::min(min_left, it->first);         max_right = std::max(max_right, it->second);         auto next = it;         next++;         segments.erase(it);         it = next;       }       segments.emplace(min_left, max_right);       std::cout << segments.size() <<    ;     }     return 0;   }