#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG = 20;
long long ans;
int n, m, k, u, v, x, y, t, a, b;
int A[MAXN], B[MAXN], C[MAXN];
int ted[MAXN], f[MAXN], g[MAXN];
int ps1[MAXN], ps2[MAXN];
int fen[MAXN];
inline void add(int pos, int val) {
  for (; pos < MAXN; pos += pos & -pos) fen[pos] += val;
}
inline int get(int pos) {
  int res = 0;
  for (; pos; pos -= pos & -pos) res += fen[pos];
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i] >> B[i];
    if (A[i] > B[i]) swap(A[i], B[i]);
    C[A[i]] = i;
    C[B[i]] = -i;
  }
  for (int i = 1; i <= 2 * n; i++) {
    if (C[i] < 0)
      add(i, -1);
    else {
      ted[C[i]] += get(B[C[i]]) - get(i);
      f[C[i]] = get(2 * n) - get(B[C[i]]);
      add(B[C[i]], +1);
    }
  }
  for (int i = 2 * n; i; i--) {
    if (C[i] > 0)
      add(i, -1);
    else {
      ted[-C[i]] += get(i) - get(A[-C[i]]);
      add(A[-C[i]], +1);
    }
  }
  for (int i = 2 * n; i; i--)
    if (C[i] > 0) {
      g[C[i]] = get(B[C[i]]);
      add(B[C[i]], +1);
    }
  memset(fen, 0, sizeof(fen));
  for (int i = 1; i <= n; i++) {
    ans += ted[i] * (n - 1ll - ted[i]);
  }
  ans /= 2;
  ans = n * (n - 1ll) * (n - 2ll) / 6 - ans;
  for (int i = 1; i <= n; i++) {
    ps1[A[i]] += g[i];
    ps2[B[i]] += g[i];
  }
  for (int i = 1; i <= 2 * n; i++) ps2[i] += ps2[i - 1];
  for (int i = 2 * n; i; i--) ps1[i] += ps1[i + 1];
  for (int i = 1; i <= n; i++) {
    ans -= 1ll * f[i] * g[i];
    ans -= ps1[B[i]];
    ans -= ps2[A[i]];
  }
  cout << ans << "\n";
  return 0;
}
