#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 201000;
int u, v, op[N], c[N], n;
long long ret;
int query(int x) {
  int s = 0;
  for (; x; x -= x & -x) s += c[x];
  return s;
}
void add(int x) {
  for (; x <= 2 * n; x += x & -x) c[x]++;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &u, &v);
    op[u] = v;
    op[v] = u;
  }
  ret = n * (n - 1ll) * (n - 2) / 3;
  for (int i = 1; i < 2 * n + 1; i++)
    if (op[i] < i) {
      long long x = query(i) - query(op[i] - 1), z = i - op[i] - 1 - 2 * x,
                y = n - 1 - x - z;
      add(op[i]);
      ret -= z * (x + y) + 2 * x * y;
    }
  printf("%I64d\n", ret / 2);
}
