#include <bits/stdc++.h>
using namespace std;
int n;
int BIT[200005] = {0};
int N;
void add(int i, int value) {
  while (i <= N) {
    BIT[i] += value;
    i = (i | (i - 1)) + 1;
  }
}
int get(int i) {
  int value = 0;
  while (i > 0) {
    value += BIT[i];
    i &= i - 1;
  }
  return value;
}
int a[100005] = {0}, b[100005] = {0};
int p[200005] = {0}, id[200005] = {0};
int inside[100005] = {0}, inter[100005] = {0};
int main() {
  scanf("%d", &n);
  N = 2 * n;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    if (a[i] > b[i]) swap(a[i], b[i]);
    p[a[i]] = b[i];
    p[b[i]] = a[i];
    id[b[i]] = i;
  }
  for (int i = 1; i <= N; i++) {
    if (p[i] < i) {
      inside[id[i]] = get(i) - get(p[i]);
      add(p[i], 1);
    }
  }
  for (int i = 1; i <= n; i++) inter[i] = b[i] - a[i] - 1 - inside[i] * 2;
  long long rst = (long long)n * (n - 1) * (n - 2) / 6;
  long long cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    cnt1 += (long long)inside[i] * (n - inside[i] - inter[i] - 1);
    cnt2 += (long long)inter[i] * (n - inter[i] - 1);
  }
  rst = rst - cnt1 - cnt2 / 2;
  cout << rst << endl;
}
