#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int l[N], r[N], a[N * 2];
int n, t[N * 2], R[N * 2], Md[N * 2];
void add(int k, int v) {
  for (; k <= 2 * n; k += k & (-k)) t[k] += v;
}
int ask(int k) {
  int ans = 0;
  for (; k; k -= k & (-k)) ans += t[k];
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x] = y;
    a[y] = x;
  }
  long long ans = 1ll * n * (n - 1) * (n - 2) / 6;
  long long s1 = 0, s2 = 0;
  for (int i = (2 * n); i >= (int)1; i--)
    if (a[i] > i) R[i] += ask(a[i]), add(a[i], 1);
  memset(t, 0, sizeof(t));
  ;
  for (int i = (2 * n); i >= (int)1; i--)
    if (a[i] < i) Md[a[i]] += ask(i) - ask(a[i] - 1), add(a[i], 1);
  memset(t, 0, sizeof(t));
  ;
  for (int i = (1); i <= (int)2 * n; i++)
    if (a[i] > i) Md[i] += ask(a[i]) - ask(i - 1), add(a[i], 1);
  for (int i = (1); i <= (int)n * 2; i++)
    if (a[i] > i) {
      s1 += 1ll * Md[i] * (n - 1 - Md[i]);
      s2 += 1ll * R[i] * (n - 1 - Md[i] - R[i]);
    }
  printf("%lld\n", ans - s1 / 2 - s2);
}
