malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const double pi = 3.1415926535897932384626433832795;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   using namespace std;   void ifd() {}   void tme() {}   int main() {     ifd();     string s, t, tmp;     getline(cin, s);     vector<string> d;     vector<int> check;     vector<int> r;     stringstream p;     p.clear();     p << s;     while (p >> t) d.push_back(t);     bool f = true;     for (int i = (0); i < (d.size()); ++i) {       tmp = d[i];       while (tmp.size() < 6) tmp =  ?  + tmp;       tmp = tmp.substr(tmp.size() - 6, 6);       if (tmp[2] ==  l  && tmp[3] ==  i  && tmp[4] ==  o  && tmp[5] ==  s ) {         check.push_back(1);         r.push_back(0);       } else if (tmp[2] ==  e  && tmp[3] ==  t  && tmp[4] ==  r  &&                  tmp[5] ==  a ) {         check.push_back(2);         r.push_back(1);       } else if (tmp[3] ==  e  && tmp[4] ==  t  && tmp[5] ==  r ) {         check.push_back(2);         r.push_back(0);       } else if (tmp[1] ==  l  && tmp[2] ==  i  && tmp[3] ==  a  &&                  tmp[4] ==  l  && tmp[5] ==  a ) {         check.push_back(1);         r.push_back(1);       } else if (tmp ==  initis ) {         check.push_back(3);         r.push_back(0);       } else if (tmp ==  inites ) {         check.push_back(3);         r.push_back(1);       } else {         cout <<  NO  << endl;         return 0;       }     }     int te = r[0];     for (int i = (0); i < (r.size()); ++i)       if (r[i] != te) f = false;     if (!f) {       cout <<  NO  << endl;       return 0;     }     if (check.size() == 1) {       cout <<  YES  << endl;       return 0;     }     int n1 = 0, n2 = 0, n3 = 0;     for (int i = (0); i < (check.size()); ++i) {       if (check[i] == 1) n1++;       if (check[i] == 2) n2++;       if (check[i] == 3) n3++;       if (i > 0 && check[i] < check[i - 1]) {         cout <<  NO  << endl;         return 0;       }     }     if (n1 >= 0 && n2 == 1 && n3 >= 0)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     tme();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   int n, m, tin[N], up[N], dw[N];   bool ans[N];   vector<int> edge[N], redge[N];   void topo() {     queue<int> q;     for (int i = 1; i <= n; i++)       if (!tin[i]) q.push(i);     while (q.size()) {       int at = q.front();       q.pop();       for (auto to : edge[at])         if (!--tin[to]) q.push(to);     }   }   void dfs2(int at, int rt, int rev) {     if (!rev) {       up[at] = rt;       for (auto to : edge[at])         if (!up[to]) dfs2(to, rt, rev);     } else {       dw[at] = rt;       for (auto to : redge[at])         if (!dw[to]) dfs2(to, rt, rev);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       edge[x].push_back(y);       redge[y].push_back(x);       tin[y]++;     }     topo();     int ok = 1;     for (int i = 1; i <= n; i++)       if (tin[i]) ok = 0;     if (!ok)       cout << -1 <<   n ;     else {       for (int i = 1; i <= n; i++) {         if (!up[i]) dfs2(i, i, 0);         if (!dw[i]) dfs2(i, i, 1);       }       int cnt = 0;       for (int i = 1; i <= n; i++)         if (up[i] == i and dw[i] == i) ans[i] = 1, cnt++;       cout << cnt <<   n ;       for (int i = 1; i <= n; i++) cout << (ans[i] ?  A  :  E );       cout <<   n ;     }   }
#include <bits/stdc++.h>   const long long inf = 1e18;   using namespace std;   int n;   long long x[100005];   long long lb, ub, mid;   long long sum, S;   long long cnt[3];   int main(void) {     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i];     lb = inf, ub = -inf;     for (int i = 1; i <= n; i++) {       lb = min(lb, x[i]);       ub = max(ub, x[i]);     }     if (ub - lb <= 1) {       cout << n << endl;       for (int i = 1; i <= n; i++) {         cout << x[i];         if (i != n) cout <<    ;       }       cout << endl;       return 0;     }     mid = lb + 1;     for (int i = 1; i <= n; i++) {       sum += x[i];       if (x[i] == lb) cnt[0]++;       if (x[i] == ub) cnt[2]++;       if (x[i] == mid) cnt[1]++;     }     S = sum - mid * n;     bool flag = false;     long long tmp, ans = n, ans_p;     if (S < 0) S *= -1, flag = true;     for (long long p = S; 2 * p <= n + S; p++) {       long long m = p - S;       if (flag)         tmp = min(ans, min(p, cnt[0]) + min(m, cnt[2]) + min(n - p - m, cnt[1]));       else         tmp = min(ans, min(p, cnt[2]) + min(m, cnt[0]) + min(n - p - m, cnt[1]));       if (ans > tmp) {         ans = tmp;         ans_p = p;       }     }     long long ans_m = ans_p - S;     if (flag) {       long long t = ans_m;       ans_m = ans_p;       ans_p = t;     }     cout << ans << endl;     for (int i = 1; i <= ans_p; i++) cout << ub <<    ;     for (int i = 1; i <= ans_m; i++) cout << lb <<    ;     for (int i = 1; i <= n - ans_p - ans_m; i++) cout << mid <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0;     int d = 0;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  A )         a++;       else         d++;     }     cout << (a == d ?  Friendship  : (a > d ?  Anton  :  Danik ));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long N;     cin >> N;     vector<long long> V;     long long Sum = N;     for (long long i = 0; i < N; i++) {       long long X;       cin >> X;       V.push_back(X);     }     long long L = 0;     long long Cnt = 0;     for (long long i = 0; i < N; i++) {       if (V[i] == V[L])         Cnt++;       else {         if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2;         while (V[L] != V[i]) {           L++;           Cnt--;         }         Cnt++;       }     }     if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2;     cout << Sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long s, total, ans, leaves[maxn];   int n;   vector<pair<long long, long long>> tree[maxn];   void dfs(int u, int prev,            priority_queue<pair<long long, pair<long long, long long>>>& pq) {     leaves[u] = (long long)(tree[u].size() == 1);     for (auto e : tree[u]) {       long long v = e.second, w = e.first;       if (v == prev) continue;       dfs(v, u, pq);       leaves[u] += leaves[v];       pq.push({w * leaves[v] - w / 2ll * leaves[v], {w, leaves[v]}});       total += w * leaves[v];     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n >> s;       for (int i = 0; i < n; ++i) {         leaves[i] = 0;         tree[i].clear();       }       for (int i = 0; i < n - 1; ++i) {         long long u, v, w;         cin >> u >> v >> w;         u--, v--;         tree[u].push_back({w, v});         tree[v].push_back({w, u});       }       priority_queue<pair<long long, pair<long long, long long>>> pq;       total = ans = 0;       dfs(0, -1, pq);       while (total > s) {         auto cur = pq.top();         pq.pop();         long long w = cur.second.first, cnt = cur.second.second;         total -= w * cnt;         w /= 2ll;         total += w * cnt;         if (w > 0ll) pq.push({w * cnt - w / 2ll * cnt, {w, cnt}});         ans++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = (int)1e9 + 1;   const int MAX = 1e5 + 1;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, arr[3] = {};     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       arr[x]++;     }     if (!arr[1])       cout << 0 << endl;     else if (arr[1] > arr[2])       cout << arr[2] + (arr[1] - arr[2]) / 3 << endl;     else if (arr[2] >= arr[1])       cout << arr[1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, reg[26] = {1};   char s[100][100];   bool dfs(int dep) {     if (reg[dep] == n) return true;     if (dep >= ans || reg[dep] > n) return false;     ++dep;     for (int i = -1; i < (dep); ++i)       for (int j = 0; j < (dep); ++j) {         int ii = i;         if (ii == -1) ii = 25;         for (int k = 1; k <= 8; k <<= 1) {           reg[dep] = reg[ii] + k * reg[j];           if (dfs(dep)) {             sprintf(s[dep],  lea e%cx, [e%cx + %d*e%cx] , dep +  a , ii +  a , k,                     j +  a );             return true;           }         }       }     return false;   }   int main() {     scanf( %d , &n);     for (ans = 0; !dfs(0); ++ans)       ;     printf( %d n , ans);     for (int i = 1; i < (ans + 1); ++i) printf( %s n , s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string tostring(int x) {     ostringstream o;     o << x;     return o.str();   }   int toint(string s) {     istringstream st(s);     int i;     st >> i;     return i;   }   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int inf = 2e9;   const double eps = 1e-7;   const long long INF = (long long)1e18;   int n;   long long h, k;   long long a[N];   int main() {     cin >> n >> h >> k;     for (int i = 0; i < (n); ++i) cin >> a[i];     int i = 0, j = 0;     long long sum = 0;     long long left = 0;     long long ans = 0;     while (i < n) {       j = i;       sum = left;       while (j < n && sum + a[j] <= h) {         sum += a[j];         j++;       }       ans += sum / k;       left = sum % k;       if (j < n && left + a[j] > h) {         ans++;         left = 0;       }       i = j;     }     if (left) ans++;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   long long gi() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? x : -x;   }   std::mt19937 rnd(time(NULL));   template <class T>   void cxk(T& a, T b) {     a = a > b ? a : b;   }   template <class T>   void cnk(T& a, T b) {     a = a < b ? a : b;   }   int a[100010];   int main() {     int qwq = gi(), n, k;     while (qwq--) {       n = gi(), k = gi();       for (int i = 1; i <= n; ++i) a[i] = gi();       bool s1 = 0, s2 = n == 1;       for (int i = 1; i <= n; ++i) s1 |= a[i] == k;       for (int i = 1; i < n; ++i) s2 |= a[i] >= k && a[i + 1] >= k;       for (int i = 1; i + 1 < n; ++i) s2 |= a[i] >= k && a[i + 2] >= k;       puts((s1 & s2) ?  yes  :  no );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 11;   const long long MOD = 1000000007LL;   int dp[N][N][3];   long long t[N][N];   int cnt[N], c[N];   int n;   string s;   long long ans = 0;   void init() {     for (int i = 0; i <= n; ++i) {       for (int k = 1; k <= 6; ++k) {         if (cnt[i] < k)           t[i][k] = 0;         else {           t[i][k] = 1LL;           for (int j = cnt[i] - k + 1; j <= cnt[i]; ++j) {             t[i][k] = (t[i][k] * (long long)j) % MOD;           }         }       }     }   }   void solve(int i, int k, int st) {     if (i > 6) {       long long p = cnt[st] * 1LL;       for (int j = 0; j <= n; ++j) {         if (c[j] == 0) continue;         if (c[j] > cnt[j]) return;         p = (p * t[j][c[j]]) % MOD;       }       ans = (ans + p) % MOD;       return;     }     for (int j = 0; j < k; ++j) {       c[j]++;       solve(i + 1, k - j, st);       c[j]--;     }   }   int main() {     cin >> s;     n = (int)(s).size();     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= 9; ++i) {       int k;       if (i == 4 || i == 7)         k = 1;       else         k = 0;       dp[1][k][0] += (s[0] -  0  > i) ? 1 : 0;       dp[1][k][1] += (s[0] -  0  == i) ? 1 : 0;       dp[1][k][2] += (s[0] -  0  < i) ? 1 : 0;     }     for (int i = 2; i <= n; ++i) {       for (int k = 0; k <= i; ++k) {         dp[i][k][1] = ((s[i - 1] ==  4  || s[i - 1] ==  7 ) ? dp[i - 1][k - 1][1]                                                             : dp[i - 1][k][1]);         if ((s[i - 1] ==  4  || s[i - 1] ==  7 ) && k == 0) dp[i][k][1] = 0;         for (int j = 0; j < 10; ++j) {           if (j == 4 || j == 7) {             if (k != 0) {               dp[i][k][0] += (dp[i - 1][k - 1][0] +                               (j < (s[i - 1] -  0 ) ? dp[i - 1][k - 1][1] : 0));               dp[i][k][2] += (dp[i - 1][k - 1][2] +                               (j > (s[i - 1] -  0 ) ? dp[i - 1][k - 1][1] : 0));             }           } else {             dp[i][k][0] +=                 (dp[i - 1][k][0] + ((j < s[i - 1] -  0 ) ? dp[i - 1][k][1] : 0));             dp[i][k][2] +=                 (dp[i - 1][k][2] + ((j > s[i - 1] -  0 ) ? dp[i - 1][k][1] : 0));           }         }       }     }     for (int k = 0; k <= n; ++k) {       cnt[k] = 0;       for (int i = 1; i <= n; ++i) {         cnt[k] += dp[i][k][0] + dp[i][k][1];         if (i < n) cnt[k] += dp[i][k][2];       }     }     init();     ans = 0;     for (int i = 1; i <= n; ++i) {       solve(1, i, i);     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int n;   vector<set<int> > g(200000);   vector<int> used(200000);   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> x(m);     vector<int> y(m);     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i];       x[i]--;       y[i]--;       g[x[i]].insert(y[i]);       g[y[i]].insert(x[i]);     }     set<pair<int, int> > s;     vector<int> v(n);     for (int i = 0; i < n; i++) {       s.insert(make_pair(g[i].size(), i));       v[i] = g[i].size();     }     while (s.size()) {       int a = s.begin()->first;       int b = s.begin()->second;       if (a < k) {         s.erase(make_pair(a, b));         v[b] = 0;         for (auto i = g[b].begin(); i != g[b].end(); i++)           if (v[*i] >= k) {             s.erase(make_pair(v[*i], *i));             v[*i]--;             s.insert(make_pair(v[*i], *i));           }       } else         break;     }     vector<int> ans(m);     ans[m - 1] = s.size();     for (int i = m - 1; i >= 1; i--) {       int fl = 0;       if (s.find(make_pair(v[x[i]], x[i])) != s.end()) fl++;       if (s.find(make_pair(v[y[i]], y[i])) != s.end()) fl++;       if (fl != 2)         ans[i - 1] = ans[i];       else {         s.erase(make_pair(v[x[i]], x[i]));         s.erase(make_pair(v[y[i]], y[i]));         v[x[i]]--;         v[y[i]]--;         s.insert(make_pair(v[x[i]], x[i]));         s.insert(make_pair(v[y[i]], y[i]));         g[x[i]].erase(y[i]);         g[y[i]].erase(x[i]);         while (s.size()) {           int a = s.begin()->first;           int b = s.begin()->second;           if (a < k) {             s.erase(make_pair(a, b));             v[b] = 0;             for (auto i = g[b].begin(); i != g[b].end(); i++)               if (v[*i] >= k) {                 s.erase(make_pair(v[*i], *i));                 v[*i]--;                 s.insert(make_pair(v[*i], *i));               }           } else             break;         }         ans[i - 1] = s.size();       }     }     for (int i = 0; i < m; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, val;     cin >> n;     vector<int> vet;     for (int i = 0; i < n; i++) {       cin >> val;       vet.push_back(val);     }     sort(vet.begin(), vet.end());     vector<int> ans;     while (ans.size() < n) {       set<int> opa;       for (int i = 0; i < n; i++) {         if (vet[i] != -1) opa.insert(vet[i]);       }       set<int>::iterator it = opa.begin();       while (it != opa.end()) {         ans.push_back(*it);         it++;       }       for (int i = 0; i < n; i++) {         if (opa.count(vet[i])) {           opa.erase(vet[i]);           vet[i] = -1;         }       }     }     int resp = 0;     for (int i = 0; i < n - 1; i++) {       if (ans[i + 1] > ans[i]) resp++;     }     cout << resp <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Max(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ b; }   int Min(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ a; }   long long GCD(long long a, long long b) { return b != 0 ? GCD(b, a % b) : a; }   long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); }   long long Pow(long long n, long long e) {     if (e == 0) return 1;     if (e == 1)       return n;     else if (e & 1) {       long long t = Pow(n, e / 2);       return n * t * t;     } else {       long long t = Pow(n, e / 2);       return t * t;     }   }   const long long MOD = 1000000007;   long long PowMod(long long n, long long e, long long m) {     if (e == 0) return 1;     if (e == 1)       return n % m;     else if (e & 1) {       long long t = PowMod(n, e / 2, m) % m;       return (((t * t) % m) * (n % m)) % m;     } else {       long long t = PowMod(n, e / 2, m) % m;       return (t * t) % m;     }   }   long long C(long long n, long long k) {     if (n == k || k == 0) return 1;     if (k > n / 2) k = n - k;     long long a = 1;     for (int i = (1), max_ = (k + 1); i < max_; ++i) {       a = (a * (n - i + 1)) % MOD;     }     long long b = 1;     for (int i = (1), max_ = (k + 1); i < max_; ++i) {       b = (b * i) % MOD;     }     a = (a * PowMod(b, MOD - 2, MOD)) % MOD;     return a;   }   long long a[2005], r[2005], inv[2005];   int main() {     int N, K;     scanf( %d %d , &N, &K);     for (int i = 0, max_ = (N); i < max_; ++i) scanf( %d , &a[i]);     if (K == 0) {       for (int i = 0, max_ = (N); i < max_; ++i) r[i] = a[i];     } else {       for (int i = (1), max_ = (2005); i < max_; ++i)         inv[i] = PowMod(i, MOD - 2, MOD);       r[0] = a[0];       for (int i = (1), max_ = (N); i < max_; ++i) {         r[i] = a[i];         long long curr = K;         int n = K;         int k = 1;         int j = i - 1;         while (j >= 0) {           long long tmp = (a[j] * curr) % MOD;           r[i] = (r[i] + tmp) % MOD;           ++n;           ++k;           curr = (curr * n) % MOD;           curr = (curr * inv[k]) % MOD;           --j;         }       }     }     for (int i = 0, max_ = (N); i < max_; ++i) printf( %I64d  , r[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int stack[90], n, k, ans, bag, a[90], tim[90];   int vec[90][90], zoom[90];   bool vis[90];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vec[a[i]][0]++;       vec[a[i]][vec[a[i]][0]] = i;     }     for (int i = 1; i <= n; i++)       tim[i] = vec[i][1], vec[i][vec[i][0] + 1] = n + 1, zoom[i] = 1;     for (int i = 1; i <= n; i++) {       if (!vis[a[i]]) {         if (bag < k)           bag++;         else {           int now, ref = 0;           for (int i = 1; i <= n; i++)             if (vis[i] && ref <= tim[i]) {               now = i;               ref = tim[i];             }           vis[now] = false;         }         ans++;         zoom[a[i]]++;         tim[a[i]] = vec[a[i]][zoom[a[i]]];         vis[a[i]] = true;       } else {         zoom[a[i]]++;         tim[a[i]] = vec[a[i]][zoom[a[i]]];       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     long long r = (n * (n - 1));     r = (r >> 1);     if (r > k) {       for (long long i = 0; i < n; i++) {         cout << 0 <<     << i <<   n ;       }       return 0;     }     cout <<  no solution n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5001;   long long x11[10];   long long y11[10];   long long x22[10];   long long y22[10];   long long deltax[10];   long long deltay[10];   int main() {     bool flag1 = 0;     bool flag2 = 0;     bool flag3 = 0;     for (int i = 0; i < 4; i++) {       scanf( %lld %lld %lld %lld , &x11[i], &y11[i], &x22[i], &y22[i]);       if (x11[i] == x22[i] && y11[i] == y22[i]) flag3 = 1;       deltax[i] = x11[i] - x22[i];       deltay[i] = y11[i] - y22[i];       if (deltax[i] == 0) flag1 = 1;       if (deltay[i] == 0) flag2 = 1;     }     if (!flag1 || !flag2 || flag3) {       printf( NO n );       return 0;     }     for (int i = 0; i < 4; i++) {       if (deltax[i] != 0 && deltay[i] != 0) {         printf( NO n );         return 0;       }     }     vector<long long> vx;     vector<long long> vy;     map<long long, int> mp1;     map<long long, int> mp2;     for (int i = 0; i < 4; i++) {       vx.push_back(x11[i]);       vx.push_back(x22[i]);       vy.push_back(y11[i]);       vy.push_back(y22[i]);       mp1[x11[i]]++;       mp1[x22[i]]++;       mp2[y11[i]]++;       mp2[y22[i]]++;     }     if (mp1.size() != 2 || mp2.size() != 2) {       printf( NO n );     } else {       bool tempflag = 0;       for (auto it : mp1) {         if (it.second != 4) tempflag = 1;       }       for (auto it : mp2) {         if (it.second != 4) tempflag = 1;       }       if (!tempflag)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int main() {     ll n;     cin >> n;     vector<ll> a(n + 1);     ll curr = 0;     vector<ll> iseven(2);     ll ans = 0;     for (int i = 1; i <= n; i++) {       ll x;       cin >> x;       x = __builtin_popcountll(x);       a[i] = x;       curr = (curr + x) % 2;       ans += iseven[curr];       if (i > 1) {         if (curr == 0) ans++;         if (x % 2 == 0) ans--;       }       iseven[curr]++;     }     for (ll i = 1; i <= n; i++) {       ll maxi = a[i];       ll sum = a[i];       for (ll j = i - 1; j >= max(1ll, i - 62); j--) {         sum += a[j];         maxi = max(maxi, a[j]);         if (sum % 2 == 0 && 2 * maxi > sum) {           ans--;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct Seg {     int sa, ea, sb, eb;   } p[200005];   int cmp(Seg &a, Seg &b) {     if (a.ea != b.ea)       return a.ea < b.ea;     else       return a.sa < b.sa;   }   int n, mx[4 * 200005], mi[4 * 200005];   void creat(int l, int r, int k) {     if (l == r) {       mx[k] = p[l].sb, mi[k] = p[l].eb;       return;     }     int mid = (l + r) / 2;     creat(l, mid, 2 * k);     creat(mid + 1, r, 2 * k + 1);     mx[k] = max(mx[2 * k], mx[2 * k + 1]);     mi[k] = min(mi[2 * k], mi[2 * k + 1]);   }   int querymin(int l, int r, int al, int ar, int k) {     if (l == al && r == ar) return mi[k];     int mid = (l + r) / 2;     if (ar <= mid)       return querymin(l, mid, al, ar, 2 * k);     else if (al > mid)       return querymin(mid + 1, r, al, ar, 2 * k + 1);     else       return min(querymin(l, mid, al, mid, 2 * k),                  querymin(mid + 1, r, mid + 1, ar, 2 * k + 1));   }   int querymax(int l, int r, int al, int ar, int k) {     if (l == al && r == ar) return mx[k];     int mid = (l + r) / 2;     if (ar <= mid)       return querymax(l, mid, al, ar, 2 * k);     else if (al > mid)       return querymax(mid + 1, r, al, ar, 2 * k + 1);     else       return max(querymax(l, mid, al, mid, 2 * k),                  querymax(mid + 1, r, mid + 1, ar, 2 * k + 1));   }   int ea[200005];   int solve() {     std::sort(p + 1, p + 1 + n, cmp);     creat(1, n, 1);     for (int i = 1; i <= n; i++) ea[i] = p[i].ea;     for (int i = 1; i <= n; i++) {       if (i == 1) continue;       int left = p[i].sa;       int ans = lower_bound(ea + 1, ea + i, left) - ea;       if (ans > i - 1) continue;       int maxL = querymax(1, n, ans, i - 1, 1);       int minR = querymin(1, n, ans, i - 1, 1);       if (minR < p[i].sb || maxL > p[i].eb) return 0;     }     return 1;   }   int main() {     int i, j, k, sig = 1;     scanf( %d , &n);     for (i = 1; i <= n; i++)       scanf( %d %d %d %d , &p[i].sa, &p[i].ea, &p[i].sb, &p[i].eb);     sig &= solve();     for (i = 1; i <= n; i++) swap(p[i].sa, p[i].sb), swap(p[i].ea, p[i].eb);     sig &= solve();     if (sig)       printf( YES n );     else       printf( NO n );   }