#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010], b[200010], c[200010], d[200010];
long long ans;
int query(int i) {
  int ret = 0;
  for (; i > 0; i -= i & (-i)) ret += c[i];
  return ret;
}
void change(int i, int x) {
  for (; i <= 2 * n; i += i & (-i)) c[i] += x;
}
int main() {
  int i, j, x, y, s, s1;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    a[x] = y;
    a[y] = x;
  }
  s = 0;
  s1 = 0;
  ans = (long long)n * (n - 1) * (n - 2) / 3;
  for (i = 2 * n; i >= 1; i--)
    if (a[i] < i) {
      s++;
      b[a[i]] += s1;
      d[a[i]] += s - 1;
    } else {
      s1++;
      x = query(a[i]);
      change(a[i], 1);
      b[i] += n - s;
      d[i] -= query(2 * n) - query(a[i]);
      ans -= (long long)(x + b[i] + d[i]) * (n - 1 - x - b[i] - d[i]) +
             (long long)x * (b[i] + d[i]) * 2;
    }
  ans /= 2;
  printf("%I64d\n", ans);
  return 0;
}
