func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int infi = 2147483600;   const long long infl = 1e17;   int n;   pair<int, int> pbef[200005];   struct SegmentTree {    private:     int N;     vector<long long> node;     long long e;       public:     SegmentTree() {}     SegmentTree(long long e) : e(e) {}     void __init__(int sz) {       N = 1;       while (N < sz) N *= 2;       node.resize(2 * N - 1, e);     }     void build(vector<long long> &v) {       int sz = int(v.size());       __init__(sz);       for (long long i = 0; i < (long long)sz; i++) {         node[i + N - 1] = v[i];       }       for (int i = N - 2; i >= 0; i--) {         node[i] = (node[i * 2 + 1] + node[i * 2 + 2]);       }     }     void update(int k, long long x) {       k += N - 1;       node[k] = x;       while (k > 0) {         k = (k - 1) / 2;         node[k] = (node[2 * k + 1] + node[2 * k + 2]);       }     }     void renew(int b, int e, long long x) {       renew(b, e, 0, 0, N, x);       return;     }     void renew(int b, int e, int k, int l, int r, long long x) {       if (e <= 0 || b >= N) return;       if (k > 0) {         node[k] = (node[k] + node[(k - 1) / 2]);       }       if (r < b || e < l) return;       if (b <= l && r <= e) {         node[k] = min(node[k], x);         return;       } else if (k < N - 1) {         renew(b, e, 2 * k + 1, l, (l + r) / 2, x);         renew(b, e, 2 * k + 2, (l + r) / 2, r, x);         return;       }       return;     }     long long get(int i) {       int k = i + N - 1;       long long res = node[k];       while (k > 0) {         k = (k - 1) / 2;         res = min(res, node[k]);       }       return res;     }     long long query(int a, int b) { return query(a, b, 0, 0, N); }     long long query(int a, int b, int k, int l, int r) {       if (b <= l || r <= a) return e;       if (a <= l && r <= b) return node[k];       long long vl, vr;       vl = query(a, b, 2 * k + 1, l, (l + r) / 2);       vr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return (vl + vr);     }     void recalc() {       for (long long k = 0; k < (long long)N - 1; k++) {         node[2 * k + 1] = (node[2 * k * 1] + node[k]);         node[2 * k + 2] = (node[2 * k * 2] + node[k]);       }     }     long long show_one(int i) { return node[i + N - 1]; }     void show() {       for (long long i = 0; i < (long long)N; i++) cout << node[i] <<    ;       cout << endl;       return;     }   };   int main() {     set<int> xapper, yapper;     map<int, int> xidx, yidx;     cin >> n;     for (long long i = 0; i < (long long)n; i++) {       int x, y;       cin >> x >> y;       xapper.insert(x);       yapper.insert(y);       pbef[i] = make_pair(x, y);     }     int xcnt = 0;     for (auto x : xapper) {       xidx[x] = xcnt;       xcnt++;     }     int ycnt = 0;     for (auto y : yapper) {       yidx[y] = ycnt;       ycnt++;     }     ycnt--;     map<int, set<int>> p;     for (long long i = 0; i < (long long)n; i++) {       p[yidx[pbef[i].second]].insert(xidx[pbef[i].first]);     }     SegmentTree seg(0);     seg.__init__(xcnt);     long long ans = 0;     int bef = 0;     for (long long y = (long long)ycnt; y > (long long)-1; y--) {       int cnt = 0;       int nwe = 0;       int bef = 0;       for (auto x : p[y]) {         seg.update(x, 1);       }       for (auto x : p[y]) {         if (seg.show_one(x) == 0) {           ans += (seg.query(0, x + 1) - bef) * seg.query(x, xcnt);           nwe++;         } else {           ans += (seg.query(0, x + 1) - bef) * seg.query(x, xcnt);         }         bef = seg.query(0, x + 1);         cnt++;       }     }     cout << ans << endl;   }   