malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 100005;   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 a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     write(a);     puts(  );   }   int sum, b[N], k, n, len, m, i, ll, rr, qian[N], hou[N];   long long tong[N], a[N], c[N], kind, an[N];   map<long long, int> Ma;   struct data {     int l, r, id, num;   } q[M];   inline void del1(int p) {     tong[a[p]]--;     if (hou[a[p]]) kind -= tong[hou[a[p]]];   }   inline void del2(int p) {     tong[a[p]]--;     if (qian[a[p]]) kind -= tong[qian[a[p]]];   }   inline void ins1(int p) {     if (hou[a[p]]) kind += tong[hou[a[p]]];     tong[a[p]]++;   }   inline void ins2(int p) {     if (qian[a[p]]) kind += tong[qian[a[p]]];     tong[a[p]]++;   }   inline bool cmp(data a, data b) {     return a.id < b.id || (a.id == b.id && a.r < b.r);   }   int main() {     n = read();     k = read();     len = sqrt(n);     for (i = 1; i <= n; i++) b[i] = read();     for (i = 1; i <= n; i++)       c[i] = a[i] = read() * (b[i] == 1 ? 1 : -1) + a[i - 1];     sort(&c[1], &c[n + 1]);     c[0] = c[1] - 1;     for (i = 1; i <= n; i++) {       if (c[i] != c[i - 1]) {         Ma[c[i]] = ++sum;       }     }     for (i = 1; i <= n; i++) {       qian[Ma[c[i]]] = Ma[c[i] - k];       hou[Ma[c[i]]] = Ma[c[i] + k];       a[i] = Ma[a[i]];     }     hou[0] = Ma[k];     m = read();     for (i = 1; i <= m; i++) {       q[i].l = read();       q[i].r = read();       q[i].id = q[i].l / len;       q[i].num = i;     }     sort(&q[1], &q[m + 1], cmp);     ll = q[1].l;     rr = q[1].l - 1;     for (i = 1; i <= m; i++) {       while (ll > q[i].l) ins1(--ll);       while (rr < q[i].r) ins2(++rr);       while (ll < q[i].l) del1(ll++);       while (rr > q[i].r) del2(rr--);       an[q[i].num] = kind + tong[hou[a[ll - 1]]];     }     for (i = 1; i <= m; i++) writeln(an[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long int MOD;   long long int mod(long long int a) {     a %= MOD;     if (a < 0) a += MOD;     return a;   }   struct matrix {     int n, m;     long long int a[6][6];     matrix() {}     matrix(int n_, int m_) {       n = n_, m = m_;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) a[i][j] = 0;     }     matrix operator*(const matrix &t) {       int p = t.m;       matrix res(n, p);       for (int i = 0; i < n; i++) {         for (int j = 0; j < p; j++) {           for (int k = 0; k < m; k++) {             long long int v = mod(1ll * a[i][k] * t.a[k][j]);             res.a[i][j] = mod(res.a[i][j] + v);           }         }       }       return res;     }     void print() {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) printf( %d  , a[i][j]);         printf(  n );       }       printf(  n );     }   };   matrix fpow(matrix a, long long int n) {     matrix ans(6, 6);     for (int i = 0; i < 6; i++) ans.a[i][i] = 1;     while (n > 0) {       if (n & 1) ans = ans * a;       a = a * a;       n >>= 1;     }     return ans;   }   int ar[6][6] = {{2, 1, 1, 0, 1, 0}, {1, 2, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 0},                   {1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}};   int main() {     int x, y, dx, dy;     long long int t;     scanf( %d%d%d%d%d%lld , &MOD, &x, &y, &dx, &dy, &t);     matrix m(6, 6), v(6, 1);     for (int i = 0; i < 6; i++) {       for (int j = 0; j < 6; j++) m.a[i][j] = ar[i][j];     }     v.a[0][0] = x, v.a[1][0] = y, v.a[2][0] = dx, v.a[3][0] = dy, v.a[5][0] = 1;     matrix sol = fpow(m, t - 1) * v;     long long int sum = mod(sol.a[0][0] + sol.a[1][0]);     sum = mod(sum + t - 1);     dx = mod(sol.a[2][0] + sum);     dy = mod(sol.a[3][0] + sum);     x = mod(sol.a[0][0] + dx - 1) + 1;     y = mod(sol.a[1][0] + dy - 1) + 1;     printf( %d %d , x, y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char pal[111];   int nn, L;   int dp[101][55][2];   bool calc[101][55][2];   pair<int, int> pai[101][55][2];   int go(int ini, int n, bool pos) {     int r1;     if (ini == L) {       pai[ini][n][pos] = make_pair(n, pos);       return (n % 2 != 0) * (-0x3f3f3f3f);     }     if (!calc[ini][n][pos]) {       calc[ini][n][pos] = true;       int resp = 0;       if (pal[ini] ==  F ) {         resp = go(ini + 1, n, pos) + pos - (!pos);         if (n)           r1 = go(ini + 1, n - 1, !pos);         else           r1 = -0x3f3f3f3f;         if (resp > r1) {           pai[ini][n][pos] = make_pair(n, pos);         } else {           resp = r1;           pai[ini][n][pos] = make_pair(n - 1, !pos);         }       } else {         resp = go(ini + 1, n, !pos);         if (n)           r1 = go(ini + 1, n - 1, pos) + pos - (!pos);         else           r1 = -0x3f3f3f3f;         if (resp > r1) {           pai[ini][n][pos] = make_pair(n, !pos);         } else {           resp = r1;           pai[ini][n][pos] = make_pair(n - 1, pos);         }       }       dp[ini][n][pos] = resp;     }     return dp[ini][n][pos];   }   void psol(int ind, int n, bool opa) {     if (ind == L) return;     if (n == pai[ind][n][opa].first)       cout << pal[ind];     else if (pal[ind] ==  T )       cout <<  F ;     else       cout <<  T ;     psol(ind + 1, pai[ind][n][opa].first, pai[ind][n][opa].second);   }   int main() {     while (scanf( %s %d , pal, &nn) == 2) {       L = strlen(pal);       memset(calc, false, sizeof(calc));       int r1 = go(0, nn, true);       int r2 = go(0, nn, false);       printf( %d n , max(r2, r1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9 + 9;   const long long inf = 1e18 + 18;   const int max6 = 1e6 + 6;   const int modx = 1e9 + 7;   const int mody = 997;   const int base = 137;   int n, m;   int cnt[max6], a[max6], tmp[max6];   int f[3][1005][1005];   int b[3][1005][1005];   int Pow(int a, int b) {     if (b == 0) return 1;     int half = Pow(a, b / 2);     int res = 1ll * half * half % m;     if (b % 2) res = 1ll * res * a % m;     return res;   }   void update(int id, int j, int u) {     if (id == 1) {       for (; u > 0; u -= u & (-u)) b[id][j][u]++;     } else {       for (; u <= n; u += u & (-u)) b[id][j][u]++;     }   }   int get(int id, int j, int u) {     int res = 0;     if (id == 1) {       for (; u <= n; u += u & (-u)) res = res + b[id][j][u];     } else {       for (; u > 0; u -= u & (-u)) res = res + b[id][j][u];     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) {       int u = a[i] % m;       if (cnt[u]) {         cout << 0;         return 0;       }       cnt[u]++;     }     int res = 1;     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) res = 1ll * res * abs(a[i] - a[j]) % m;     cout << res;   }
#include <bits/stdc++.h>   const int N = 1000005;   int fa[N], h[N], nxt[N], adj[N], a[N], u, v, t, id[N], Id, ans[N], f[N], n, tot,       m;   inline int fd(register int x) { return fa[x] == x ? x : fa[x] = fd(fa[x]); }   inline void add() {     nxt[++t] = h[u], h[u] = t, adj[t] = v, id[t] = Id, nxt[++t] = h[v], h[v] = t,     adj[t] = u, id[t] = Id;   }   inline void mer() {     register int t1 = fd(u), t2 = fd(v);     if (t1 != t2) fa[t1] = t2, add();   }   inline void dfs(register int x) {     for (register int i = h[x], j; i; i = nxt[i])       if ((j = adj[i]) != f[x])         f[j] = x, dfs(j), a[x] += a[j], ans[id[i]] = (i & 1 ? a[j] : -a[j]);   }   inline void fr(int &num) {     num = 0;     char c = getchar();     int p = 1;     while (c <  0  || c >  9 ) c ==  -  ? p = -1, c = getchar() : c = getchar();     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     num *= p;   }   int main() {     fr(n);     for (register int i = 1; i <= n; ++i) fr(a[i]), tot += a[i], fa[i] = i;     if (tot) return puts( Impossible ), 0;     puts( Possible );     fr(m);     for (Id = 1; Id <= m; ++Id) fr(u), fr(v), mer();     dfs(1);     for (register int i = 1; i <= m; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a;   string s;   int main() {     cin >> a >> s;     sort(s.rbegin(), s.rend());     for (int i = 0, j = 0; i < a.size(); i++) {       int ins = s[j] -  0 ;       int ina = a[i] -  0 ;       if (ina < ins && j < s.size()) {         a[i] = s[j++];       }     }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) scanf( %d , A + i);   }   struct lt {     char c;     long long T;     bool operator<(const lt &r) const { return c != r.c ? T < r.T : c < r.c; }     bool operator==(const lt &r) const { return c == r.c && T == r.T; }     bool operator!=(const lt &r) const { return c != r.c || T != r.T; }   } T[(1 << 20)], P[(1 << 20)], I[(1 << 20)];   long long S;   void preKMP(lt *p, int *f) {     *f = -1;     for (int i(1), k; p[i + 1].c; ++i) {       k = f[i - 1];       while (~k && p[k] != p[i - 1]) k = f[k];       f[i] = k + 1;     }   }   int N, M, n, m, a;   int sm(int b) {     if (!b) return 0;     if (T[b - 1].c != P[0].c || T[b - 1].T < P[0].T) return 0;     if (T[b + m - 2].c != P[m - 1].c || T[b + m - 2].T < P[m - 1].T) return 0;     return 1;   }   void KMP(lt *p, lt *t, int m) {     static int f[(1 << 20)];     preKMP(p, f);     for (int i(0), k(0); t[i].c;)       if (!~k)         ++i, k = 0;       else if (t[i] == p[k]) {         ++i;         if (++k == m) S += sm(i - k), k = f[k - 1], --i;       } else         k = f[k];   }   char c;   int main(void) {     scanf( %d%d , &N, &M);     for (int i(0); i < N; i++) {       scanf( %d-%c , &a, &c);       if (i && T[n - 1].c == c)         T[n - 1].T += a;       else         T[n++] = {c, a};     }     T[n].c = 0;     for (int i(0); i < M; i++) {       scanf( %d-%c , &a, &c);       if (i && P[m - 1].c == c)         P[m - 1].T += a;       else         P[m++] = {c, a};     }     P[m].c = 0;     if (m == 1) {       for (int i(0); i < n; i++)         if (T[i].c == P[0].c) S += max(0ll, T[i].T - P[0].T + 1);     } else if (m == 2)       for (int i(0); i < n - 1; i++)         S += T[i].c == P[0].c && T[i].T >= P[0].T && T[i + 1].c == P[1].c &&              T[i + 1].T >= P[1].T;     else if (m == 3)       for (int i(0); i < n - 1; i++)         S += T[i + 1] == P[1] && T[i].c == P[0].c && T[i].T >= P[0].T &&              T[i + 2].c == P[2].c && T[i + 2].T >= P[2].T;     else       KMP(P + 1, T, m - 2);     printf( %lld n , S);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x;     cin >> x;     if (!x)       cout << 0 << endl;     else {       if (x < 0) x = -1 * x;       long long ans = 1, temp = 0;       while (temp < x) {         temp = temp + ans;         ans++;       }       ans--;       long long res = ans * (ans + 1) / 2 - x;       if (!res)         cout << ans << endl;       else if (res % 2) {         if (ans % 2) ans++;         cout << ans + 1 << endl;       } else         cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma warning(disable : 4996)   using namespace std;   const long long INF = 2147483647;   const double PI = acos(-1);   const int mod = 1e9 + 7;   char arr[121212];   int main() {     long long t;     cin >> t;     for (int j = 1; j <= t; j++) {       long long n;       cin >> n;       cin >> (arr + 1);       long long ans = 0;       bool sign = false;       while (sign == false) {         sign = true;         for (int i = 1; i <= n - 1; i++) {           if (arr[i] ==  A  && arr[i + 1] ==  P ) {             arr[i + 1] =  A ;             sign = false;             i = i + 1;           }         }         if (!sign) ans++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, seed = 131, MAXN = 0;   struct Item {     string s;     int x;   };   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> arr(n);       for (int i = 0; i < n; ++i) cin >> arr[i];       queue<Item> q;       q.push({  , 0});       string str;       int curr, uwu;       for (int idx = 0; idx < m; ++idx) {         int qsize = q.size();         for (int _ = 0; _ < qsize; ++_) {           str = q.front().s;           curr = q.front().x;           q.pop();           for (char c =  a ; c <=  z ; ++c) {             uwu = 0;             for (int i = 0; i < n; ++i)               if (arr[i][idx] != c) uwu |= (1 << i);             if ((uwu & curr) == 0) q.push({str + c, uwu | curr});           }         }       }       if (q.empty())         cout << -1 <<   n ;       else         cout << q.front().s <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, a[N], b[N], lst[N], pre[N], suf[N], pr[N], sf[N], cn[N], sta[N], top,       ans;   long long s[N][4], tag[N][4];   inline long long S2(const int x) { return (x + 1ll) * x >> 1; }   inline long long S(const int l, const int r) { return S2(r) - S2(l - 1); }   inline void pd(const int rt, const int l, const int r, const int x,                  const int i) {     s[rt][2] = s[rt][i ^ 1] * x, s[rt][i] = (r - l + 1ll) * x, tag[rt][i] = x,     !i ? s[rt][3] = S(l, r) * x : 0;   }   inline void pd(const int rt, const int l, const int r) {     const int mid = l + r >> 1, ls = rt << 1, rs = ls | 1;     tag[rt][0] ? pd(ls, l, mid, tag[rt][0], 0), pd(rs, mid + 1, r, tag[rt][0], 0),         tag[rt][0] = 0 : 0;     tag[rt][1] ? pd(ls, l, mid, tag[rt][1], 1), pd(rs, mid + 1, r, tag[rt][1], 1),         tag[rt][1] = 0 : 0;   }   inline void upd(const int rt, const int l, const int r, const int u,                   const int v, const int x, const int i) {     if (l >= u && r <= v) return pd(rt, l, r, x, i);     const int mid = l + r >> 1, ls = rt << 1, rs = ls | 1;     pd(rt, l, r);     u <= mid ? upd(ls, l, mid, u, v, x, i), 0 : 0,         v > mid ? upd(rs, mid + 1, r, u, v, x, i), 0 : 0;     s[rt][0] = s[ls][0] + s[rs][0], s[rt][1] = s[ls][1] + s[rs][1],     s[rt][2] = s[ls][2] + s[rs][2], s[rt][3] = s[ls][3] + s[rs][3];   }   inline long long que(const int rt, const int l, const int r, const int u,                        const int v, const int i) {     if (u > v) return 0;     if (l >= u && r <= v) return s[rt][i];     const int mid = l + r >> 1, ls = rt << 1, rs = ls | 1;     pd(rt, l, r);     if (v <= mid) return que(ls, l, mid, u, v, i);     if (u > mid) return que(rs, mid + 1, r, u, v, i);     return que(ls, l, mid, u, mid, i) + que(rs, mid + 1, r, mid + 1, v, i);   }   int main() {     scanf( %d , &n);     register int i, j;     for (i = 1; i <= n; ++i) scanf( %d , &a[i]), b[i] = a[i];     std::sort(b + 1, b + 1 + n), *b = std::unique(b + 1, b + 1 + n) - b - 1;     for (i = 1; i <= n; ++i)       a[i] = std::lower_bound(b + 1, b + 1 + *b, a[i]) - b,       pre[i] = lst[a[i]] + 1, lst[a[i]] = i;     for (i = 1; i <= *b; ++i) lst[i] = n + 1;     for (i = n; i; --i) suf[i] = lst[a[i]] - 1, lst[a[i]] = i;     for (i = n, top = 0; i; --i) {       while (top && pre[i] > pre[sta[top]]) --top;       pr[i] = top ? sta[top] - 1 : n, sta[++top] = i;     }     for (i = n, top = 0; i; --i) {       while (top && suf[i] < suf[sta[top]]) --top;       sf[i] = top ? sta[top] - 1 : n, sta[++top] = i;     }     for (i = n, j = n; i; --i) {       upd(1, 1, n, i, pr[i], pre[i], 0), upd(1, 1, n, i, sf[i], suf[i], 1),           ++cn[a[i]];       while (cn[a[i]] > 1) --cn[a[j]], --j;       ans = (ans + que(1, 1, n, i, j, 3) + que(1, 1, n, i, j, 1) * i -              S(i, j) * i - que(1, 1, n, i, j, 2)) %             1000000007;     }     printf( %d , ans < 0 ? ans + 1000000007 : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 2;   void testCase() {     int n, k, cnt = 0, ans = 1, s = 0;     scanf( %d%d , &n, &k);     vector<int> a(n), fr(101), z(101);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       if (fr[a[i]]++ == 0) ++cnt, ++s;       if (cnt == k + 1) cnt = 2, ans++;     }     if (s >= 2 && k == 1) {       puts( -1 );       return;     }     cout << ans << endl;   }   int main() {     int T = 1;     scanf( %d , &T);     while (T--) {       testCase();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxn = 1e5 + 10;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     int ans = 0;     vector<int> b(n);     for (int k = 0; k < 26; ++k) {       for (int i = 0, mod = (1 << (k + 1)); i < n; ++i) b[i] = a[i] % mod;       sort(b.begin(), b.end());       long long cnt = 0;       int l1 = (1 << k), r1 = (1 << (k + 1)) - 1;       int l2 = (1 << (k + 1)) + (1 << k), r2 = (1 << (k + 2)) - 2;       for (int i = 0; i < n; ++i) {         int l = l1 - b[i], r = r1 - b[i];         cnt += upper_bound(b.begin(), b.begin() + i, r) -                lower_bound(b.begin(), b.begin() + i, l);       }       for (int i = 0; i < n; ++i) {         int l = l2 - b[i], r = r2 - b[i];         cnt += upper_bound(b.begin(), b.begin() + i, r) -                lower_bound(b.begin(), b.begin() + i, l);       }       if (cnt & 1) ans += (1 << k);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, k, j, c;     while (scanf( %d%d , &n, &m) != EOF) {       c = 0;       char a[990][101], x;       for (i = 0; i < n; i++) scanf( %s , a[i]);       for (i = 0; i < n; i++) {         for (k = 0; k < m; k++) {           x = a[i][k];           for (j = 0; j < n; j++) {             if (x >= a[j][k])               continue;             else               break;           }           if (j == n) {             c = c + 1;             break;           }         }       }       printf( %d n , c);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s[100010];   int main() {     long long n, x;     cin >> n >> x;     long long sum = 0, ans = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     sort(s, s + n);     int j = 0;     while (j < n) {       if (x < 1) x = 1;       ans += s[j] * x;       x--;       j++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5;   int n;   pair<long long, long long> a[MAXN + 5];   priority_queue<long long, vector<long long>, greater<long long> > q;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       long long t, w;       cin >> t >> w;       a[i] = make_pair(t, w);     }     sort(a + 2, a + n + 1);     int ans = n, pos = n;     for (;;) {       for (; pos > 1 && a[pos].first > a[1].first; --pos)         q.push(a[pos].second - a[pos].first + 1);       ans = min(ans, (int)q.size() + 1);       if (!q.empty() && a[1].first >= q.top()) {         a[1].first -= q.top();         q.pop();       } else         break;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   const double EPS = 1e-10;   const double PI = acos(-1);   class EDividePoints {    public:     int N;     void rec(std::ostream& out, vector<pair<int, int>>& vec) {       vector<vector<int>> par(2);       for (int i = (0); i < (N); ++i)         par[((vec[i].first + vec[i].second) % 2 + 2) % 2].push_back(i + 1);       if (not par[0].empty() and (int)(par[0]).size() < N) {         out << (int)(par[0]).size() <<   n ;         for (auto u : par[0]) out << u <<    ;         out <<   n ;         return;       }       vector<vector<vector<int>>> ids(2, vector<vector<int>>(2));       for (int i = (0); i < (N); ++i) {         ids[(vec[i].first % 2 + 2) % 2][(vec[i].second % 2 + 2) % 2].push_back(i +                                                                                1);       }       for (int i = (0); i < (2); ++i)         for (int j = (0); j < (2); ++j)           if (not ids[i][j].empty() and (int)(ids[i][j]).size() < N) {             out << (int)(ids[i][j]).size() <<   n ;             for (auto u : ids[i][j]) out << u <<    ;             out <<   n ;             return;           }       for (int i = (0); i < (N); ++i) {         if (vec[i].first % 2) vec[i].first--;         if (vec[i].second % 2) vec[i].second--;         vec[i].first /= 2, vec[i].second /= 2;       }       rec(out, vec);     }     void solve(std::istream& in, std::ostream& out) {       ios_base::sync_with_stdio(false);       in.tie(nullptr), out.tie(nullptr);       in >> N;       vector<pair<int, int>> A(N);       for (int i = (0); i < (N); ++i) in >> A[i].first >> A[i].second;       rec(out, A);     }   };   int main() {     EDividePoints solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     register T sum = 0;     register char cc = getchar();     int sym = 1;     while (cc !=  -  && (cc >  9  || cc <  0 )) cc = getchar();     if (cc ==  - ) sym = -1, cc = getchar();     sum = sum * 10 + cc -  0 ;     cc = getchar();     while (cc >=  0  && cc <=  9 ) sum = sum * 10 + cc -  0 , cc = getchar();     return sym * sum;   }   template <typename T>   inline T read(T &a) {     a = read<T>();     return a;   }   template <typename T, typename... Others>   inline void read(T &a, Others &...b) {     a = read(a);     read(b...);   }   struct Data {     int x, y, p;   } a[200010];   int n, l[200010], r[200010], t[200010];   long long ans1, ans2;   int lowbit(int x) { return x & -x; }   void change(int x, int y) {     for (int i = x; i <= n << 1; i += lowbit(i)) t[i] += y;   }   int query(int x) {     int res = 0;     for (int i = x; i; i -= lowbit(i)) res += t[i];     return res;   }   bool cmp1(const Data &a, const Data &b) { return a.x < b.x; }   bool cmp2(const Data &a, const Data &b) { return a.y > b.y; }   int main() {     read(n);     for (int i = 1; i <= n; i++) {       read(a[i].x, a[i].y);       if (a[i].x > a[i].y) swap(a[i].x, a[i].y);       a[i].p = i;     }     sort(a + 1, a + 1 + n, cmp1);     for (int i = 1; i <= n; i++) {       l[a[i].p] += query(a[i].x) + query(n << 1) - query(a[i].y);       change(a[i].y, 1);     }     memset(t + 1, 0, sizeof(int) * (n << 1));     for (int i = n; i >= 1; i--) {       r[a[i].p] = query(a[i].y);       change(a[i].y, 1);     }     memset(t + 1, 0, sizeof(int) * (n << 1));     sort(a + 1, a + 1 + n, cmp2);     for (int i = 1; i <= n; i++) {       l[a[i].p] += query(n << 1) - query(a[i].y);       change(a[i].x, 1);     }     ans1 = 1ll * n * (n - 1) * (n - 2) / 6;     for (int i = 1; i <= n; i++) {       ans1 -= 1ll * l[i] * r[i];       ans2 += 1ll * (l[i] + r[i]) * (n - l[i] - r[i] - 1);     }     printf( %lld n , ans1 - ans2 / 2);     return 0;   }