#include <bits/stdc++.h>
using namespace std;
const int oo = 1047483647, maxn = 201000;
int n, i, j, k, m, q, p[maxn], f[maxn], inside[maxn], inter[maxn], id[maxn];
pair<int, int> a[maxn];
int Read() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && (ch != '-'))
    ;
  bool neg = (ch == '-');
  if (ch == '-') ch = getchar();
  int v = 0;
  while (ch >= '0' && ch <= '9') v = v * 10 + ch - '0', ch = getchar();
  if (neg) v = -v;
  return v;
}
void add(int k, int v) {
  while (k <= n + n) {
    f[k] += v;
    k += (k & (-k));
  }
}
int ask(int k) {
  int ans = 0;
  while (k) {
    ans += f[k];
    k -= (k & (-k));
  }
  return ans;
}
int main() {
  n = Read();
  for (i = 1; i <= n; i++) {
    a[i].first = Read();
    a[i].second = Read();
    if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
    p[a[i].first] = a[i].second;
    p[a[i].second] = a[i].first;
    id[a[i].first] = id[a[i].second] = i;
  }
  for (i = 1; i <= n + n; i++)
    if (p[i] < i) {
      inside[id[i]] = ask(i) - ask(p[i] - 1);
      add(p[i], 1);
    }
  for (i = 1; i <= n; i++)
    inter[i] = a[i].second - a[i].first - 1 - inside[i] * 2;
  long long cnt1 = 0, cnt2 = 0;
  long long ans = (long long)n * (n - 1) * (n - 2) / 6;
  for (i = 1; i <= n; i++) {
    cnt1 += (long long)inter[i] * (n - inter[i] - 1);
    cnt2 += (long long)inside[i] * (n - inside[i] - 1 - inter[i]);
  }
  ans -= cnt1 / 2 + cnt2;
  cout << ans;
  return 0;
}
