#include <bits/stdc++.h>
using namespace std;
inline int lowbit(int x) { return x & (-x); }
struct point {
  int l, r, id;
} p[1000000 + 5];
bool cmpl(point a, point b) { return a.l < b.l; }
bool cmpr(point a, point b) { return a.r < b.r; }
int s[1000000 + 5], in[1000000 + 5], out[1000000 + 5], n, ri[1000000 + 5],
    le[1000000 + 5];
long long ans = 0;
void modify(int pos) {
  while (pos) s[pos]++, pos -= lowbit(pos);
}
int query(int pos) {
  int sum = 0;
  while (pos <= 2 * n) sum += s[pos], pos += lowbit(pos);
  return sum;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].l, &p[i].r);
    p[i].id = i;
    if (p[i].l > p[i].r) swap(p[i].l, p[i].r);
    ri[p[i].r] = 1, le[p[i].l] = 1;
  }
  for (int i = 1; i <= 2 * n; i++) ri[i] += ri[i - 1];
  for (int i = 2 * n; i; i--) le[i] += le[i + 1];
  memset(s, 0, sizeof(s));
  sort(p + 1, p + 1 + n, cmpl);
  for (int i = 1; i <= n; i++)
    out[p[i].id] = query(p[i].r) + ri[p[i].l] + le[p[i].r], modify(p[i].r);
  memset(s, 0, sizeof(s));
  sort(p + 1, p + 1 + n, cmpr);
  for (int i = 1; i <= n; i++) in[p[i].id] = query(p[i].l), modify(p[i].l);
  for (int i = 1; i <= n; i++) {
    ans -= in[i] * 1ll * out[i] * 2 +
           (out[i] + in[i]) * 1ll * (n - in[i] - out[i] - 1);
  }
  ans /= 2;
  ans += 1ll * n * (n - 1) * (n - 2) / 6;
  printf("%I64d\n", ans);
  return 0;
}
