#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
int n, a[200005], M[200005], R[200005];
long long ans, foo;
struct fenwick {
  int bit[200005];
  void init() { memset(bit, 0, sizeof(bit)); }
  void add(int i) {
    for (; i <= n << 1; i += i & -i) bit[i]++;
  }
  int sum(int i) {
    int res = 0;
    for (; i; i -= i & -i) res += bit[i];
    return res;
  }
} F;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read(), y = read();
    a[a[x] = y] = x;
  }
  for (int i = n << 1; i; i--)
    if (a[i] > i) R[i] = F.sum(a[i]), F.add(a[i]);
  F.init();
  for (int i = n << 1; i; i--)
    if (a[i] < i) M[a[i]] = F.sum(i) - F.sum(a[i]), F.add(a[i]);
  F.init();
  for (int i = 1; i <= n << 1; i++)
    if (a[i] > i) M[i] += F.sum(a[i]) - F.sum(i), F.add(a[i]);
  ans = 1LL * n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= n << 1; i++)
    if (a[i] > i)
      ans -= 1LL * R[i] * (n - 1 - R[i] - M[i]),
          foo += 1LL * M[i] * (n - 1 - M[i]);
  printf("%lld\n", ans - (foo >> 1));
}
