#include <bits/stdc++.h>
using namespace std;
long long t, q;
int n, a[200005], c[200005], d[200005];
void Add(int x, int y) {
  for (; x <= n; x += x & -x) c[x] += y;
}
int Query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret += c[x];
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i++) scanf("%d%d", &x, &y), a[a[y] = x] = y;
  t = (long long)n * (n - 1) * (n - 2) / 6;
  n <<= 1;
  for (int i = 1, s = 0; i <= n; i++)
    if (a[i] > i)
      d[i] = Query(a[i]) - s, Add(a[i], 1);
    else
      s++;
  memset(c, 0, sizeof(c));
  for (int i = n, s = 0; i; i--)
    if (a[i] < i)
      d[a[i]] += Query(n - a[i] + 1) - s, Add(n - a[i] + 1, 1);
    else
      s++;
  for (int i = 1; i <= n; i++)
    if (a[i] > i)
      q += (long long)d[i] * (n - d[i] * 2 - 2),
          q += (long long)(a[i] - i - 1 - d[i]) * (n - a[i] + i - 1 - d[i]);
  printf("%I64d\n", t - (q >> 2));
}
