#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 9;
int match[Maxn];
int fen[Maxn];
long long l[Maxn], r[Maxn], c[Maxn];
int qry(int v) {
  int res = 0;
  v++;
  for (v; v; v -= v & -v) res += fen[v];
  return res;
}
void update(int v) {
  v++;
  for (v; v < Maxn; v += v & -v) fen[v]++;
  return;
}
int query(int l, int r) { return qry(r) - qry(l - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, v;
    cin >> u >> v;
    match[--u] = --v;
    match[v] = u;
  }
  long long lr = 0;
  long long clpr = 0;
  for (int i = 0; i < 2 * n; i++) {
    int ot = match[i];
    if (i > ot) {
      l[i] = query(ot, i);
      c[i] = (i - ot - 1) - 2 * l[i];
      r[i] = n - 1 - l[i] - c[i];
      lr += l[i] * r[i];
      clpr += c[i] * (l[i] + r[i]);
      update(ot);
    }
  }
  long long all = ((long long)n * (n - 1) * (n - 2)) / 6;
  cout << all - (clpr / 2) - lr << endl;
  return 0;
}
