#include <bits/stdc++.h>
using namespace std;
const long long N = 1000005;
long long num[N], l[N], r[N], n, ans1, ans2;
struct Ask {
  long long l, r, id;
} a[N];
inline long long cmp1(Ask a, Ask b) { return a.l < b.l; }
inline long long cmp2(Ask a, Ask b) { return a.r < b.r; }
inline void insert(long long x) {
  for (; x <= 2 * n; x += x & -x) num[x]++;
}
inline long long find(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += num[x];
  return ans;
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &a[i].l, &a[i].r);
    if (a[i].l > a[i].r) swap(a[i].l, a[i].r);
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmp2);
  for (long long i = 1; i <= n; i++) {
    r[a[i].id] += i - 1 - find(a[i].l);
    insert(a[i].l);
  }
  memset(num, 0, sizeof(num));
  for (long long i = n; i >= 1; i--) {
    l[a[i].id] += n - i - find(a[i].r);
    insert(a[i].l);
  }
  memset(num, 0, sizeof(num));
  for (long long i = n; i >= 1; i--) {
    l[a[i].id] += find(a[i].l);
    insert(a[i].l);
  }
  sort(a + 1, a + n + 1, cmp1);
  memset(num, 0, sizeof(num));
  for (long long i = 1; i <= n; i++) {
    l[a[i].id] += find(a[i].l);
    insert(a[i].r);
  }
  ans1 = n * (n - 1) * (n - 2) / 6;
  for (long long i = 1; i <= n; i++) {
    ans1 -= l[i] * r[i];
    ans2 += (l[i] + r[i]) * (n - l[i] - r[i] - 1);
  }
  printf("%lld", ans1 - ans2 / 2);
}
