malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[1000010], n, mo = 1000000007;   long long dp[1000010], ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       a[i]--;     }     dp[1] = min(a[1], a[2]);     for (int i = 2; i <= n; i++) {       dp[i] =           (min(a[i], a[i + 1]) + min(a[i - 1], min(a[i], a[i + 1])) * dp[i - 1]) %           mo;       if (a[i + 1] >= a[i])         ans = (ans + dp[i]) % mo;       else         ans = (ans + min(a[i], a[i - 1]) * dp[i - 1] + a[i]) % mo;     }     printf( %I64d n , (ans + a[1]) % mo);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   using bigint = long long int;   using vi = vector<int>;   using vll = vector<long long int>;   int spf[2005];   void smallestFactor() {     for (int i = 1; i <= 2000; i++) spf[i] = i;     for (int i = 2; i * i <= 2000; i++) {       if (spf[i] == i) {         for (int j = i * i; j <= 2000; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     smallestFactor();     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       int arr[N + 1];       for (int i = 0; i < N; i++) {         int x;         cin >> x;         arr[i] = spf[x];       }       map<int, int> m;       int j = 1;       vi ans;       for (int i = 0; i < N; i++) {         if (m.find(arr[i]) != m.end())           ans.push_back(m[arr[i]]);         else {           m[arr[i]] = j;           ans.push_back(j);           j++;         }       }       cout << j - 1 <<   n ;       for (int x : ans) cout << x <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[123456];   map<long long int, bool> mp;   int main() {     int a = 0, b = 0, n, k, l, r, all, kall;     cin >> n >> k >> l >> r >> all >> kall;     int rest = all - kall;     for (int i = 0; i < k; i++) {       arr[i] = kall / k;       if (kall % k != 0) {         arr[i]++;         kall--;       }     }     int rem, man = n - k;     if (k != n) {       for (int i = k; i < n; i++) {         arr[i] = rest / man;         rem = rest % man;         if (rem != 0) {           arr[i]++;           rest--;         }       }     }     random_shuffle(arr, arr + n);     for (int i = 0; i < n - 1; i++) {       printf( %d  , arr[i]);     }     cout << arr[n - 1] << endl;   }
#include <bits/stdc++.h>   int main() {     int j, n, t, i;     int a[100];     scanf( %d , &t);     for (i = 1; i <= t; i++) {       int d = 0, b = 0;       scanf( %d , &n);       for (j = 1; j <= n; j++) {         scanf( %d , &a[j]);         if (d == 0 && a[j] == 1) d = 1;         if (d == 1 && a[j] == 0) b++;       }       for (j = n; j >= 1; j--) {         if (a[j] == 0) b--;         if (a[j] == 1) break;       }       if (d == 0)         printf( 0 n );       else         printf( %d n , b);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void min_self(int& a, int b) { a = min(a, b); }   void max_self(int& a, int b) { a = max(a, b); }   const int NAX = (int)(2e5 + 5);   int v[NAX], visited[NAX];   int component_size;   void visit(int i) {     if (!visited[i]) {       ++component_size;       visited[i] = 1;       visit(v[i]);       visited[i] = component_size;       return;     }     return;   }   int main() {     int t, n;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %d , &v[i]);       for (int i = 1; i <= n; ++i) {         component_size = 0;         visit(i);       }       for (int i = 1; i <= n; ++i) printf( %d  , visited[i]);       printf(  n );       for (int i = 1; i <= n; ++i) visited[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100];   int main() {     long long n, m;     cin >> n >> m;     int L = 0, R = n - 1;     --m;     long long sum = 0;     for (int i = 1; i < n; ++i) {       sum <<= 1;       if (m & 1) sum += 1;       m >>= 1;     }     m = sum;     for (int i = 1; i <= n; m >>= 1, ++i) {       if (m & 1) {         a[R--] = i;       } else {         a[L++] = i;       }     }     cout << a[0];     for (int i = 1; i < n; ++i) {       cout <<     << a[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, s = 1, d = 2, q[105][105];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> a >> b;     for (int i = 1; i <= a; ++i) {       for (int j = 1; j <= b; ++j) {         q[i][j] = 0;         if ((i + j) % 2 == 0) {           if (s <= n) {             q[i][j] = s;             s += 2;           }         }         if ((i + j) % 2 == 1) {           if (d <= n) {             q[i][j] = d;             d += 2;           }         }       }     }     if (s <= n || d <= n) {       cout <<  -1  << endl;       return 0;     }     for (int i = 1; i <= a; ++i) {       for (int j = 1; j <= b; ++j) {         cout << q[i][j] <<    ;       }       cout << endl;     }     return 0;   }
#pragma GCC optimize( Ofast )      #include <iostream>   #include <fstream>   #include <algorithm>   #include <functional>   #include <array>   #include <chrono>   #include <random>   #include <vector>   #include <string>   #include <sstream>   #include <cmath>   #include <cstring>   #include <bitset>   #include <list>   #include <stack>   #include <queue>   #include <set>   #include <map>   #include <cassert>      #define sq(x) ((x) * (x))   #define err(x) cerr <<  [ #x ]    << (x) <<   n ;   #define errp(x) cerr <<  [ #x ]  {  << ((x).first) <<  ,   << ((x).second) <<  } n ;   #define errv(x) {cerr <<  [ #x ]  [ ;for(const auto& ___ : (x)) cerr << ___ <<  ,  ; cerr <<  ] n ;}   #define errvn(x, n) {cerr <<  [ #x ]  [ ;for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] <<  ,  ; cerr <<  ] n ;}   #define errf() cerr <<   n n ;      using namespace std;      using ll = long long;   using ull = unsigned long long;   using ld = long double;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll getrnd(ll l, ll r) {       return uniform_int_distribution<ll>(l, r)(rng);   }      template <typename T1, typename T2> inline bool relax(T1& a, const T2& b) {       return a > b ? a = b, true : false;   }      template <typename T1, typename T2> inline bool strain(T1& a, const T2& b) {       return a < b ? a = b, true : false;   }      // :::::::::::::::::::::::::::::::      void solve() {       int n;       cin >> n;              int x = 0;       vector<int> a(n);       for (int i = 0; i < n; ++i) {           cin >> a[i];           x ^= a[i];       }              int cur = 0;       for (int i = 0; i < n; ++i) {           cur ^= a[i];           if (cur == (x ^ cur)) {               cout <<  YES n ;               return;           }       }              cur = 0;       for (int i = 0; i < n; ++i) {           cur ^= a[i];           int sec = 0;           for (int j = i + 1; j < n - 1; ++j) {               sec ^= a[j];               if (cur == sec && sec == (cur ^ sec ^ x)) {                   cout <<  YES n ;                   return;               }           }       }       cout <<  NO n ;   }      int main() {       ios::sync_with_stdio(0);       cin.tie(nullptr); cout.tie(nullptr);              int t = 1;       cin >> t;       while (t--)           solve();              return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[120];   int n, m;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int s = 0;     int j;     for (j = 1; j < n; j++) {       s += a[j];       if (s > m) break;     }     if (j < n)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long int> a(n), b(n);       map<long long int, bool> mp;       bool ok = false;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];         if (mp[a[i]]) {           ok = true;         }         mp[a[i]] = true;       }       sort(b.rbegin(), b.rend());       if (a != b) {         ok = true;       }       if (ok) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long kek[102][102];   long long dp[15][102][102], a[100000], b[100000], c[100000], a1, b1, c1, n, m,       x, i, j, sc, k;   string s;   int main() {     long long i1, j1;     ios_base ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> c1;     c1++;     for (i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];     for (i = 0; i < n; i++) a[i]++, b[i]++;     for (i = 0; i < c1; i++) {       for (i1 = 1; i1 < 102; i1++)         for (j1 = 1; j1 < 102; j1++) kek[i1][j1] = 0;       for (j = 0; j < n; j++) {         if (c[j] >= c1) c[j] = 0;         kek[a[j]][b[j]] += c[j];         c[j]++;       }       for (i1 = 1; i1 < 102; i1++)         for (j1 = 1; j1 < 102; j1++)           dp[i][i1][j1] = dp[i][i1 - 1][j1] + dp[i][i1][j1 - 1] -                           dp[i][i1 - 1][j1 - 1] + kek[i1][j1];     }     for (i = 0; i < k; i++) {       long long t1, x1, x2, y1, y2;       cin >> t1 >> x1 >> y1 >> x2 >> y2;       x1++, y1++, x2++, y2++;       t1 %= c1;       long long ans = dp[t1][x2][y2] - dp[t1][x1 - 1][y2] - dp[t1][x2][y1 - 1] +                       dp[t1][x1 - 1][y1 - 1];       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   uint64_t log4(uint64_t n) { return log2(n) / 2; }   uint64_t getA(uint64_t triple) {     if (triple == 0) {       return 1;     }     uint64_t doubleBits;     if (triple == 1) {       doubleBits = 1;     } else {       doubleBits = log4(triple * 3 + 1);     }     uint64_t tripleIndex = triple - (pow(4, doubleBits) - 1) / 3;     return pow(4, doubleBits) + tripleIndex;   }   uint64_t getB(uint64_t A) {     uint64_t res = 0;     uint64_t power = 1;     while (A > 0) {       if (A % 4 == 1) {         res += 2 * power;       }       if (A % 4 == 2) {         res += 3 * power;       }       if (A % 4 == 3) {         res += power;       }       power *= 4;       A /= 4;     }     return res;   }   uint64_t getC(uint64_t A) {     uint64_t res = 0;     uint64_t power = 1;     while (A > 0) {       if (A % 4 == 1) {         res += 3 * power;       }       if (A % 4 == 2) {         res += power;       }       if (A % 4 == 3) {         res += 2 * power;       }       power *= 4;       A /= 4;     }     return res;   }   uint64_t solve(uint64_t n) {     uint64_t triple = (n - 1) / 3;     uint64_t A = getA(triple);     if (n % 3 == 0) {       return getC(A);     }     if (n % 3 == 1) {       return A;     }     return getB(A);   }   int main() {     int T;     cin >> T;     for (int t = 0; t < T; t++) {       uint64_t n;       cin >> n;       uint64_t result;       result = solve(n);       cout << result << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int N = 1000010;   template <class T>   class BIT {     T bit[N + 1];     int n;       public:     BIT() {       n = N;       memset(bit, 0, sizeof(bit));     }     T sum(int i) {       T s = 0;       ++i;       while (i > 0) {         s += bit[i];         s %= MOD;         i -= i & -i;       }       return s;     }     void add(int i, T x) {       ++i;       while (i <= n) {         bit[i] += x;         bit[i] %= MOD;         i += i & -i;       }     }   };   BIT<long long> T;   int n, m, k;   vector<pair<int, int>> in[1000010];   vector<pair<int, int>> out[1000010];   set<int> alive;   set<pair<int, int>> itv;   int main() {     scanf( %d %d %d , &n, &m, &k);     alive.insert(1);     itv.insert(make_pair(0, 0));     for (int i = 0; i < (k); i++) {       int a, b, c, d;       scanf( %d %d %d %d , &a, &b, &c, &d);       in[b].push_back(make_pair(a, c));       out[d + 1].push_back(make_pair(a, c));     }     T.add(1, 1);     for (int i = 1; i <= m; ++i)       if (in[i].size() > 0 || out[i].size() > 0) {         sort((in[i]).begin(), (in[i]).end());         sort((out[i]).begin(), (out[i]).end());         vector<pair<int, long long>> vals;         for (int j = 0; j < (in[i].size()); j++) {           pair<int, int> p = in[i][j];           auto it = itv.upper_bound(make_pair(p.second + 1, n));           --it;           if (it->second < p.second + 1) {             long long num = T.sum(p.second) - T.sum(it->second);             num %= MOD;             if (num < 0) num += MOD;             vals.emplace_back(p.second + 1, i > 1 ? num : 0LL);             if (i > 1) alive.insert(p.second + 1);           }         }         for (pair<int, int> p : out[i]) {           itv.erase(p);         }         for (int j = 0; j < (vals.size()); j++) {           T.add(vals[j].first, vals[j].second);         }         for (int j = 0; j < (in[i].size()); j++) {           pair<int, int> p = in[i][j];           itv.insert(p);           auto it = alive.lower_bound(p.first);           while (it != alive.end() && *it <= p.second) {             int pos = *it;             long long k = T.sum(pos) - T.sum(pos - 1);             k %= MOD;             T.add(pos, MOD - k);             alive.erase(it++);           }         }       }     long long ret = T.sum(n);     auto it = itv.end();     --it;     ret = (ret - T.sum(it->second)) % MOD;     if (ret < 0) ret += MOD;     printf( %d n , (int)ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double E = exp(1);   const int N = 1e5 + 5;   int n;   map<long long, long long> m;   int main(void) {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       if (!m.count(a)) m[a] = 0;       m[a]++;     }     long long at = 0;     long long s;     long long f = 0;     for (map<long long, long long>::iterator it = m.begin(); it != m.end();          it++) {       s = it->first;       long long x = it->second;       at += s - f;       at = max(0LL, at - x);       f = s;     }     cout << s - at + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void chkmin(T &a, T b) {     if (a > b) a = b;   }   inline int read() {     int sum = 0, p = 1;     char ch = getchar();     while (!(( 0  <= ch && ch <=  9 ) || ch ==  - )) ch = getchar();     if (ch ==  - ) p = -1, ch = getchar();     while ( 0  <= ch && ch <=  9 ) sum = sum * 10 + ch - 48, ch = getchar();     return sum * p;   }   const int maxn = 5e5 + 20;   struct node {     int v, next;   };   node e[maxn << 1];   int cnt, start[maxn];   inline void addedge(int u, int v) {     e[++cnt] = (node){v, start[u]};     start[u] = cnt;   }   int n;   inline void init() {     n = read();     for (int i = (1), _end_ = (n - 1); i <= _end_; i++) {       int u = read(), v = read();       addedge(u, v);       addedge(v, u);     }   }   int sz[maxn];   void get_sz(int u, int fa) {     sz[u] = 1;     for (int i = start[(u)]; i; i = e[i].next)       if (e[i].v != fa) get_sz(e[i].v, u), sz[u] += sz[e[i].v];   }   long long ans[maxn];   void dfs(int u, int fa) {     for (int i = start[(u)]; i; i = e[i].next) {       int v = e[i].v;       if (v == fa) continue;       ans[v] = ans[u] + (long long)(sz[u] - sz[v]) * sz[v];       dfs(v, u);     }   }   inline void doing() {     get_sz(1, 0);     ans[1] = (long long)n * (n - 1) >> 1;     dfs(1, 0);     int u = 2;     for (int i = (3), _end_ = (n); i <= _end_; i++)       if (ans[u] < ans[i]) {         u = i;       }     get_sz(u, 0);     ans[u] = (long long)n * (n - 1) >> 1;     dfs(u, 0);     long long t = 0;     for (int i = (1), _end_ = (n); i <= _end_; i++) chkmax(t, ans[i]);     printf( %lld n , t);   }   int main() {     init();     doing();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int to, cap, cost, rev, id;   };   int dist[5005], h[5005], prevv[5005], preve[5005];   int V, n, m;   vector<edge> G[5005];   void add_edge(int from, int to, int cap, int cost) {     G[from].push_back((edge){to, cap, cost, (int)G[to].size()});     G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});   }   int min_cost_flow(int s, int t, int f) {     int res = 0;     fill(h + 1, h + V + 1, 0);     while (f > 0) {       priority_queue<pair<int, int>, vector<pair<int, int> >,                      greater<pair<int, int> > >           que;       fill(dist + 1, dist + V + 1, 1000000000);       dist[s] = 0;       que.push(pair<int, int>(0, s));       while (!que.empty()) {         pair<int, int> p = que.top();         que.pop();         int v = p.second;         if (dist[v] < p.first) continue;         for (int i = 0; i < G[v].size(); i++) {           edge &e = G[v][i];           if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {             dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];             prevv[e.to] = v;             preve[e.to] = i;             que.push(pair<int, int>(dist[e.to], e.to));           }         }       }       if (dist[t] == 1000000000) {         return -1;       }       for (int v = 1; v <= V; v++) h[v] += dist[v];       int d = f;       for (int v = t; v != s; v = prevv[v]) {         d = min(d, G[prevv[v]][preve[v]].cap);       }       f -= d;       res += d * h[t];       for (int v = t; v != s; v = prevv[v]) {         edge &e = G[prevv[v]][preve[v]];         e.cap -= d;         G[v][e.rev].cap += d;       }     }     return res;   }   int w[5005][5005];   int ans[5005][5005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       w[u][v] = 1;     }     int s = n + n * (n - 1) / 2 + 1, t = s + 1;     V = t;     int tot = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         tot++;         add_edge(s, tot + n, 1, 0);         if (!w[i][j]) add_edge(tot + n, i, 1, 0);         if (!w[j][i]) add_edge(tot + n, j, 1, 0);       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n - 1; j++) add_edge(i, t, 1, 2 * j - 1);     int res = min_cost_flow(s, t, n * (n - 1) / 2);     tot = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         tot++;         for (auto e : G[n + tot]) {           if (e.cap) continue;           if (e.to == i)             w[j][i] = 1;           else             w[i][j] = 1;         }       }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) printf( %d , w[i][j]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[100010];   int main() {     int n;     cin >> n;     int k = ceil(sqrt(n));     int m = ceil((double)n / (double)k);     int y = m;     int flag = 0, cnt = 0;     for (int i = 1; i <= k; i++) {       int p = 0;       int j = m;       while (j--) {         while (y > n) {           y--;         }         cout << y - p <<    ;         p++;         cnt++;         if (cnt == n) {           flag = 1;           break;         }       }       y += m;       if (flag) break;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1007;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   int n;   int a[maxn], b[maxn];   vector<pair<pair<int, int>, pair<int, int> > > v;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       int atta, attb;       for (int j = i; j <= n; j++) {         if (a[j] == i) atta = j;         if (b[j] == i) attb = j;       }       if (atta == attb && atta == i)         ;       else {         v.push_back(make_pair(make_pair(atta, i), make_pair(i, attb)));         swap(a[atta], a[i]);         swap(b[attb], b[i]);       }     }     cout << ((int)(v).size()) << endl;     for (auto i : v)       cout << i.first.first <<     << i.first.second <<     << i.second.first            <<     << i.second.second << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long l, r;     long long mx = -1e18;     long long ch = 0;   };   vector<node> tree;   void push(long long v) {     if (tree[v].l == tree[v].r) {       tree[v].ch = 0;     } else {       tree[v * 2].ch += tree[v].ch;       tree[v * 2 + 1].ch += tree[v].ch;       tree[v * 2].mx += tree[v].ch;       tree[v * 2 + 1].mx += tree[v].ch;       tree[v].ch = 0;       tree[v].mx = max(tree[v * 2].mx, tree[v * 2 + 1].mx);     }   }   vector<long long> atc(1e6 + 2, 1e17);   vector<long long> def(1e6 + 2, 1e17);   void build(long long v, long long l, long long r) {     tree[v].l = l, tree[v].r = r;     if (l == r) {       tree[v].mx = def[l];       return;     }     long long mid = (r + l) / 2;     build(v * 2, l, mid);     build(v * 2 + 1, mid + 1, r);     tree[v].mx = max(tree[v * 2].mx, tree[v * 2 + 1].mx);   }   long long get_max(long long v, long long l, long long r) {     push(v);     if (tree[v].l > r || tree[v].r < l) return -1e17;     if (tree[v].l >= l && tree[v].r <= r) {       return tree[v].mx;     }     return max(get_max(v * 2, l, r), get_max(v * 2 + 1, l, r));   }   void upd(long long v, long long l, long long r, long long val) {     push(v);     if (tree[v].l > r || tree[v].r < l) return;     if (tree[v].l >= l && tree[v].r <= r) {       tree[v].ch += val;       tree[v].mx += val;       push(v);       return;     }     upd(v * 2, l, r, val);     upd(v * 2 + 1, l, r, val);     tree[v].mx = max(tree[v * 2].mx, tree[v * 2 + 1].mx);   }   signed main() {     ios_base::sync_with_stdio(false);     long long mna = 1e9, mnb = 1e9;     long long n, m, k;     cin >> n >> m >> k;     tree.resize(1e6 * 4);     for (long long i = 0; i < n; ++i) {       long long a, b;       cin >> a >> b;       mna = min(mna, b);       atc[a - 1] = min(atc[a - 1], b);     }     for (long long i = 1e6; i >= 0; --i) atc[i] = min(atc[i + 1], atc[i]);     for (long long i = 0; i < m; ++i) {       long long a, b;       cin >> a >> b;       mnb = min(mnb, b);       def[a - 1] = min(def[a - 1], b);     }     for (long long i = 1e6; i >= 0; --i) def[i] = min(def[i + 1], def[i]);     for (long long i = 0; i < 1e6 + 2; ++i) def[i] *= -1;     vector<pair<long long, pair<long long, long long> > > mnst;     for (long long i = 0; i < k; ++i) {       long long d, a, cen;       cin >> d >> a >> cen;       mnst.push_back({d, {a, cen}});     }     build(1, 0, 1e6 + 1);     sort(mnst.begin(), mnst.end());     long long j = 0;     long long ans = -(mnb + mna);     for (long long i = 0; i < 1e6 + 1; ++i) {       while (j < k && mnst[j].first <= i) {         long long att = mnst[j].second.first, cen = mnst[j].second.second;         upd(1, att, 1e6 + 1, cen);         ++j;       }       long long sum = get_max(1, 1ll, 1e6 + 1) - atc[i];       ans = max(sum, ans);     }     cout << ans;   }