func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], b[100005];   int l[100005], r[100005];   using pii = pair<int, int>;   using ppi = pair<pii, int>;   int tr[100005 * 2];   int get(int k) {     int res = 0;     for (; k; k -= k & -k) res += tr[k];     return res;   }   void update(int k) {     for (; k <= m; k += k & -k) tr[k]++;   }   void calc(int *g, int *gg) {     vector<ppi> V;     for (int i = 1; i <= n; i++)       V.push_back(ppi(pii(min(a[i], b[i]), max(a[i], b[i])), i));     sort(V.begin(), V.end(), [](const ppi &x, const ppi &y) {       return x.first.second < y.first.second;     });     int cnt = 0;     memset(tr, 0, sizeof tr);     for (auto x : V) {       g[x.second] = cnt - get(x.first.first);       update(x.first.first);       cnt++;     }     reverse(V.begin(), V.end());     memset(tr, 0, sizeof tr);     cnt = 0;     for (auto x : V) {       gg[x.second] = cnt - get(x.first.second) + get(x.first.first);       update(x.first.first);       cnt++;     }     memset(tr, 0, sizeof tr);     for (auto x : V) update(x.first.second);     for (auto x : V) gg[x.second] += get(x.first.first);     return;   }   int main() {     scanf( %d , &n);     m = 2 * n;     for (int i = 1; i <= n; i++) scanf( %d %d , &a[i], &b[i]);     calc(l, r);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int t = n - 1 - l[i] - r[i];       ans += 1ll * t * (l[i] + r[i]);     }     ans >>= 1;     for (int i = 1; i <= n; i++) ans += 1ll * l[i] * r[i];     ans = 1ll * n * (n - 1) * (n - 2) / 6 - ans;     cout << ans << endl;     return 0;   }   