#include <bits/stdc++.h>
using namespace std;
int n, m, sl, fh, x[1000010], y[1000010], e[1000010], tr[1000010];
long long res, ans;
int rd() {
  sl = 0;
  fh = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') sl = sl * 10 + ch - '0', ch = getchar();
  return sl * fh;
}
void ins(int i) {
  for (; i <= m; i += (i & -i)) tr[i]++;
}
int qry(int i) {
  int ret = 0;
  for (; i; i -= (i & -i)) ret += tr[i];
  return ret;
}
int main() {
  n = rd();
  m = n << 1;
  int X, Y;
  for (int i = 1; i <= n; ++i) {
    x[i] = rd();
    y[i] = rd();
    e[x[i]] = y[i];
    e[y[i]] = x[i];
  }
  ans = 1ll * n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= m; ++i)
    if (i > e[i]) {
      X = qry(i - 1) - qry(e[i]);
      Y = i - e[i] - 1 - X * 2;
      res += 1ll * Y * (n - 1 - Y);
      ans -= 1ll * X * (n - 1 - X - Y);
      ins(e[i]);
    }
  printf("%lld\n", ans - res / 2);
  return 0;
}
