#include <bits/stdc++.h>
using namespace std;
const long long N = 100100 * 20;
long long n;
long long ans;
struct node {
  long long x, y;
  long long cta, ctb;
} a[N];
bool cmp(node a, node b) { return (a.x < b.x); }
bool cmy(node a, node b) { return (a.y > b.y); }
long long t[N];
long long lowbit(long long x) { return (x) & (-x); };
void add(long long x, long long v) {
  for (; x <= n * 2; x += lowbit(x)) t[x] += v;
}
long long qry(long long x) {
  long long rt = 0;
  for (; x; x -= lowbit(x)) rt += t[x];
  return rt;
}
priority_queue<pair<long long, long long> > q;
void solve() {
  memset(t, 0, sizeof t);
  for (long long i = (1); i <= (n); ++i) {
    if (!q.empty()) {
      pair<long long, long long> p = q.top();
      p.first = -p.first;
      while (p.first < a[i].x) {
        a[p.second].ctb += qry(a[p.second].y - 1) - qry(a[p.second].x);
        q.pop();
        if (q.empty()) break;
        p = q.top();
        p.first = -p.first;
      }
    }
    a[i].cta += qry(a[i].x) + qry(2 * n) - qry(a[i].y);
    a[i].ctb -= qry(a[i].y - 1) - qry(a[i].x);
    add(a[i].y, 1);
    q.push(make_pair(-a[i].y, i));
  }
  while (!q.empty()) {
    pair<long long, long long> p = q.top();
    p.first = -p.first;
    a[p.second].ctb += qry(a[p.second].y - 1) - qry(a[p.second].x);
    q.pop();
    if (q.empty()) break;
  }
  memset(t, 0, sizeof t);
  sort(a + 1, a + 1 + n, cmy);
  for (long long i = (1); i <= (n); ++i) {
    a[i].cta += qry(2 * n) - qry(a[i].y);
    add(a[i].x, 1);
  }
}
int bz[N];
int main() {
  scanf("%I64d\n", &n);
  for (long long i = (1); i <= (n); ++i) {
    scanf("%I64d%I64d", &a[i].x, &a[i].y);
    if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
    a[i].cta = a[i].ctb = 0;
  }
  sort(a + 1, a + 1 + n, cmp);
  solve();
  for (long long i = (1); i <= (n); ++i)
    ans = ans + (1ll * (n - a[i].cta - a[i].ctb - 1) * (a[i].cta + a[i].ctb)) +
          (1ll * a[i].cta * a[i].ctb) * 2;
  ans = (1ll * n * (n - 1) * (n - 2) / 3) - ans;
  ans /= 2;
  printf("%I64d\n", ans);
  return 0;
}
