#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
inline int read() {
  int sum = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
  return sum;
}
int N, t[maxn], to[maxn], mix[maxn], in[maxn];
void add(int x) {
  for (int i = x; i <= N; i += i & (-i)) t[i]++;
}
int query(int x) {
  int res = 0;
  for (int i = x; i; i -= i & (-i)) res += t[i];
  return res;
}
int main() {
  N = read();
  for (int u, v, i = 1; i <= N; ++i) {
    u = read();
    v = read();
    to[u] = v;
    to[v] = u;
  }
  N <<= 1;
  for (int i = 1; i <= N; ++i)
    if (to[i] > i) {
      mix[i] += query(to[i]) - query(i);
      add(to[i]);
    }
  memset(t, 0, sizeof(t));
  for (int i = N; i; --i)
    if (to[i] < i) {
      mix[to[i]] += query(i) - query(to[i]);
      add(to[i]);
    }
  memset(t, 0, sizeof(t));
  for (int i = N; i; --i)
    if (to[i] > i) {
      in[i] += query(to[i]);
      add(to[i]);
    }
  N >>= 1;
  long long ans = 1LL * N * (N - 1) * (N - 2) / 6, fo = 0;
  for (int i = 1; i <= 2 * N; ++i)
    if (to[i] > i) {
      ans -= 1LL * in[i] * (N - in[i] - mix[i] - 1);
      fo += 1LL * mix[i] * (N - mix[i] - 1);
    }
  printf("%lld\n", ans - fo / 2);
  return 0;
}
