#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, mat[N], id[N];
int t[N], ans1[N], ans2[N];
long long res;
void change(int k, int v) {
  for (; k <= 2 * n; k += k & (-k)) t[k] += v;
}
int ask(int k) {
  int ans = 0;
  for (; k; k -= k & (-k)) ans += t[k];
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    mat[x] = y;
    mat[y] = x;
    id[x] = i;
    id[y] = i;
  }
  for (int i = (int)(1); i <= (int)(2 * n); i++)
    if (mat[i] > i) {
      ans1[id[i]] += ask(mat[i]) - ask(i);
      change(mat[i], 1);
    }
  memset(t, 0, sizeof(t));
  for (int i = (int)(2 * n); i >= (int)(1); i--)
    if (mat[i] < i) {
      ans1[id[i]] += ask(i) - ask(mat[i]);
      change(mat[i], 1);
    }
  for (int i = (int)(1); i <= (int)(n); i++)
    res += 1ll * ans1[i] * (n - 1 - ans1[i]);
  res = 1ll * n * (n - 1) * (n - 2) / 6 - res / 2;
  memset(t, 0, sizeof(t));
  for (int i = (int)(1); i <= (int)(2 * n); i++)
    if (mat[i] < i) {
      ans2[id[i]] += ask(2 * n) - ask(mat[i]);
      change(mat[i], 1);
    }
  for (int i = (int)(1); i <= (int)(n); i++)
    res -= 1ll * ans2[i] * (n - 1 - ans1[i] - ans2[i]);
  printf("%lld\n", res);
}
