malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   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...);   }   long long dp[31][31][51];   long long calc(long long x, long long y, long long k) {     if (dp[x][y][k] || !k || x * y == k) return dp[x][y][k];     long long ans = 1e9;     for (long long i = 1; 2 * i <= x; i++) {       for (long long j = 0; j <= k; j++) {         ans = min(ans, y * y + calc(i, y, j) + calc(x - i, y, k - j));       }     }     for (long long i = 1; 2 * i <= y; i++) {       for (long long j = 0; j <= k; j++) {         ans = min(ans, x * x + calc(x, i, j) + calc(x, y - i, k - j));       }     }     return dp[x][y][k] = ans;   }   void solve() {     long long t;     cin >> t;     while (t--) {       long long n, m, k;       cin >> n >> m >> k;       cout << calc(n, m, k) <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tests;     tests = 1;     for (long long i = 0; i < tests; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 45;   const int inf = 0x3f3f3f3f;   void ttf() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int z[N], p[N];   void solve() {     string s;     cin >> s;     int n = (int)s.length();     z[0] = n;     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     for (int i = 0; i < n; ++i) {       p[z[i]]++;     }     for (int i = n - 1; i >= 1; --i) {       p[i] += p[i + 1];     }     vector<pair<int, int> > v;     for (int i = 0; i < n; ++i) {       if (z[i] + i == n) {         v.push_back(make_pair(z[i], p[z[i]]));       }     }     cout << ((int)(v.size())) << endl;     reverse(v.begin(), v.end());     for (int i = 0; i < ((int)(v.size())); ++i)       cout << v[i].first <<     << v[i].second << endl;   }   int main() {     ttf();     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, i, t;     cin >> n;     long int a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[0] == 0) a[0] = a[1];     if (n >= 2) {       if (a[n - 2] - a[0] < a[n - 1] - a[1])         t = a[n - 2] - a[0];       else         t = a[n - 1] - a[1];       cout << t;     } else       cout << 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int MOD = 1e9 + 7;   vector<int> v;   long long f[301][N];   int a[N];   int main() {     for (int i = 1; i <= 300; i++) {       f[i][0] = 1;       for (int j = 1; j < N; j++) {         f[i][j] = f[i][j - 1] * i % MOD;       }     }     int n, x, sum;     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %d , &x);         a[x]++;       }       for (int i = 100000; i > 1; i--) a[i - 1] += a[i];       long long ans = 1;       for (int i = 2; i <= 100000; i++) {         if (a[i] == 0) continue;         v.clear();         for (int j = 1; j * j <= i; j++) {           if (i % j == 0) {             v.push_back(j);             if (j != i / j) v.push_back(i / j);           }         }         sort(v.begin(), v.end());         int len = v.size();         long long ret1 = 1, ret2 = 1;         sum = 0;         for (int j = len - 1; j >= 0; j--) {           if (a[v[j]] <= sum) continue;           ret1 = ret1 * f[j + 1][a[v[j]] - sum] % MOD;           sum = a[v[j]];         }         sum = 0;         for (int j = len - 2; j >= 0; j--) {           if (a[v[j]] <= sum) continue;           ret2 = ret2 * f[j + 1][a[v[j]] - sum] % MOD;           sum = a[v[j]];         }         ans = ((ans + ret1 - ret2) % MOD + MOD) % MOD;       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, cnt[101];   int main() {     int N, M, cnt[101] = {0};     scanf( %d%d , &N, &M);     for (int i = 0; i < N; i++) {       int t;       scanf( %d , &t);       int now = M - t;       int ans = i;       for (int j = 1; j <= 100; j++) {         int get = min(now / j, cnt[j]);         now -= get * j;         ans -= get;       }       cnt[t]++;       printf( %d%c , ans, i == N - 1 ? 10 : 32);     }   }
#include <bits/stdc++.h>   using namespace std;   int arr[10001];   int main() {     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       vector<int> ans1, ans2;       for (int i = 0; i < 2 * n; i++) cin >> arr[i];       vector<pair<int, int> > vp;       for (int i = 0; i < 2 * n; i++) {         if (arr[i] % 2 == 0)           ans2.push_back(i + 1);         else           ans1.push_back(i + 1);       }       for (int i = 1; i < ans2.size(); i += 2)         vp.push_back({ans2[i], ans2[i - 1]});       for (int i = 1; i < ans1.size(); i += 2)         vp.push_back({ans1[i], ans1[i - 1]});       for (int i = 0; i < n - 1; i++)         cout << vp[i].first <<     << vp[i].second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, d;       cin >> n >> d;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       long long int ans = a[0];       for (long long int i = 1; i < n; i++) {         if (d > 0) ans += min((d / i), a[i]);         d -= a[i] * i;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ll t;     cin >> t;     for (ll i = 0; i < t; i++) {       ll n;       cin >> n;       vector<ll> in(n);       vector<ll> count(n + 1);       for (ll i = 0; i < n; i++) {         cin >> in[i];         count[in[i]]++;       }       vector<ll> ops;       while (true) {         ll mex = 0;         while (count[mex] > 0) mex++;         if (mex < n) {           ops.push_back(mex);           count[in[mex]]--;           in[mex] = mex;           count[mex]++;         } else {           ll j = 0;           while (in[j] == j) j++;           if (j >= n) break;           ops.push_back(j);           count[in[j]]--;           in[j] = mex;           count[mex]++;         }       }       cout << (ll)(ops).size() << endl;       for (ll x : ops) {         cout << x + 1 <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   inline void amax(T &x, U y) {     if (x < y) x = y;   }   struct UnionFind {     vector<int> data;     UnionFind(int size_) : data(size_, -1) {}     bool unionSet(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (data[y] < data[x]) swap(x, y);         data[x] += data[y];         data[y] = x;       }       return x != y;     }     bool findSet(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }   };   struct Edge {     int x, y;     int w;     Edge() {}     Edge(int x_, int y_, int w_) : x(x_), y(y_), w(w_) {}   };   bool operator<(const Edge &a, const Edge &b) { return a.w < b.w; }   vector<vector<int> > g;   vector<long long> dist;   vector<vector<int> > d;   void dfs(int i, int p, long long t) {     dist[i] = t;     for (typeof((g[i]).begin()) j = ((g[i]).begin()); j != (g[i]).end(); ++j)       if (*j != p) dfs(*j, i, t + d[i][*j]);   }   int main() {     int n;     scanf( %d , &n);     d.assign(n, vector<int>(n));     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(n); ++(j)) scanf( %d , &d[i][j]);     bool ok = true;     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(i); ++(j)) {         ok &= d[i][j] == d[j][i];         ok &= d[i][j] > 0;       }     for (int(i) = 0; (i) < (int)(n); ++(i)) ok &= d[i][i] == 0;     if (!ok) {       puts( NO );       return 0;     }     vector<Edge> edges;     edges.reserve(n * (n - 1) / 2);     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(i); ++(j))         edges.push_back(Edge(i, j, d[i][j]));     sort(edges.begin(), edges.end());     UnionFind uf(n);     g.assign(n, vector<int>());     for (int i = 0; i < (int)edges.size(); i++) {       int x = edges[i].x, y = edges[i].y;       if (uf.unionSet(x, y)) {         g[x].push_back(y);         g[y].push_back(x);       }     }     dist.resize(n);     for (int(i) = 0; (i) < (int)(n); ++(i)) {       dfs(i, -1, 0);       for (int(j) = 0; (j) < (int)(n); ++(j)) ok &= dist[j] == d[i][j];     }     puts(ok ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct point {     double x, y;   } a, b, t, q[100010];   struct wxz {     double d1, d2;   } f[100010];   double ans, delta1[100010], delta2[100010], delta;   double dist(point u, point v) {     return sqrt((u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y));   }   bool vis[100010];   int main() {     scanf( %lf%lf%lf%lf%lf%lf , &a.x, &a.y, &b.x, &b.y, &t.x, &t.y);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &q[i].x, &q[i].y);     for (int i = 1; i <= n; i++) ans += 2 * dist(t, q[i]);     for (int i = 1; i <= n; i++) f[i].d1 = dist(a, q[i]) - dist(t, q[i]);     for (int i = 1; i <= n; i++) f[i].d2 = dist(b, q[i]) - dist(t, q[i]);     double delta = 1e18, dd1 = 1e18, dd2 = 1e18;     for (int i = 1; i <= n; i++) {       delta = min(delta, min(dd1 + f[i].d2, dd2 + f[i].d1));       dd1 = min(dd1, f[i].d1), dd2 = min(dd2, f[i].d2);     }     printf( %lf n , ans + min(delta, min(dd1, dd2)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vis[105][105];   int main() {     int n;     scanf( %d , &n);     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int x;       scanf( %d , &x);       vis[1][x] = true;     }     for (int i = 2; i <= n; i++) {       int m;       scanf( %d , &m);       for (int j = 1; j <= m; j++) {         int x;         scanf( %d , &x);         if (vis[i - 1][x]) vis[i][x] = true;       }     }     for (int i = 1; i <= 100; i++)       if (vis[n][i]) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, n, k;   double jumlah, x[101], y[101];   int main() {     scanf( %d %d , &n, &k);     for (i = 1; i <= n; ++i) {       scanf( %lf %lf , &x[i], &y[i]);     }     for (i = 1; i < n; ++i) {       jumlah += sqrt(((x[i] - x[i + 1]) * (x[i] - x[i + 1])) +                      ((y[i] - y[i + 1]) * (y[i] - y[i + 1])));     }     jumlah = ((jumlah / 50) * k);     printf( %.9lf n , jumlah);   }
#include <bits/stdc++.h>   using namespace std;   long long a[20], b[20];   long long ans = 0;   void print() {     for (int i = 0; i < 14; i++) cout << b[i] <<    ;     cout << endl;   }   int main() {     for (int i = 0; i < 14; i++) cin >> a[i];     for (int i = 0; i < 14; i++) {       if (a[i]) {         for (int j = 0; j < 14; j++) b[j] = a[j];         long long score = 0;         long long tmp = b[i];         b[i] = 0;         for (int j = 0; j < 14; j++) b[j] += tmp / 14;         for (int j = 1; j <= tmp % 14; j++) b[(i + j) % 14]++;         for (int j = 0; j < 14; j++)           if (b[j] % 2 == 0) score += b[j];         ans = max(ans, score);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e6 + 7;   long long t, n, k, temp;   int main(int argc, char* argv[]) {     cin >> t;     while (t--) {       cin >> n >> k;       long long cnt = 0;       while (n > 0) {         if (n % k != 0) {           cnt += n % k;           n -= n % k;         } else {           cnt++;           n /= k;         }       }       cout << cnt << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     long long n, x;     int q, i;     scanf( %lld %i , &n, &q);     while (q--) {       scanf( %lld , &x);       while (!(x & 1)) {         x += (n - (x >> 1));       }       printf( %lld n , (x + 1) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111111], b[111111], n, m, k;   int main() {     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= m; i++) scanf( %d , &b[i]);       sort(a + 1, a + 1 + n);       sort(b + 1, b + 1 + m);       bool yes = 0;       for (int i = 0; i <= max(n, m); i++) {         if (n - i < 1 || m - i < 1) break;         if (a[n - i] > b[m - i]) {           yes = 1;           printf( YES n );           break;         }       }       if (yes) continue;       if (n > m)         printf( YES n );       else         printf( NO n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.size() % 2)         cout <<  NO n ;       else {         string word1 =   , word2 =   ;         for (int i = 0; i < s.size() / 2; i++) word1 += s[i];         for (int i = s.size() / 2; i < s.size(); i++) word2 += s[i];         if (word1 == word2)           cout <<  YES n ;         else           cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 100, MAX = 1e6 + 5;   const long long INF = 1e18 + 5;   int main() {     string s;     cin >> s;     long long n = (s[1] -  0 ) + (s[3] -  0 ) * 10 + (s[4] -  0 ) * 100 +                   (s[2] -  0 ) * 1000 + (s[0] -  0 ) * 10000;     long long Ans = 1;     for (int i = 0; i < 5; i++) {       Ans = (Ans * n) % 100000;     }     string x = to_string(Ans);     reverse(x.begin(), x.end());     while (x.size() != 5) {       x +=  0 ;     }     reverse(x.begin(), x.end());     cout << x << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e10;   set<long long> s;   void bt(long long x) {     if (x >= M) return;     s.insert(x);     bt(x * 10 + 4);     bt(x * 10 + 7);   }   int main() {     bt(0);     int l, r;     cin >> l >> r;     long long c = 0;     for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {       if (*it >= l) {         if (r <= *it) {           c += (r - l + 1) * *it;           break;         } else           c += (*it - l + 1) * *it;         l = *it + 1;       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   int n;   pair<int, int> a[MAX];   struct par {     int a, b;     par(int a, int b) : a(a), b(b) {}     bool operator<(const par &p) const { return b < p.b; }   };   multiset<par> s;   multiset<int> sizes;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + n + 1);     int best = 1, opt = a[n].first + 1;     for (int i = 1; i <= n; i++) {       if (!sizes.empty()) {         auto x = sizes.begin();         auto y = sizes.rbegin();         int v = a[i - 1].first + 1;         if (*x == *y) {           if ((int)sizes.size() > best) {             best = sizes.size();             opt = v;           } else if ((int)sizes.size() == best && a[i].first < opt)             opt = v;         }       }       auto u = s.upper_bound(par(0, a[i].second));       par intervalo = par(a[i].second, a[i].second);       vector<par> del;       if (u != s.end()) {         auto o = *u;         if (o.a - 1 == a[i].second) {           del.push_back(o);           intervalo.b = o.b;         }       }       if (u != s.begin()) {         u--;         auto o = *u;         if (o.b + 1 == a[i].second) {           del.push_back(o);           intervalo.a = o.a;         }       }       for (auto o : del) {         s.erase(s.find(o));         int sz = o.b - o.a + 1;         sizes.erase(sizes.find(sz));       }       s.insert(intervalo);       sizes.insert(intervalo.b - intervalo.a + 1);     }     printf( %d n , opt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     long long idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  ,  ;     dbs(str.substr(idx + 1), s...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, i, j, k, n, m, q;     long long x, y, l, r;     string s;     long long len;     cin >> len;     cin >> s;     vector<long long> pos(len + 7, -1);     long long cur = 1;     for (i = 0; i < len; i++) {       if (s[i] ==  8 ) {         pos[cur++] = i;       }     }     long long moves = (len - 11) / 2;     cur = min(cur - 1, moves);     dbs( cur, pos[cur], pos[cur + 1] , cur, pos[cur], pos[cur + 1]);     if (pos[cur + 1] == -1 || pos[cur + 1] - (cur) > moves) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   namespace chtholly {   char buf[1 << 23], *p1 = buf, *p2 = buf;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar()) f ^= c ==  - ;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return f ? x : -x;   }   template <typename mitsuha>   inline bool read(mitsuha &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c) && ~c; c = getchar()) f ^= c ==  - ;     if (!~c) return 0;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return x = f ? x : -x, 1;   }   template <typename mitsuha>   inline int write(mitsuha x) {     if (!x) return 0 & putchar(48);     if (x < 0) putchar( - ), x = -x;     int bit[20], i, p = 0;     for (; x; x /= 10) bit[++p] = x % 10;     for (i = p; i; --i) putchar(bit[i] + 48);     return 0;   }   inline char fuhao() {     char c = getchar();     for (; isspace(c); c = getchar())       ;     return c;   }   }  // namespace chtholly   using namespace chtholly;   using namespace std;   const int yuzu = 2e5;   typedef int fuko[yuzu | 10];   vector<int> lj[yuzu | 10];   fuko a;   int zxy;   int dfs(int u, int lxy, int fa = 0) {     if (a[u] % lxy) return 0;     for (; a[u] % lxy == 0; a[u] /= lxy)       ;     vector<int> v;     for (int i : lj[u])       if (i ^ fa) v.push_back(dfs(i, lxy, u));     sort(v.begin(), v.end(), greater<int>());     int llx = 1;     if (v.size()) llx += v[0];     if (v.size() > 1) zxy = max(zxy, llx + v[1]);     return zxy = max(zxy, llx), llx;   }   int main() {     int i, j, n = read(), u, v;     for (i = 1; i <= n; ++i) a[i] = read();     for (i = 1; i < n; ++i) {       read(u), read(v);       lj[u].push_back(v);       lj[v].push_back(u);     }     for (i = 1; i <= n; ++i) {       for (j = 2; j * j <= a[i]; ++j)         if (a[i] % j == 0) dfs(i, j);       if (a[i] > 1) dfs(i, a[i]);     }     write(zxy), puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (c <= d) {         if (a <= b * c)           cout << a << endl;         else {           cout << -1 << endl;         }       } else {         long long len = c % d ? c / d + 1 : c / d;         long long ans = 0;         long long x = (b * d + 2 * a) / 2 / b / d;         x = min(x, len);         ans = a * x - x * (x - 1) / 2 * b * d;         x++;         x = min(x, len);         ans = max(ans, a * x - x * (x - 1) / 2 * b * d);         if (a > b * c)           cout << -1 << endl;         else {           ans = max(ans, a * len - (len - 1) * len / 2 * d * b);           cout << ans << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int flag = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int num, num1;       string str;       cin >> str >> num >> num1;       if (num >= 2400 && (num1 - num) > 0) {         flag = 1;         break;       }     }     if (flag)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int limite = 100005;   pair<int, int> maximo[limite];   void inserta(int pos, int val) {     pair<int, int> valor(val, pos);     for (; pos < limite; pos += pos & -pos) maximo[pos] = max(maximo[pos], valor);   }   int computamaximo(int pos) {     pair<int, int> maxi(0, 0);     for (; pos > 0; pos -= pos & -pos) maxi = max(maxi, maximo[pos]);     return maxi.second;   }   int n;   int a[limite];   long long int sr[limite];   long long int sol = 0;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     for (int i = n - 1; i >= 1; i--) {       if (a[i] == n)         sr[i] = n - i;       else {         int jmin = computamaximo(a[i]);         sr[i] = a[i] - i + sr[jmin] - (a[i] - jmin) + (n - a[i]);       }       sol += sr[i];       inserta(i, a[i]);     }     cout << sol << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long inf = 1e9;   const int MAXM = 1048800;   const int MAXN = 1e7 + 1;   bool visit[MAXM];   int a[MAXM];   int k;   vector<int> v;   int main() {     int n, i, j, k;     cin >> n;     n *= 2;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans = INT_MAX, cnt = 0;     sort(a, a + n);     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         v.clear();         cnt = 0;         for (int k = 0; k < n; k++) {           if (k == i or k == j) continue;           v.push_back(a[k]);         }         int nn = v.size();         for (int k = 0; k < nn; k += 2) {           cnt += v[k + 1] - v[k];         }         ans = min(ans, cnt);       }     }     cout << ans << endl;     return 0;   }