malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, k, w, f[1005], ans, cnt, t;   char a[1005][15][15];   vector<int> v[1005];   struct rec {     int x, y, z;   } e[1050005];   bool operator<(rec a, rec b) { return (a.z < b.z); }   int find(int x) {     if (f[x] == x)       return x;     else       return (f[x] = find(f[x]));   }   void dfs(int x, int fa) {     if (x > 0) cout << x <<     << fa <<   n ;     for (auto y : v[x])       if (y != fa) dfs(y, x);   }   int main() {     cin >> n >> m >> k >> w;     for (int i = 1; i <= k; ++i) {       for (int j = 1; j <= n; ++j)         for (int k = 1; k <= m; ++k) cin >> a[i][j][k];       e[++cnt].x = 0, e[cnt].y = i, e[cnt].z = n * m;       for (int j = 1; j <= i - 1; ++j) {         int sum = 0;         for (int k = 1; k <= n; ++k)           for (int l = 1; l <= m; ++l)             if (a[j][k][l] != a[i][k][l]) sum += w;         e[++cnt].x = i, e[cnt].y = j, e[cnt].z = sum;       }     }     sort(e + 1, e + cnt + 1);     for (int i = 0; i <= k; ++i) f[i] = i;     for (int i = 1; i <= cnt; ++i) {       int p = find(e[i].x), q = find(e[i].y);       if (p != q) {         f[p] = q;         ans += e[i].z;         v[e[i].x].push_back(e[i].y), v[e[i].y].push_back(e[i].x);         ++t;         if (t == k) break;       }     }     cout << ans <<   n ;     dfs(0, -1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, z;   };   int n, a[1001][1001], b[10001];   vector<node> v;   int main() {     int br = 0, i, j, x, y, in, mx, c;     node el;     cin >> n;     for (i = 1; i < n; i++) {       cin >> x >> y;       a[x][y] = 1;     }     for (i = 1; i <= n; i++)       for (j = n; j >= 1; j--)         if (a[i][j]) {           b[i] = j;           break;         }     for (i = n; i >= 1; i--) {       mx = -1;       for (j = 1; j <= n; j++)         if (b[j] > mx || mx == -1) {           mx = b[j];           c = j;         }       b[c] = 0;       swap(b[c], b[i]);       if (c != i) {         for (j = 1; j <= n; j++) swap(a[i][j], a[c][j]);         el.x = 1;         el.y = i;         el.z = c;         v.push_back(el);         br++;       }     }     for (j = 1; j <= n; j++) {       for (i = 1; i <= n; i++)         if (a[i][j]) break;       if (i == n + 1) {         in = j;       }     }     for (i = 1; i <= n; i++) b[i] = 10000;     for (j = 1; j <= n; j++)       for (i = 1; i <= n; i++)         if (a[i][j]) {           b[j] = i;           break;         }     for (j = 1; j < n; j++) {       mx = -1;       if (in != j) {         br++;         el.x = 2;         el.y = j;         el.z = in;         v.push_back(el);       }       swap(b[in], b[j]);       in = j;       for (i = j; i <= n; i++)         if (b[i] < mx || mx == -1) {           mx = b[i];           c = i;         }       if (in != c) {         br++;         el.x = 2;         el.y = in;         el.z = c;         v.push_back(el);       }       b[c] = 1000001;       swap(b[in], b[c]);       in = c;     }     cout << br << endl;     int sz = v.size();     for (i = 0; i < sz; i++)       cout << v[i].x <<     << v[i].y <<     << v[i].z << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, d;     cin >> n >> d;     int a[n];     int count = 0;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j == i) continue;         if (abs(a[i] - a[j]) <= d) count++;       }     }     cout << count <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000;   const int B = 33;   const int P = 1e6 + 3;   string s[2];   int ans, Max[2][maxn], dp1[maxn][maxn], dp2[maxn][maxn], dp3[maxn][maxn];   inline void make(const string &x, const string &y, int dp[maxn][maxn]) {     for (int i = 0; i < x.size(); i++)       for (int j = 0; j < y.size(); j++)         if (x[i] == y[j]) dp[i][j] = 1 + (i && j ? dp[i - 1][j - 1] : 0);   }   int main() {     ios_base ::sync_with_stdio(0);     for (int i = 0; i < 2; i++) cin >> s[i];     make(s[0], s[0], dp1);     make(s[0], s[1], dp2);     make(s[1], s[1], dp3);     for (int i = 0; i < s[0].size(); i++)       for (int j = 0; j < s[0].size(); j++)         if (i != j) Max[0][i] = max(Max[0][i], dp1[i][j]);     for (int i = 0; i < s[1].size(); i++)       for (int j = 0; j < s[1].size(); j++)         if (i != j) Max[1][i] = max(Max[1][i], dp3[i][j]);     ans = INT_MAX;     for (int i = 0; i < s[0].size(); i++)       for (int j = 0; j < s[1].size(); j++)         if (dp2[i][j] > Max[0][i] && dp2[i][j] > Max[1][j])           ans = min(ans, max(Max[0][i], Max[1][j]) + 1);     cout << (ans == INT_MAX ? -1 : ans) << endl;   }
#include <bits/stdc++.h>   using namespace std;   double eps = 1e-12;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const int MAXN = 1;   double l, v1, v2;   int n, k;   bool Judge(double m) {     double t = (l - m * v1) / (v2 - v1);     if (t < 0) return false;     double pos = 0, lim = 0;     int sum = n;     while (sum > 0) {       sum -= k;       lim = pos + v2 * t;       pos += 2 * v2 * v1 / (v2 + v1) * t;     }     if (lim <= l) return true;     return false;   }   int main(int argc, char const *argv[]) {     cin >> n >> l >> v1 >> v2 >> k;     double lb = l / v2 - eps, ub = l / v1 + eps;     for (int c = 1; c <= 300; ++c) {       double m = (lb + ub) / 2.0;       if (Judge(m))         ub = m;       else         lb = m;     }     printf( %.12f n , ub);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool Adj[1005][1005];   int Cnt[1005];   void Edge(int A, int B) {     Adj[A][B] = 1;     Adj[B][A] = 1;     Cnt[A]++, Cnt[B]++;   }   int main() {     memset(Adj, 0, sizeof(Adj));     memset(Cnt, 0, sizeof(Cnt));     int N, M;     scanf( %d , &N);     scanf( %d , &M);     for (int i = 0; i < M; i++) {       int A, B;       scanf( %d , &A);       scanf( %d , &B);       Edge(A, B);     }     int Ans = 0;     bool cont = 1;     while (cont) {       cont = 0;       vector<int> mf;       mf.empty();       for (int i = 1; i <= N; i++) {         if (Cnt[i] == 1) {           cont = 1;           Cnt[i] = 0;           for (int j = 1; j <= N; j++)             if (Adj[i][j]) {               Adj[j][i] = 0;               mf.push_back(j);               break;             }         }       }       if (cont) {         Ans++;         for (int i = 0; i < mf.size(); i++) Cnt[mf[i]]--;       }     }     printf( %d , Ans);   }
#include <bits/stdc++.h>   using namespace std;      typedef long long big;   #define bigvec vector<big>   #define pbb pair<big, big>   #define pii pair<int, int>   #define fe first   #define se second   #define maxheap priority_queue   #define uset unordered_set   #define umap unordered_map   #define fr(i, j) for(big i = 0; i < j; i++)   #define revfr(i, j) for(big i = j - 1; i >= 0; i--)   #define speed ios_base::sync_with_stdio(false); cin.tie(NULL)   #define debug(text) if(do_debug) {cout << text << endl;}      const big mod = 1000000007;   const big infinity = 1000000000000000000;   bool do_debug = false;         void rob_santa() {       string wasted;    getline(cin, wasted);       int n_col, n_blocked;    cin >> n_col >> n_blocked;       vector<pii> blocked (n_blocked);       for(int i = 0; i < n_blocked; i++) {        cin >> blocked[i].se >> blocked[i].fe;    }       if(n_blocked == 1) {        cout <<  no  << endl;     return;    }       sort(blocked.begin(), blocked.end());          int i = 0;       for(; i < n_blocked - 1; i++) {        int x = blocked[i].fe;     int y = blocked[i].se;     //cout << x <<  ,   << y << endl;     int next_x = blocked[i + 1].fe;     int next_y = blocked[i + 1].se;        if(blocked[i].fe == blocked[i + 1].fe) {         i++;      continue;     }        if(i + 2 < n_blocked && blocked[i + 1].fe == blocked[i + 2].fe) {         cout <<  no  << endl;      return;     }           if(next_y == y) {         if(next_x - x - 1 == 0) {          i++;       continue;         } else if((next_x - x - 1) % 2 == 0){          i++;       continue;         } else {          cout <<  no  << endl;       return;      }        } else {         if((next_x - x - 1) % 2 == 1) {          i++;       continue;         } else {          cout <<  no  << endl;       return;      }     }    }       //cout << i << endl;       if(i >= n_blocked) {        cout <<  yes  << endl;       } else {        cout <<  no  << endl;    }   }         int main() {        speed;       int q;    cin >> q;       while(q-- > 0) {        rob_santa();    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 2e5 + 10;   long long Inf = 1e18;   const int Log = 20;   const long long Sqrt = 1000000;   const long long Mod = 998244353LL;   long long mul(long long a, long long b) {     a %= Mod;     b %= Mod;     return (a * b) % Mod;   }   long long bin_pow(long long b, long long p) {     long long res = 1;     for (long long j = 1, pw = b; j <= p; j <<= 1, pw = mul(pw, pw))       if (p & j) res = mul(res, pw);     return res;   }   long long a[Maxn];   long long X = 110000;   long long cnt[Maxn];   long long dp[1010][1010];   long long ps[1010][1010];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     a[0] = -10000000;     sort(a + 1, a + n + 1);     long long mx = X / max(1LL, (k - 1));     for (int i = 1; i <= mx; i++) {       for (int ii = 1; ii <= n; ii++)         for (int j = 1; j <= k; j++) dp[ii][j] = 0, ps[ii][j] = 0;       long long p1 = 0;       dp[0][0] = 1;       ps[0][0] = 1;       for (int j = 1; j <= n; j++) ps[j][0] = 1;       for (int j = 1; j <= n; j++) {         while (a[p1] + i <= a[j]) {           p1++;         }         p1--;         for (int K = 1; K <= k; K++) {           dp[j][K] = ps[p1][K - 1];           ps[j][K] = (ps[j - 1][K] + dp[j][K]) % Mod;         }         cnt[i] += dp[j][k];         cnt[i] %= Mod;       }     }     long long ans = 0;     for (int i = 1; i <= mx; i++) {       ans += mul(i, cnt[i] - cnt[i + 1]);       ans %= Mod;     }     ans += Mod;     cout << ans % Mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string c[int(20)];   int r[int(20)], b[int(20)];   int count(int mask, char color) {     int ans = 0;     for (int s = 0, __R = n - 1; s <= __R; s++)       if (!((mask >> s) & 1) && c[s][0] == color) ans++;     return ans;   }   int f(int i, int j, int k) {     if (!i) return 0;     static int dp[1 << 16][2][(1 << 8) + 1];     static bool mark[1 << 16][2][(1 << 8) + 1];     auto& ans = dp[i][j][k];     if (mark[i][j][k]) return ans;     mark[i][j][k] = true;     ;     int R = count(i,  R ), B = count(i,  B );     int rs = j ? k : 0, bs = j ? 0 : k;     ans = 0x3f3f3f3f3f3f3f3fLL;     for (int s = 0, __R = n - 1; s <= __R; s++)       if ((i >> s) & 1) {         int cr = max(0, r[s] - R), cb = max(0, b[s] - B);         int fr = max(0, cr - rs), fb = max(0, cb - bs);         int turns = max(fr, fb);         int rs_ = rs + turns - cr, bs_ = bs + turns - cb;         ans = min(ans, f(i & ~(1 << s), rs_ ? 1 : 0, max(rs_, bs_)) + turns);       }     return ans;   }   int main() {     int B = 0, R = 0;     cin >> n;     for (int i = 0, __R = n - 1; i <= __R; i++) {       cin >> c[i] >> r[i] >> b[i];       B += max(0, b[i] - n);       R += max(0, r[i] - n);       b[i] = min(b[i], n);       r[i] = min(r[i], n);     }     cout << f((1 << n) - 1, B > R ? 1 : 0, min(n * n, max(B, R) - min(B, R))) +                 max(B, R) + n          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   int dx[4] = {0, 1, 0, -1};   int dy[4] = {1, 0, -1, 0};   int main() {     int n;     cin >> n;     string s;     cin >> s;     s +=  . ;     n++;     vector<pair<char, int>> a;     int c = s[0];     int cnt = 1;     for (int i = 1; i < n; i++) {       if (c == s[i]) {         cnt++;       } else {         a.push_back({c, cnt});         c = s[i];         cnt = 1;       }     }     for (int i = 0; i < a.size(); i++) {       if (a[i].first ==  a  || a[i].first ==  e  || a[i].first ==  i  ||           a[i].first ==  o  || a[i].first ==  u  || a[i].first ==  y ) {         if ((a[i].first ==  e  || a[i].first ==  o ) && a[i].second == 2) {           cout << a[i].first << a[i].first;         } else {           cout << a[i].first;         }       } else {         for (int j = 0; j < a[i].second; j++) cout << a[i].first;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, m, y;   int main() {     int i, j, k, flag;     long long ans;     int l1, l2, r1, r2, l, r;     int cnt;     while (scanf( %d%d%d%d , &n, &x, &m, &y) != EOF) {       if (x > y) {         k = x;         x = y;         y = k;       }       ans = 1;       flag = 0;       for (i = 1; i <= n; i++) {         k = ans;         if (i + x == y) {           r1 = y - x + i;           r = min(r1, m);           cnt = 0;           if (r1 <= r) {             cnt++;           }           ans += 2 * (r - cnt) + cnt;           flag = 1;         } else if (i + x > y) {           l1 = i + x - y;           r1 = y - x + i;           if (m < l1) {             ans++;             continue;           }           r = min(r1, m);           cnt = 1;           if (r1 <= r) {             cnt++;           }           ans += (r - l1 + 1 - cnt) * 2 + cnt;           flag = 1;         } else {           l1 = y - x - i;           r1 = y - x + i;           if (m < l1) {             ans++;             continue;           }           cnt = 1;           r = min(r1, m);           if (r1 <= r) {             cnt++;           }           ans += 2 * (r - l1 + 1 - cnt) + cnt;           flag = 1;         }       }       for (i = 1; i <= m; i++) {         if (i + x == y) {           continue;         } else if (i + x > y) {           l1 = i + x - y;           r1 = y - x + i;           if (n < l1) {             ans++;           }         } else {           l1 = y - x - i;           r1 = y - x + i;           if (n < l1) {             ans++;             continue;           }         }       }       if (flag) ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int B = 350;   int a[N];   int b[N];   int tot = 0;   mt19937 rng(4112003);   struct Node {     Node *l, *r;     Node *p;     int key, pri;     int nCh, cnt[B];     Node(int x = 0) : key(x), pri(rng() << 16 | rng()), nCh(1) {       l = r = 0;       for (int i = 0; i < tot; ++i) cnt[i] = 0;       if (b[x] >= 0) cnt[b[x]] = 1;     };   } * p[N];   int Siz(Node *x) {     if (x)       return x->nCh;     else       return 0;   }   void pull(Node *x) {     Node *u = x->l;     Node *v = x->r;     x->nCh = 1;     x->nCh += Siz(u);     x->nCh += Siz(v);     for (int i = 0; i < tot; ++i) {       x->cnt[i] = 0;       if (u) x->cnt[i] += u->cnt[i];       if (v) x->cnt[i] += v->cnt[i];     }     if (b[x->key] >= 0) x->cnt[b[x->key]]++;     if (u) u->p = x;     if (v) v->p = x;   }   Node *join(Node *x, Node *y) {     if (!x) return y;     if (!y) return x;     if (x->pri > y->pri) {       x->r = join(x->r, y);       pull(x);       return x;     } else {       y->l = join(x, y->l);       pull(y);       return y;     }   }   void split(Node *x, Node *&l, Node *&r, int p) {     if (!x) {       l = r = 0;       return;     }     if (p >= Siz(x->l) + 1) {       p -= Siz(x->l) + 1;       split(x->r, x->r, r, p);       pull(l = x);     } else       split(x->l, l, x->l, p), pull(r = x);   }   vector<int> pos[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(NULL));     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       --x;       pos[x].emplace_back(i);       a[i] = x;     }     for (int i = 0; i < n; ++i) {       if (pos[i].size() > B)         b[i] = tot++;       else         b[i] = -1;     }     Node *R = 0;     for (int i = 0; i < n; ++i) R = join(R, p[i] = new Node(a[i]));     int q;     cin >> q;     int lst = 0;     for (int i = 0; i < q; ++i) {       int t;       cin >> t;       int l;       cin >> l;       l = (l + lst - 1) % n;       int r;       cin >> r;       r = (r + lst - 1) % n;       if (l > r) swap(l, r);       if (t == 1) {         Node *x, *y, *z;         split(R, R, x, l);         split(x, x, y, r - l + 1);         split(x, x, z, r - l);         x = join(z, x);         x = join(x, y);         R = join(R, x);       }       if (t == 2) {         int x;         cin >> x;         x = (x + lst - 1) % n;         lst = 0;         if (b[x] >= 0) {           Node *p, *q;           split(R, R, p, l);           split(p, p, q, r - l + 1);           lst = p->cnt[b[x]];           p = join(p, q);           R = join(R, p);         } else {           for (int a : pos[x]) {             Node *T = p[a];             int cur = Siz(T->l);             while (T != R) {               if (T->p->r == T) cur += Siz(T->p->l) + 1;               T = T->p;             }             if (cur < l) continue;             if (cur > r) continue;             lst++;           }         }         cout << lst <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool checkMax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   template <typename T, typename... Args>   inline void checkMax(T &a, const Args... arg) {     checkMax(a, max(arg...));   }   template <class T>   inline bool checkMin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename... Args>   inline void checkMin(T &a, const Args... arg) {     checkMin(a, min(arg...));   }   const int INF = 0x3f3f3f3f;   const long long llINF = 0x3f3f3f3f3f3f3f3f;   const int MAXN = 2e5 + 5;   int n, m, K, cnt, tot;   int a[MAXN];   long long num[MAXN];   struct Rect {     int x100, y100, x2, y2;   } rec[MAXN];   struct Line {     int x, y100, y2, op;   } line[MAXN];   struct SegmentTree {     static const int MAXM = MAXN << 2;     struct Tree {       int l, r;       int cov, sum;     } tree[MAXM];     void update(int k) {       if (tree[k].cov > 0)         tree[k].sum = a[tree[k].r] - a[tree[k].l - 1];       else         tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;     }     void build(int k, int l, int r) {       tree[k].l = l;       tree[k].r = r;       tree[k].cov = tree[k].sum = 0;       if (l == r) return;       int mid = (l + r) >> 1;       build(k << 1, l, mid);       build(k << 1 | 1, mid + 1, r);     }     void modify(int k, int l, int r, int v) {       if (tree[k].l >= l && tree[k].r <= r) {         tree[k].cov += v;         update(k);         return;       }       int mid = (tree[k].l + tree[k].r) >> 1;       if (l <= mid) modify(k << 1, l, r, v);       if (r > mid) modify(k << 1 | 1, l, r, v);       update(k);     }     int query() { return tree[1].sum; }   } T;   long long Solve(int t) {     tot = cnt = 0;     for (int i = 1; i <= m; i++) {       int x100 = (rec[i].x100 - 1) / t + 1, x2 = rec[i].x2 / t;       int y100 = (rec[i].y100 - 1) / t + 1, y2 = rec[i].y2 / t;       if (x100 > x2 || y100 > y2) continue;       a[++cnt] = y100 - 1, a[++cnt] = y2;       line[++tot] = {x100 - 1, y100, y2, 1};       line[++tot] = {x2, y100, y2, -1};     }     if (!tot) return 0;     sort(a + 1, a + 1 + cnt);     cnt = unique(a + 1, a + 1 + cnt) - a - 1;     T.build(1, 1, cnt);     sort(line + 1, line + 1 + tot,          [](const Line &x, const Line &y) { return x.x < y.x; });     long long ans = 0;     for (int i = 1; i <= tot; i++) {       ans += (long long)(line[i].x - line[i - 1].x) * T.query();       int y100 = lower_bound(a + 1, a + 1 + cnt, line[i].y100) - a;       int y2 = lower_bound(a + 1, a + 1 + cnt, line[i].y2) - a;       T.modify(1, y100, y2, line[i].op);     }     return ans;   }   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 1; i <= m; i++) {       int x100, y100, x2, y2;       scanf( %d%d%d%d , &x100, &y100, &x2, &y2);       rec[i] = {x100, y100, x2, y2};     }     int w = 0;     while ((1 << (w + 1)) <= K) w += 1;     for (int i = 0; i <= w; i++) {       num[i] = Solve(1 << i);       if (i && ((num[i] - num[i - 1]) & 1)) {         printf( Hamed );         return 0;       }     }     if (num[w] & 1)       printf( Hamed n );     else       printf( Malek n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, Q;   string s;   struct Info {     int len;     int l_len, r_len;     char left, right;     int ans;     void Output() {       printf( len=%d l_len=%d r_len=%d left=  %c   right=  %c   ans=%d n , len,              l_len, r_len, left, right, ans);     }   };   class TreeNode {    public:     TreeNode *lch, *rch;     int l, r;     bool tag;     Info front, back;     TreeNode(int l, int r) : l(l), r(r) { tag = false; }     void TurnOver() {       tag = !tag;       swap(front, back);     }     void PushDown() {       if (tag) {         tag = false;         lch->TurnOver();         rch->TurnOver();       }     }     void Update() {       front = Merge(lch->front, rch->front);       back = Merge(lch->back, rch->back);     }     void Output() {       printf( l: %d  r: %d  tag: %s n , l, r, tag ?  true  :  false );       printf( front:  );       front.Output();       printf( back:  );       back.Output();     }     static Info Merge(const Info& a, const Info& b) {       Info now;       now.len = a.len + b.len;       now.left = a.left;       now.right = b.right;       now.ans = max(a.ans, b.ans);       if ((a.right ==  <  && b.left ==  < ) ||           (a.right ==  >  && b.left ==  > ) ||           (a.right ==  >  && b.left ==  < )) {         if (a.r_len == a.len) {           now.l_len = a.len + b.l_len;         } else {           now.l_len = a.l_len;         }         if (b.l_len == b.len) {           now.r_len = b.len + a.r_len;         } else {           now.r_len = b.r_len;         }         now.ans = max(now.ans, a.r_len + b.l_len);       } else {         now.l_len = a.l_len;         now.r_len = b.r_len;       }       return now;     }   };   TreeNode* BuildTree(const string& s, int l, int r) {     auto v = new TreeNode(l, r);     if (l == r) {       v->front.len = 1;       v->front.l_len = v->front.r_len = 1;       v->front.left = v->front.right =  < ;       v->front.ans = 1;       v->back.len = 1;       v->back.l_len = v->back.r_len = 1;       v->back.left = v->back.right =  > ;       v->back.ans = 1;       if (s[l] ==  > ) swap(v->front, v->back);       return v;     }     int mid = (l + r) / 2;     v->lch = BuildTree(s, l, mid);     v->rch = BuildTree(s, mid + 1, r);     v->Update();     return v;   }   void Change(TreeNode* v, int ww, int ee, vector<TreeNode*>& visit) {     if (ww <= v->l && v->r <= ee) {       v->TurnOver();       visit.push_back(v);       return;     }     v->PushDown();     int mid = (v->l + v->r) / 2;     if (ww <= mid) Change(v->lch, ww, ee, visit);     if (ee > mid) Change(v->rch, ww, ee, visit);     v->Update();   }   int main() {     cin >> N >> Q;     cin >> s;     auto root = BuildTree(s, 0, N - 1);     vector<TreeNode*> visit;     for (int i = 0; i < Q; i++) {       int a, b;       cin >> a >> b;       a--, b--;       visit.clear();       Change(root, a, b, visit);       Info info = visit[0]->front;       for (int i = 1; i < visit.size(); i++) {         info = TreeNode::Merge(info, visit[i]->front);       }       cout << info.ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int min2 = n, max1 = 1;     while (m--) {       int u, v;       cin >> u >> v;       if (v > u) {         v = u ^ v;         u = v ^ u;         v = u ^ v;       }       min2 = min(u, min2);       max1 = max(v, max1);     }     cout << max(0, min2 - max1);   }