#include <bits/stdc++.h>
#pragma GCC optimize "O3"
using namespace std;
constexpr int N = 100000;
int n, m, ab[N + 1][2], p[4 * N + 1], s[4 * N + 1], xy[N + 1][2];
bool t[N + 1];
void add(int o, int d = 1) {
  for (; o <= 2 * m; o += (o & (-o))) s[o] += d;
}
int query(int o) {
  int rtn = 0;
  for (; o > 0; o -= (o & (-o))) rtn += s[o];
  return rtn;
}
int main() {
  scanf("%d", &n);
  m = 2 * n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", ab[i], ab[i] + 1);
    if (ab[i][0] > ab[i][1]) swap(ab[i][0], ab[i][1]);
    int cur = ab[i][1], dd[2] = {ab[i][0] + m - ab[i][1], ab[i][1] - ab[i][0]};
    bool st = 0;
    while (cur <= 2 * m) {
      p[cur] = i;
      cur += dd[st];
      st = !st;
    }
  }
  for (int i = 1; i <= 2 * m; ++i) {
    if (p[i]) {
      const int &id = p[i];
      bool &st = t[id];
      xy[id][st] = query(ab[id][!st]) - query(ab[id][st]);
      add(ab[id][st]);
      ab[id][st] += m;
      st = !st;
    }
  }
  long long ans = (long long)n * (n - 1) * (n - 2) / 6, dd = 0;
  for (int i = 1; i <= n; ++i) {
    ans -= (long long)xy[i][0] * xy[i][1];
    dd += (long long)(n - 1 - xy[i][0] - xy[i][1]) * (xy[i][0] + xy[i][1]);
  }
  printf("%lld\n", ans - dd / 2);
}
