malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, mn = 1e12;     cin >> a >> b;     int n;     cin >> n;     while (n--) {       double x, y, v, dis;       cin >> x >> y >> v;       dis = sqrt((a - x) * (a - x) + (b - y) * (b - y));       dis /= v;       mn = min(mn, dis);     }     cout << fixed << setprecision(7) << mn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int to, id;   };   vector<node> E[10005];   vector<int> Ans;   int dep[10005], fa[10005][15], Id[10005], S1[10005], S0[10005], Stk[10005], cnt,       n1, n, m;   bool mk[10005], Mk[10005];   void dfs(int x, int f) {     mk[x] = 1;     dep[x] = dep[f] + 1, fa[x][0] = f;     for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) {       int y = E[x][i].to;       if (!mk[y]) {         Stk[++cnt] = y;         Id[y] = E[x][i].id;         dfs(y, x);       }     }   }   int LCA(int x, int y) {     if (dep[x] > dep[y]) swap(x, y);     int d = dep[y] - dep[x];     for (int i = (0), i_ = (13); i <= i_; i++)       if (d & (1 << i)) y = fa[y][i];     for (int i = (13), i_ = (0); i >= i_; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return x == y ? x : fa[x][0];   }   void Init() {     for (int j = (1), j_ = (13); j <= j_; j++)       for (int i = (1), i_ = (cnt); i <= i_; i++)         fa[Stk[i]][j] = fa[fa[Stk[i]][j - 1]][j - 1];   }   void Dfs(int x) {     for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) {       int y = E[x][i].to;       if (Id[y] == E[x][i].id)         Dfs(y);       else if (dep[y] < dep[x] && y != fa[x][0]) {         if ((dep[x] & 1) == (dep[y] & 1)) {           n1++;           S1[x]++, S1[y]++, S1[LCA(x, y)] -= 2;           Mk[E[x][i].id] = 1;         } else           S0[x]++, S0[y]++, S0[LCA(x, y)] -= 2;       }     }   }   void DFS(int x) {     for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) {       int y = E[x][i].to;       if (Id[y] == E[x][i].id) {         DFS(y);         S0[x] += S0[y], S1[x] += S1[y];       }     }   }   void Deal() {     if (!n1) {       for (int i = (1), i_ = (m); i <= i_; i++) Ans.push_back(i);       return;     }     for (int i = (1), i_ = (n); i <= i_; i++)       if (S1[i] == n1 && !S0[i]) Ans.push_back(Id[i]);     if (n1 == 1)       for (int i = (1), i_ = (m); i <= i_; i++)         if (Mk[i]) Ans.push_back(i);   }   int main() {     int a, b;     scanf( %d%d , &n, &m);     for (int i = (1), i_ = (m); i <= i_; i++) {       scanf( %d%d , &a, &b);       E[a].push_back((node){b, i});       E[b].push_back((node){a, i});     }     for (int i = (1), i_ = (n); i <= i_; i++)       if (!mk[i]) cnt = 0, dfs(i, 0), Init(), Dfs(i), DFS(i);     Deal();     printf( %d n , Ans.size());     sort(Ans.begin(), Ans.end());     for (int i = (0), i_ = (Ans.size() - 1); i <= i_; i++) printf( %d  , Ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int N = 1e6 + 5;   int f[N];   int a[] = {1, 2};   int na = 2;   int main() {     int cnt;     cin >> cnt;     if (cnt == 1) {       cout <<  1 1 n1 ;       return 0;     }     int x = 1;     for (int i = 2; i < N; i++) {       if (i % 2 == 0) x++;       if (x == cnt) {         cout << i <<   2 n1 2 ;         return 0;       }     }     return 0;   }
#include <cstdio>   #include <cmath>   long long T, n;   bool flag;   int main()   {    scanf( %d , &T);    for(int t = 1; t <= T; t ++)    {     scanf( %lld , &n);     flag = false;     for(long long i = 2; i <= n; i *= 2)     {      if(n == i)       {       printf( NO n );       flag = true;       break;      }     }     if(!flag) printf( YES n );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3020;   long long a[maxn], b[maxn];   long long dp1[maxn][maxn];   int n;   bool cmp(int x, int y) { return x > y; }   int main() {     while (cin >> n) {       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         a[i] -= i;         b[i] = a[i];       }       sort(b, b + n);       memset(dp1, 0, sizeof(dp1));       for (int i = 0; i < n; i++) {         long long minx = dp1[i][0];         for (int j = 0; j < n; j++) {           minx = min(minx, dp1[i][j]);           dp1[i + 1][j] = minx + abs(a[i] - b[j]);         }       }       long long min_up = dp1[n][0];       for (int i = 1; i < n; i++) {         min_up = min(min_up, dp1[n][i]);       }       cout << min_up << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2,unroll-loops )   using namespace std;   const int inf = 1000000010;   const long long INF = 1000000000000001000LL;   const int mod = 1000000007;   const int MAXN = 100200, SQ = 320, NSQ = MAXN / SQ + 1;   int n, m, w, u, v, x, y, t, a, b, maxb;   int A[MAXN], B[MAXN], ans[MAXN], lazy[NSQ];   pair<long long, long long> X[MAXN];   vector<int> vec[MAXN];   struct CHT {     pair<long long, int> cht[SQ];     int L, R;     inline long long Inter(pair<long long, long long> x,                            pair<long long, long long> y) {       if (x.first == y.first) return (x <= y ? -INF : INF);       return (x.second - y.second) / (y.first - x.first) +              ((x.second - y.second) % (y.first - x.first) > 0);     }     inline void Add(int a) {       while (R && Inter(X[cht[R - 1].second], X[a]) <= cht[R - 1].first) R--;       if (!R)         cht[R++] = {-INF, a};       else         cht[R] = {Inter(X[cht[R - 1].second], X[a]), a}, R++;     }     inline pair<long long, long long> Get(long long x) {       while (L + 1 < R && cht[L + 1].first <= x) L++;       int i = cht[L].second;       return {X[i].first * x + X[i].second, i};     }   } cht[NSQ];   void Build(int id) {     int tl = id * SQ, tr = min(MAXN, tl + SQ);     cht[id].L = cht[id].R = 0;     for (int i = tl; i < tr; i++) {       X[i].second += lazy[id] * X[i].first;       cht[id].Add(i);     }     lazy[id] = 0;   }   void Add(int l, int r, int val) {     int idl = -1, idr = -1;     while (l < r && l % SQ) idl = l / SQ, X[l].second += val * l, l++;     while (l < r && r % SQ) idr = r / SQ, r--, X[r].second += val * r;     while (l < r) lazy[l / SQ] += val, l += SQ;     if (idl != -1) Build(idl);     if (idr != -1) Build(idr);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> w;     for (int i = 1; i <= n; i++) {       cin >> A[i] >> B[i];       vec[B[i]].push_back(i);       maxb = max(maxb, B[i]);     }     for (int i = 0; i < MAXN; i++) X[i].first = i;     for (int i = 0; i * SQ < MAXN; i++) Build(i);     int ted = n;     for (int i = 0; i <= maxb + 1; i++) {       pair<long long, long long> p = {-inf, -1};       for (int j = 0; j * SQ + SQ <= MAXN; j++) p = max(p, cht[j].Get(lazy[j]));       cout << p.first + 1ll * ted * i * w <<     << p.second <<   n ;       for (int j : vec[i]) Add(0, A[j] + 1, +1), ted--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long mod = 1000000007;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void init() {}   void solve() {     long long x, y, n, i, j;     cin >> n;     vector<pair<long long, long long> > adj(n - 1);     vector<long long> deg(n + 1, 0);     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       deg[x]++;       deg[y]++;       adj[i] = {x, y};     }     vector<long long> edge;     for (i = 0; i < n + 1; i++) {       if (deg[i] == 1) {         edge.push_back(i);       }     }     if ((int)edge.size() == 2) {       for (i = 0; i < n - 1; i++) {         cout << i << endl;       }     } else {       long long ep = 0, elp = 3;       for (i = 0; i < n - 1; i++) {         bool flag = false;         for (j = 0; j < 3; j++) {           if (edge[j] == adj[i].first or edge[j] == adj[i].second) {             flag = true;           }         }         if (flag) {           cout << ep << endl;           ep++;         } else {           cout << elp << endl;           elp++;         }       }     }   }   int main() {     init();     auto start = high_resolution_clock::now();     int T = 1;     while (T--) {       solve();     }     auto stop = high_resolution_clock::now();     auto duration = duration_cast<milliseconds>(stop - start);   }
#include <bits/stdc++.h>   #define int long long   #define f(i,a,n) for (int i = a; i < n; ++i)   #define f1(i,a,n) for(int i=n-1;i>=a;i--)   #define ff first   #define ss second   #define pb push_back   #define mp make_pair   #define all(x) x.begin(), x.end()   #define sortall(x) sort(all(x))   #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL);   #define w1 solve();   #define mod (int)(1e9 + 7)   #define prq priority_queue   #define gcd __gcd   #define sz(x) (int)x.size()   #define w(t) int t; cin>>t; while (t--) { solve(); }   #define N 1000001      using namespace std;      void __print(int x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}      #ifdef Avash_Local_Machine   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif      typedef vector<int> vi;   typedef pair<int, int> pii;   typedef vector<pii> vpi;   typedef vector<string> vs;   typedef vector<char> vc;      const int INF = (int)(1e17);   const double PI = 3.141592653589793;      int dx[4] = { -1, 0, 1, 0};   int dy[4] = {0, 1, 0, -1};   string path =  URDL ;         void solve()   {    int q;    cin >> q;    char c; int n , id = 1;    set<pii> set1, set2;    //set1 for price,id    //set2 for id,price    while (q--)    {     cin >> c;     if (c ==  1 )     {      cin >> n;      set1.insert(mp(n, id));      set2.insert(mp(id, n));      ++id;     }     if (c ==  2 )     {      auto it = *set2.begin();      cout << it.ff <<   n ;      auto ind = set1.lower_bound(mp(it.ss, it.ff));      set1.erase(ind);      set2.erase(set2.begin());     }     if (c ==  3 )     {      auto it = *set1.rbegin();      // debug(it);      auto ind = set1.lower_bound(mp(it.ff, -INF));      // debug(ind);      cout << (*ind).ss <<   n ;      auto ind1 = set2.lower_bound(mp((*ind).ss, (*ind).ff));      // debug(*ind1);      set2.erase(ind1);      set1.erase(ind);      // debug(set2);     }    }   }      int32_t main()   {       fastio    w1    // w(t)    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tt;   int n, m;   int main() {     scanf( %d , &tt);     while (tt--) {       scanf( %d %d , &n, &m);       long long z = (n - m), g = m + 1;       long long k = z / g;       long long ans =           (n * 1ll * (n + 1) / 2) - (k * (k + 1) / 2) * g - (k + 1) * (z % g);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, F[500007], wartosc[500007], Fat[500007];   bool valid_number[500007], valid_edges[300007], query_node[500007];   int Find(int a) { return (a == Fat[a] ? a : Fat[a] = Find(Fat[a])); }   inline void Union(int a, int b) {     a = Find(a);     b = Find(b);     F[a] = F[b] = ++n;     Fat[a] = Fat[b] = F[n] = Fat[n] = n;   }   vector<int> G[500007];   int pre[500007], pos[500007], order[500007], nr;   bool visited[500007];   void DFS(int v) {     visited[v] = 1;     pre[v] = ++nr;     order[nr] = v;     for (auto i : G[v])       if (!visited[i]) DFS(i);     pos[v] = nr;   }   int tree[1 << 20], M = 1;   inline void zrob_drzewa() {     for (int i = 1; i <= n; i++)       if (F[i] != i) {         G[i].push_back(F[i]);         G[F[i]].push_back(i);       }     for (int i = 1; i <= n; i++)       if (F[i] == i) DFS(i);     while (M < n) M *= 2;     for (int i = 1; i <= n; i++) tree[i + M - 1] = wartosc[order[i]];     for (int i = M - 1; i > 0; i--) tree[i] = max(tree[i * 2], tree[i * 2 + 1]);   }   void remove_invalid(int v) {     if (valid_number[tree[v]]) return;     tree[v] = 0;     if (v >= M) return;     remove_invalid(v * 2);     remove_invalid(v * 2 + 1);     tree[v] = max(tree[v * 2], tree[v * 2 + 1]);   }   int maks(int a, int b, int v = 1, int p = 1, int k = M) {     if (p > b || k < a) return 0;     if (p >= a && k <= b) {       remove_invalid(v);       return tree[v];     }     return max(maks(a, b, v * 2, p, (p + k) / 2),                maks(a, b, v * 2 + 1, (p + k) / 2 + 1, k));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int m, q;     cin >> n >> m >> q;     n = n;     for (int i = 1, a; i <= n; i++) {       cin >> wartosc[i];       valid_number[wartosc[i]] = true;       F[i] = i;       Fat[i] = i;     }     vector<pair<int, int>> edges(m + 1);     for (int i = 1; i <= m; i++) {       cin >> edges[i].first >> edges[i].second;       valid_edges[i] = true;     }     vector<pair<int, int>> queries(q);     for (int i = 0; i < q; i++) {       cin >> queries[i].first >> queries[i].second;       if (queries[i].first == 2) valid_edges[queries[i].second] = false;     }     for (int i = 1; i <= m; i++)       if (valid_edges[i]) Union(edges[i].first, edges[i].second);     int Res[q];     for (int i = q - 1; i >= 0; i--) {       if (queries[i].first == 1) {         int v = queries[i].second;         v = Find(v);         Res[i] = v;       } else {         int j = queries[i].second;         int a = edges[j].first, b = edges[j].second;         Union(a, b);       }     }     zrob_drzewa();     for (int i = 0; i < q; i++) {       if (queries[i].first == 2) continue;       int v = Res[i];       int res = maks(pre[v], pos[v]);       cout << res <<   n ;       valid_number[res] = false;       valid_number[0] = true;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[200005];   int main() {     int t, k, i, j, n, m, x, y, q, c;     cin >> n >> k;     if ((n - 1) % k >= 2) {       printf( %d n , 2 * ((n - 1) / k) + 2);     } else if ((n - 1) % k == 1) {       printf( %d n , 2 * ((n - 1) / k) + 1);     } else {       printf( %d n , 2 * ((n - 1) / k));     }     for (i = 0; i < k; i++) a[i] = 1;     for (i = 2; i <= n; i++) {       j = (i - 2) % k;       printf( %d %d n , i, a[j]);       a[j] = i;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, Y[50001];   set<int> pos[50001];   set<int> used;   priority_queue<int> q;   int next(int x) {     int temp = x;     while (x != 0) {       if (used.count(x) == 0) return x;       x /= 2;     }     return temp;   }   int main() {     cin >> N;     for (int i = 0; i < N; i++) {       cin >> Y[i];       used.insert(Y[i]);       q.push(Y[i]);     }     for (;;) {       int num = next(q.top());       if (q.top() == num) break;       used.erase(num);       used.insert(num);       q.pop();       q.push(num);     }     while (!q.empty()) {       cout << q.top() <<    ;       q.pop();     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 3;   int a[maxn], b[maxn], c[maxn], sum;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     int ans = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       ans += a[i];       cnt -= a[i];       b[i] = max(max(cnt, ans), b[i - 1] + a[i]);     }     ans = 0, cnt = 0;     for (int i = n; i > 0; i--) {       ans += a[i];       cnt -= a[i];       c[i] = max(max(cnt, ans), c[i + 1] + a[i]);     }     int mx = 0;     for (int i = 0; i <= n; i++) mx = max(c[i + 1] + b[i], mx);     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, l, r, c, pl, pr, cl, cr;     cin >> a >> b >> l >> r;     c = a + b;     cl = --l / c;     cr = --r / c;     pl = l % c;     pr = r % c;     if (cl == cr) {       if (pl < a && pr < a) {         cout << pr - pl + 1 << endl;       } else if (pl < a && pr >= a) {         cout << a - pl << endl;       } else {         cout << 1 << endl;       }     } else if (a <= b) {       if (cl < cr - 1) {         cout << a + 1 << endl;       } else {         if (pr >= a) {           cout << a + 1 << endl;         } else {           if (pl >= a) {             cout << pr + 1 + 1 << endl;           } else {             int left = a - pl;             int right = pr + 1;             if (left + right > a) {               cout << a + (right == a) << endl;             } else {               cout << left + right + (right == a) << endl;             }           }         }       }     } else {       int d = a - b;       if (cl == cr - 1) {         if (pr >= a && pl >= a) {           cout << a + 1 << endl;         } else if (pr < a && pl >= a) {           cout << pr + 1 + 1 << endl;         } else if (pr >= a && pl < a) {           cout << min((a + a - pl), a + a - b) << endl;         } else if (pr < a && pl < a) {           if (pl > b) {             cout << pr + 1 + a - pl << endl;           } else {             cout << pr + 1 + a - b << endl;           }         }       } else if (cl == cr - 2) {         if (pr >= a && pl >= a) {           cout << a + a - b << endl;         } else if (pr >= a && pl < a) {           cout << a + a - b << endl;         } else if (pr < a && pl < a) {           cout << min((a + pr + 1 + a - pl + 1), a + a - b) << endl;         } else {           cout << a + max(1, d + min(0, pr - a + 1 + max(0, a - pl)));         }       } else {         cout << a + d << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long bbuy(long long* c, long long l, int n);   int main() {     long long n, l;     cin >> n >> l;     long long c[n];     for (int i = 0; i < n; ++i) {       cin >> c[i];     }     long long bp = c[0];     for (int i = 0; i < n; ++i) {       bp *= 2;       bp = min(bp, c[i]);       if (bp != c[i]) c[i] = -1;     }     long long bcost = 0;     bcost += bbuy(c, l, n);     cout << bcost;     return 0;   }   long long bbuy(long long* c, long long l, int n) {     int i = int(log2(l));     long long gcost = 0;     long long cost = 0, buy;     long long prev = l;     while (i >= n || c[i] == -1) i--;     buy = l / pow(2, i);     l -= buy * pow(2, i);     cost = buy * c[i];     if (l > 0) cost += bbuy(c, l, n);     for (int j = i + 1; j < n; ++j) {       l = prev;       if (c[j] == -1) continue;       buy = (l / pow(2, j)) + 1;       if (cost > buy * c[j]) {         cost = buy * c[j];         l -= buy * pow(2, j);       }     }     gcost += cost;     return gcost;   }
#include <bits/stdc++.h>   using namespace std;   namespace std {   template <>   struct hash<pair<int, int>> {     size_t operator()(const pair<int, int> &x) const {       long long P = 38923, Q = 109797901;       return (size_t)((x.first * P + x.second) % Q);     }   };   };  // namespace std   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   void print(T t) {     cout << t << endl;   }   template <typename T, typename... Args>   void print(T t, Args... args) {     cout << t <<    ;     print(args...);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long x, y, z;     cin >> x >> y >> z;     if (x > y + z)       print( + );     else if (y > x + z)       print( - );     else if (x == y && z == 0)       print( 0 );     else       print( ? );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T qmin(const T a, const T b) {     return a < b ? a : b;   }   template <typename T>   inline T qmax(const T a, const T b) {     return a > b ? a : b;   }   template <typename T>   inline void getmin(T &a, const T b) {     if (a > b) a = b;   }   template <typename T>   inline void getmax(T &a, const T b) {     if (a < b) a = b;   }   inline void fileio(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const int inf = 1e9;   const long long linf = 1e17 + 7;   const int N = 2e5 + 7;   struct seg {     int h, l, r;     seg() {}     seg(int _h, int _l, int _r) : h(_h), l(_l), r(_r) {}     bool operator<(const seg &b) const { return h < b.h; }   } a[N];   struct node {     int l, r, v;     seg s;     node() {}     node(int _l, int _r, int _v, seg _s) : l(_l), r(_r), v(_v), s(_s) {}     bool operator<(const node &b) const { return l < b.l; }   };   inline int overlap(int l1, int r1, int l2, int r2) {     return qmax(0, qmin(r1, r2) - qmax(l1, l2));   }   inline bool canget(const seg &a, set<node>::iterator it) {     set<node>::iterator ul = it, ur = it;     --ul;     ++ur;     seg pre = ul->s, nxt = ur->s, cur = it->s;     if (pre.h < a.h && pre.h > cur.h && overlap(a.l, a.r, pre.l, pre.r) &&         overlap(pre.l, pre.r, cur.l, cur.r))       return false;     if (nxt.h < a.h && nxt.h > cur.h && overlap(a.l, a.r, nxt.l, nxt.r) &&         overlap(nxt.l, nxt.r, cur.l, cur.r))       return false;     return true;   }   set<node> s;   int n, t;   int main() {     scanf( %d%d , &n, &t);     for (int i = 1; i <= n; ++i) scanf( %d%d%d , &a[i].h, &a[i].l, &a[i].r);     a[++n] = seg(t, -inf, inf);     sort(a + 1, a + n + 1);     node bot(-inf, inf, inf << 1, seg(0, -inf, inf));     node left(-inf - 1, -inf, 0, seg());     node right(inf, inf + 1, 0, seg());     s.insert(bot);     s.insert(left);     s.insert(right);     for (int i = 1; i <= n; ++i) {       set<node>::iterator ul = s.upper_bound(node(a[i].l, a[i].r, 0, seg())), ur;       int ans = 0;       for (--ul; ul->r <= a[i].l; ++ul)         ;       for (ur = ul; ur->l < a[i].r; ++ur) {         if (!canget(a[i], ur)) continue;         getmax(ans, qmin(overlap(a[i].l, a[i].r, ur->l, ur->r), ur->v));       }       --ur;       int l = ul->l, r = ur->r, v1 = ul->v, v2 = ur->v;       seg s1 = ul->s, s2 = ur->s;       ++ur;       s.erase(ul, ur);       s.insert(node(a[i].l, a[i].r, ans, a[i]));       if (l < a[i].l) s.insert(node(l, a[i].l, v1, s1));       if (r > a[i].r) s.insert(node(a[i].r, r, v2, s2));     }     set<node>::iterator ite = s.begin();     ++ite;     printf( %d n , ite->v);     return 0;   }