malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct EDGE {     int to, w;     EDGE *las;   } e[100005];   int ne;   EDGE *last[100005];   void link(int u, int v, int w) {     e[ne] = {v, w, last[u]};     last[u] = e + ne++;   }   long long dis[100005], f[100005];   void adjust() {     for (int i = 1; i <= n; ++i)       for (EDGE *ei = last[i]; ei; ei = ei->las) ei->w += dis[i] - dis[ei->to];     for (int i = 1; i <= n; ++i) f[i] += dis[i];   }   void SP0() {     static priority_queue<pair<long long, int>, vector<pair<long long, int> >,                           greater<pair<long long, int> > >         q;     memset(dis, 127, sizeof(long long) * (n + 1));     dis[1] = 0;     q.push(make_pair(0, 1));     while (!q.empty()) {       int x = q.top().second;       long long s = q.top().first;       q.pop();       if (s != dis[x]) continue;       for (EDGE *ei = last[x]; ei; ei = ei->las)         if (s + ei->w < dis[ei->to]) {           dis[ei->to] = s + ei->w;           q.push(make_pair(dis[ei->to], ei->to));         }     }     adjust();   }   void SP1() {     static vector<int> b[100005];     memset(dis, 127, sizeof(long long) * (n + 1));     dis[1] = 0;     b[0].push_back(1);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < b[i].size(); ++j) {         int x = b[i][j];         if (dis[x] < i) continue;         for (EDGE *ei = last[x]; ei; ei = ei->las)           if (i + ei->w < n && i + ei->w < dis[ei->to]) {             dis[ei->to] = i + ei->w;             b[dis[ei->to]].push_back(ei->to);           }       }       b[i].clear();     }     adjust();   }   int main() {     int Q;     scanf( %d%d%d , &n, &m, &Q);     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       link(u, v, w);     }     SP0();     while (Q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int v;         scanf( %d , &v);         printf( %lld n , dis[v] > 100000000000000 ? -1 : f[v]);       } else {         int c;         scanf( %d , &c);         for (int i = 0; i < c; ++i) {           int id;           scanf( %d , &id), --id;           e[id].w++;         }         SP1();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[105];   bool visited[105];   int df[1005];   int ans = 0, k = 0;   void dfs(int i, int parent) {     visited[i] = true;     for (int j = 0; j < adj[i].size(); j++) {       if (!visited[adj[i][j]]) dfs(adj[i][j], i);     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) k++, dfs(i, 0);     }     if (n == m && k == 1)       cout <<  FHTAGN! n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int x;     int y;   };   int main() {     long long n;     cin >> n;     vector<data> info;     long long smallest = 9999999999;     long long largest2 = -1;     for (int i = 0; i < n; i++) {       data temp;       cin >> temp.x >> temp.y;       if (temp.y < smallest) {         smallest = temp.y;       }       if (temp.x > largest2) {         largest2 = temp.x;       }       info.push_back(temp);     }     long long m;     cin >> m;     vector<data> info2;     long long largest = -1;     long long smallest2 = 9999999999;     for (int i = 0; i < m; i++) {       data temp;       cin >> temp.x >> temp.y;       if (temp.x > largest) {         largest = temp.x;       }       if (temp.y < smallest2) {         smallest2 = temp.y;       }       info2.push_back(temp);     }     cout << max(max(largest - smallest, largest2 - smallest2), (long long)0)          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1010;   int n, t, pop = -1, p[2 * MAX], para[2 * MAX], odw[2 * MAX];   inline void dodaj_pare(int a, int b) {     para[a] = b;     para[b] = a;   }   void wczytaj_dane() {     int m;     cin >> n >> m;     for (int i = 0; i < (2 * n); i++) cin >> p[i];     fill(para, para + 2 * n, -1);     while (m--) {       int a, b;       cin >> a >> b;       dodaj_pare(a - 1, b - 1);     }     cin >> t;   }   void wypisz(int x) {     assert(!odw[x]);     odw[x] = true;     cout << (x + 1) <<   n ;     fflush(stdout);   }   int najsilniejszy_sparowany() {     int x = -1;     for (int i = 0; i < (2 * n); i++)       if ((!odw[i]) && para[i] != -1 && (x == -1 || p[x] < p[i])) x = i;     return x;   }   int najsilniejszy() {     int x = -1;     for (int i = 0; i < (2 * n); i++)       if ((!odw[i]) && (x == -1 || p[x] < p[i])) x = i;     assert(x != -1);     return x;   }   int rozwiaz() {     int x = najsilniejszy_sparowany();     if (x != -1) return x;     return najsilniejszy();   }   void moj_ruch() {     if (pop != -1 && para[pop] != -1 && (!odw[para[pop]])) {       wypisz(para[pop]);       return;     }     wypisz(rozwiaz());   }   inline int wczytaj() {     int x;     cin >> x;     if (x == -1) exit(1);     return x - 1;   }   void twoj_ruch() {     int x = wczytaj();     odw[x] = true;     pop = x;   }   void zrob_test() {     wczytaj_dane();     fill(odw, odw + 2 * n, false);     if (t == 1) {       for (int q = 0; q < (n); q++) {         moj_ruch();         twoj_ruch();       }     } else {       for (int q = 0; q < (n); q++) {         twoj_ruch();         moj_ruch();       }     }   }   int main() {     zrob_test();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     static int X[100];     for (int i = 0; i < N; i++) scanf( %d , &X[i]);     vector<int> Ans;     for (int i = 0, Count = 0, First = 0; i < N; i++) {       if (X[i] < 0) Count++;       if (i == N - 1 || (Count == 2 && X[i + 1] < 0)) {         Ans.push_back(i - First + 1);         First = i + 1;         Count = 0;       }     }     int M = Ans.size();     printf( %d n , M);     for (int i = 0; i < M; i++) {       printf( %d , Ans[i]);       putchar((i + 1 == M) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long m) {     if (p == 0) return 1;     long long my = bigmod(b, p / 2, m);     my *= my;     my %= m;     if (p & 1) my *= b, my %= m;     return my;   }   int setb(int n, int pos) { return n = n | (1 << pos); }   int resb(int n, int pos) { return n = n & ~(1 << pos); }   bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }   struct info {     int x, y, idx;     info() {}     info(int _x, int _y, int _idx) {       x = _x;       y = _y;       idx = _idx;     }     bool operator<(const info &p) const {       if (y == p.y)         return x < p.x;       else         return y < p.y;     }   };   info ara[200005];   bool taken[200005];   int n;   int last[2];   bool fuck() {     int i;     last[0] = last[1] = -1;     for (i = 1; i <= n; i++) {       if (last[0] > last[1]) swap(last[0], last[1]);       if (ara[i].x > last[1]) {         last[1] = ara[i].y;         continue;       }       if (ara[i].x > last[0]) {         last[0] = ara[i].y;         continue;       }       return 0;     }     return 1;   }   int main() {     int x, y, i;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       ara[i] = info(x, y, i);     }     sort(ara + 1, ara + n + 1);     bool f = fuck();     if (f)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(string& a) {     for (int i = 1; i < a.size(); i++) {       if (abs(a[i] - a[i - 1]) == 1) return false;     }     return true;   }   string gen(string a) {     if (check(a)) return a;     while (next_permutation(a.begin(), a.end())) {       if (check(a)) return a;     }     return   ;   }   string print(string& t, map<char, int>& cnt) {     string res;     for (auto it : t) {       res += string(cnt[it], it);     }     return res;   }   void solve() {     string in;     cin >> in;     map<char, int> cnt;     for (char i : in) cnt[i]++;     string res;     for (auto it : cnt) {       res += it.first;     }     if (res.size() <= 8) {       string temp = gen(res);       if (temp.empty()) {         cout <<  No answer  << endl;         return;       }       cout << print(temp, cnt) << endl;       return;     }     string t;     for (int i = 0; i < res.size(); i += 2) {       t += res[i];     }     for (int i = 1; i < res.size(); i += 2) {       t += res[i];     }     cout << print(t, cnt) << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int max2[205][6005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fill_n(max2[0], 205 * 6005, -1);     max2[0][0] = 0;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       long long int a;       cin >> a;       int p2 = 0, p5 = 0;       while (a % 2 == 0) {         a /= 2;         p2++;       }       while (a % 5 == 0) {         a /= 5;         p5++;       }       for (int pos = k - 1; pos >= 0; pos--) {         for (int s = p5; s < 6005; s++) {           if (max2[pos][s - p5] != -1) {             max2[pos + 1][s] = max(max2[pos + 1][s], max2[pos][s - p5] + p2);           }         }       }     }     int best = 0;     for (int i = 0; i < 6005; i++) {       best = max(best, min(i, max2[k][i]));     }     cout << best <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   long long n, now[4][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};   inline long long find(long long x, long long y) {     return (x / 4) * (n / 4) + y / 4 + 1;   }   signed main() {     n = read();     for (register long long i = 0; i <= n - 1; i++) {       for (register long long j = 0; j <= n - 1; j++) {         long long at = find(i, j);         cout << (at - 1) * 16 + now[i % 4][j % 4] <<    ;       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const int inf = -INF;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   string s;   int pre[N];   int dp[N][2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       cin >> s;       pre[0] = 0;       for (int i = 0; i <= n; i++) {         dp[i][0] = dp[i][1] = 0;       }       s =     + s;       for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + s[i] -  0 ;       for (int i = 1; i <= n; i++) {         int t = max(0, i - k);         dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + (s[i] ==  1 );         dp[i][1] =             min(pre[i - 1], dp[t][1] + pre[i - 1] - pre[t]) + (s[i] ==  0 );       }       int ans = min(dp[n][0], dp[n][1]);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, rej = 0;     cin >> n;     vector<int> a(n);     for (size_t i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     for (int i = 0; i < n; i++)       if (a[i] == a[0] || a[i] == a[n - 1]) rej++;     cout << n - rej;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long read() {     long long x = 0, f = 1;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f);     for (x = ch ^ 48; isdigit(ch = getchar());          x = (x << 3) + (x << 1) + (ch ^ 48))       ;     return x * f;   }   template <class T>   void Max(T &a, T b) {     a = a > b ? a : b;   }   template <class T>   void Min(T &a, T b) {     a = a < b ? a : b;   }   long long n, l[4], r[4], L[4], R[4], x[N], y[N], z[N];   bool check(long long p, bool type) {     for (long long i = 0; i <= 3; ++i) l[i] = -6e18, r[i] = 6e18;     for (long long i = 1; i <= n; ++i) {       Max(l[0], x[i] + y[i] + z[i] - p);       Min(r[0], x[i] + y[i] + z[i] + p);       Max(l[1], -x[i] + y[i] + z[i] - p);       Min(r[1], -x[i] + y[i] + z[i] + p);       Max(l[2], x[i] - y[i] + z[i] - p);       Min(r[2], x[i] - y[i] + z[i] + p);       Max(l[3], x[i] + y[i] - z[i] - p);       Min(r[3], x[i] + y[i] - z[i] + p);     }     for (long long i = 0; i <= 3; ++i)       if (l[i] > r[i]) return 0;     for (long long A = 0, flag; A <= 1; ++A) {       L[0] = l[0] - 3 * A, R[0] = r[0] - 3 * A;       for (long long i = 1; i <= 3; ++i) L[i] = l[i] - A, R[i] = r[i] - A;       for (long long i = 0; i <= 3; ++i) L[i] = (L[i] + 1) >> 1, R[i] >>= 1;       flag = 1;       for (long long i = 0; i <= 3; ++i)         if (L[i] > R[i]) {           flag = 0;           break;         }       if (flag == 0) continue;       long long L0 = L[1] + L[2] + L[3], R0 = R[1] + R[2] + R[3];       if (R[0] >= L0 && R0 >= L[0]) {         if (type) {           long long a = L[1], b = L[2], c = L[3];           if (a + b + c < L[0]) a += min(R[1] - L[1], L[0] - a - b - c);           if (a + b + c < L[0]) b += min(R[2] - L[2], L[0] - a - b - c);           if (a + b + c < L[0]) c += min(R[3] - L[3], L[0] - a - b - c);           printf( %lld %lld %lld n , b + c + A, a + c + A, a + b + A);         }         return 1;       }     }     return 0;   }   void solve() {     n = read();     for (long long i = 1; i <= n; ++i)       x[i] = read(), y[i] = read(), z[i] = read();     long long l = 0, r = 6e18, mid, ans;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid, 0))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     check(ans, 1);   }   signed main() {     long long T = read();     while (T-- > 0) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int hell = 9223372036854775807;   bool a[40000000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       for (long long int i = 1; i < 4000000; i++) {         a[i] = true;       }       for (long long int i = 2; i * i < 4000000; i++) {         if (a[i])           for (long long int j = i * i; j < 4000000; j = j + i) a[j] = false;       }       long long int n;       cin >> n;       vector<long long int> v;       long long int k = 0;       for (long long int i = 2; i * i <= n; i++) {         if (n % i == 0 && a[i]) {           v.push_back(i);           if (n % (i * i) == 0) v.push_back(i);         }         if (n % i == 0) k++;       }       if (k == 0)         cout << 1 << endl << 0;       else if (v.size() > 1) {         if (v[0] * v[1] < n)           cout <<  1  << endl << v[0] * v[1];         else           cout <<  2 ;       } else         cout <<  2 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[6];     for (int i = 0; i < 6; i++) {       cin >> a[i];     }     cout << (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - (a[0] * a[0]) -                 (a[2] * a[2]) - (a[4] * a[4])          << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5050;   const int inf = 0x37373737;   int L[N], R[N], size[N], tot, n, i, a, b, cnt, j, k;   int d[N], root;   int dp[N][N];   vector<pair<int, int> > vec[N];   vector<int> e[N];   void dfs(int x, int fa) {     int i, j, k;     if (e[x].size() == 1) size[x] = 1;     for (i = 0; i < e[x].size(); i++)       if (e[x][i] != fa) {         dfs(e[x][i], x);         for (j = size[x]; j >= 0; j--)           for (k = 0; k <= size[e[x][i]]; k++)             dp[x][j + k] = min(dp[x][j + k], dp[x][j] + dp[e[x][i]][k]);         size[x] += size[e[x][i]];       }     for (i = 0; i <= size[x]; i++)       dp[x][i] = min(dp[x][i], dp[x][size[x] - i] + 1);   }   int main() {     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       e[a].push_back(b);       e[b].push_back(a);       d[a]++;       d[b]++;     }     if (n == 2) {       printf( 1 );       return 0;     }     for (i = 1; i <= n; i++)       if (d[i] != 1) break;     root = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) dp[i][j] = inf;     dfs(root, 0);     printf( %d n , dp[root][size[root] / 2]);   }
#include <bits/stdc++.h>   int main() {     int i, j, k, l, y, m, n;     char s[101], t[101];     scanf( %d , &y);     for (i = y + 1;; i++) {       n = i;       j = n % 10;       n = n / 10;       k = n % 10;       n = n / 10;       l = n % 10;       n = n / 10;       if (n != l && n != k && n != j && l != k && l != j && k != j) {         printf( %d n , i);         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, t = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) t = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * t;   }   const int N = 3005;   int n, m, T, K, w[N], s[N], U[N], pr[N], su[N];   long long Sum, Ans;   vector<int> G[N];   int C(int n) { return n * (n + 1) / 2; }   void Add(int i, int t) {     Sum += (1ll * (i - U[i]) * (su[i] - i) + C(su[i] - i - 1)) * t;   }   int main() {     n = read(), m = read(), T = read(), K = read();     for (int i = 1; i <= T; i++) {       int x = read(), y = read();       G[y].push_back(x);     }     if (K == 0) return cout << 1ll * n * (n + 1) / 2 * m * (m + 1) / 2, 0;     for (int l = 1; l <= m; l++) {       memset(w, 0, sizeof(w)), Sum = 0;       for (int r = l; r <= m; r++)         for (auto x : G[r]) w[x]++;       for (int i = 1; i <= n; i++)         if (i == 1 || w[i]) {           U[i] = i, pr[i] = i - 1, su[i] = i + 1, s[i] = 0;           while (pr[i] && !w[pr[i]]) pr[i]--;           if (i > 1) pr[i] = max(pr[i], 1);           while (su[i] <= n && !w[su[i]]) su[i]++;           while (U[i] && s[i] + w[U[i]] < K) s[i] += w[U[i]], U[i] = pr[U[i]];           Add(i, +1);         }       for (int r = m; r >= l; r--) {         Ans += Sum;         for (auto x : G[r]) {           int t = x;           w[x]--;           if (x != 1 && !w[x]) {             t = su[x], pr[su[x]] = pr[x];             Add(x, -1), Add(pr[x], -1), su[pr[x]] = su[x], Add(pr[x], +1);           }           for (int j = 1, i = t; j <= K && i <= n; j++, i = su[i]) {             if (U[i] < x) s[i]--;             Add(i, -1);             while (U[i] && s[i] + w[U[i]] < K) s[i] += w[U[i]], U[i] = pr[U[i]];             Add(i, +1);           }         }       }     }     cout << 1ll * n * (n + 1) / 2 * m * (m + 1) / 2 - Ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   struct Node {     int x, y, w;   } a, b, c, g[6005];   int n, x, y, S, m[5][5], f[5][5][5];   long long now1, now2, ans1, ans2, ans3;   inline int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       g[i].x = read();       g[i].y = read();     }     for (int i = 1; i <= n; i++) {       memset(f, 0, sizeof f);       a.x = (g[i].x + 3) % 4 + 1;       a.y = (g[i].y + 3) % 4 + 1;       for (int j = 1; j <= n; j++) {         if (i != j) {           if (abs(g[i].x - g[j].x) * abs(g[i].y - g[j].y)) {             f[(g[j].x + 3) % 4 + 1][(g[j].y + 3) % 4 + 1]              [(gcd(abs(g[i].x - g[j].x), abs(g[i].y - g[j].y)) + 3) % 4 + 1]++;           } else {             f[(g[j].x + 3) % 4 + 1][(g[j].y + 3) % 4 + 1]              [(abs(g[i].x - g[j].x) + abs(g[i].y - g[j].y) + 3) % 4 + 1]++;           }         }       }       for (int j = 0; j < 16; j++) {         b.x = j / 4 + 1;         b.y = j % 4 + 1;         for (b.w = 1; b.w <= 4; b.w++) {           now1 = f[b.x][b.y][b.w];           f[b.x][b.y][b.w]--;           for (int k = 0; k < 16; k++) {             c.x = k / 4 + 1;             c.y = k % 4 + 1;             S = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);             if (S & 1) continue;             S /= 2;             for (c.w = (b.w + 1) % 2 + 1; c.w <= 4; c.w += 2) {               now2 = now1 * f[c.x][c.y][c.w];               a.w = gcd(abs(b.x - c.x) + 4, abs(b.y - c.y) + 4);               if ((S + (a.w + b.w + c.w) / 2) & 1) continue;               if (b.w % 2 + c.w % 2) {                 ans1 += now2;               } else {                 ans2 += now2;               }             }           }           f[b.x][b.y][b.w]++;         }       }     }     writeln(ans1 / 2 + ans2 / 6);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<stack<int>> ids;   vector<int> b;   string answer;   int segtree_size;   template <typename T>   struct segtree {     int segtree_size;     vector<T> segtree;     T identity;     T (*UpdateFn)(T, T);     void InitSegtree(int main_size, T (*UpdateFunction)(T, T), T fun_identity) {       segtree_size = 1;       while (segtree_size < main_size) segtree_size *= 2;       segtree_size *= 2;       segtree.resize(segtree_size);       UpdateFn = UpdateFunction;       this->identity = fun_identity;     }     void UpdateAllParents() {       for (int i = segtree_size / 2 - 1; i > 0; i--)         segtree[i] = UpdateFn(segtree[i * 2], segtree[i * 2 + 1]);     }     void ChangeValue(int index, T value) {       segtree[index + segtree_size / 2] = value;     }     T GetValue(int index) { return segtree[index + segtree_size / 2]; }     void Update(int pos, T value) {       for (segtree[pos += segtree_size / 2] = value; pos > 1; pos /= 2)         segtree[pos / 2] = UpdateFn(segtree[pos], segtree[pos ^ 1]);     }     T Query(int start, int finish) {       T ans = this->identity;       for (start += segtree_size / 2, finish += segtree_size / 2; start < finish;            start /= 2, finish /= 2) {         if (start % 2 == 1) ans = UpdateFn(ans, segtree[start++]);         if (finish % 2 == 0) ans = UpdateFn(ans, segtree[finish--]);       }       return UpdateFn(ans, segtree[start]);     }     void Destroy() { segtree.clear(); }   };   struct segtree<int> tree;   void In() {     cin >> n;     ids.resize(n + 1);     b.resize(n);     tree.InitSegtree(         n + 1, [](int a, int b) -> int { return max(a, b); }, INT_MIN);     int a;     for (int i = 0; i < n; i++) {       cin >> a;       tree.ChangeValue(i, a);     }     tree.UpdateAllParents();     for (int i = 0; i < n; i++) cin >> b[i];   }   void Solve() {     answer =  NO ;     for (int i = 0; i < n; i++) ids[tree.GetValue(i)].push(i);     for (int i = n - 1; i >= 0; i--) {       if (ids[b[i]].empty()) return;       int a_idx = ids[b[i]].top();       ids[b[i]].pop();       if (tree.Query(a_idx + 1, n) > b[i]) return;       tree.Update(a_idx, 0);     }     answer =  YES ;   }   void Out() {     cout << answer << endl;     tree.Destroy();     ids.clear();     b.clear();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       In();       Solve();       Out();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i;     cin >> n;     long long a[n + 1];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long ans = 0, sum = 0;     for (i = 0; i < n; i++) {       if (sum <= a[i]) {         ans++;         sum += a[i];       }     }     cout << ans;     return 0;   }