#include <bits/stdc++.h>
using namespace std;
int N;
pair<int, int> p[210000];
int cnt1[210000], cnt2[210000];
int tree[210000];
void update(int u, int val) {
  while (u < 210000) {
    tree[u] += val;
    u += u & -u;
  }
}
int calc(int u) {
  int res = 0;
  while (u) {
    res += tree[u];
    u -= u & -u;
  }
  return res;
}
int main() {
  int i;
  long long ans, tmp;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
    if (p[i].first > p[i].second) swap(p[i].first, p[i].second);
  }
  sort(p, p + N);
  for (i = N - 1; i >= 0; i--) {
    cnt1[i] = calc(p[i].second);
    update(p[i].second, 1);
  }
  memset(tree, 0, sizeof(tree));
  for (i = 0; i < N; i++) update(2 * N - p[i].second + 1, 1);
  for (i = N - 1; i >= 0; i--) {
    update(N * 2 - p[i].second + 1, -1);
    cnt2[i] = calc(2 * N - p[i].second + 1);
  }
  for (i = 0; i < N; i++) {
    cnt2[i] += calc(p[i].first);
    update(p[i].second, 1);
  }
  memset(tree, 0, sizeof(tree));
  for (i = N - 1; i >= 0; i--) {
    cnt2[i] += calc(N * 2 + 1 - p[i].second);
    update(N * 2 + 1 - p[i].first, 1);
  }
  ans = (long long)N * (N - 1) * (N - 2) / 6;
  tmp = 0;
  for (i = 0; i < N; i++) {
    tmp += (long long)(N - 1 - cnt1[i] - cnt2[i]) * (cnt1[i] + cnt2[i]);
  }
  tmp /= 2;
  ans -= tmp;
  for (i = 0; i < N; i++) {
    ans -= (long long)cnt1[i] * cnt2[i];
  }
  printf("%I64d\n", ans);
  return 0;
}
