#include <bits/stdc++.h>
using namespace std;
int n, szsz[2][200010], qzh[200010], hzh[200010];
long long jg, emm;
struct bbbb {
  int l, r;
  long long ll, rr;
} b[100010];
void xg(int em, int wz, int val) {
  while (wz <= n * 2) {
    szsz[em][wz] += val;
    wz += (wz & (-wz));
  }
  return;
}
long long cx(int em, int wz) {
  int jgg = 0;
  while (wz > 0) {
    jgg += szsz[em][wz];
    wz -= (wz & (-wz));
  }
  return jgg;
}
bool gz(bbbb x, bbbb y) { return x.l < y.l; }
int main() {
  scanf("%d", &n);
  jg = (1ll * n * (n - 1) * (n - 2)) / 6;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &b[i].l, &b[i].r);
    if (b[i].l > b[i].r) swap(b[i].l, b[i].r);
    qzh[b[i].r]++;
    hzh[b[i].l]++;
    xg(0, b[i].r, 1);
  }
  for (int i = 1; i <= n * 2; i++) {
    qzh[i] += qzh[i - 1];
  }
  for (int i = n * 2; i >= 1; i--) {
    hzh[i] += hzh[i + 1];
  }
  sort(b + 1, b + n + 1, gz);
  for (int i = 1; i <= n; i++) {
    b[i].ll = qzh[b[i].l] + hzh[b[i].r] + i - 1 - cx(1, b[i].r);
    b[i].rr = cx(0, b[i].r - 1);
    xg(0, b[i].r, -1);
    xg(1, b[i].r, 1);
    jg -= b[i].ll * b[i].rr;
    emm += (b[i].ll + b[i].rr) * (n - b[i].ll - b[i].rr - 1);
  }
  jg -= emm / 2;
  cout << jg;
  return 0;
}
