#include <bits/stdc++.h>
const int MAXN = 200005;
int n, bit[MAXN], a[MAXN];
long long ans, tot;
inline void Modify(int i) {
  for (; i <= 2 * n; i += i & -i) ++bit[i];
}
inline int Query(int i) {
  int res = 0;
  for (; i; i -= i & -i) res += bit[i];
  return res;
}
int in[MAXN], on[MAXN];
int main() {
  scanf("%d", &n);
  for (register int u, v, i = 1; i <= n; ++i) {
    scanf("%d%d", &u, &v);
    a[u] = v;
    a[v] = u;
  }
  for (register int i = 2 * n; i; --i)
    if (a[i] > i) {
      in[i] = Query(a[i]);
      Modify(a[i]);
    }
  memset(bit, 0, sizeof bit);
  for (register int i = 1; i <= 2 * n; ++i)
    if (a[i] > i) {
      on[i] += Query(a[i]) - Query(i);
      Modify(a[i]);
    }
  memset(bit, 0, sizeof bit);
  for (register int i = 2 * n; i; --i)
    if (a[i] < i) {
      on[a[i]] += Query(i) - Query(a[i]);
      Modify(a[i]);
    }
  ans += 1LL * n * (n - 1) * (n - 2) / 6;
  for (register int i = 1; i <= 2 * n; ++i)
    if (a[i] > i) {
      ans -= 1LL * in[i] * (n - 1 - in[i] - on[i]);
      tot += 1LL * on[i] * (n - 1 - on[i]);
    }
  printf("%lld\n", ans - tot / 2);
  return 0;
}
