#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, to[N + N];
int tr[N + N];
long long ans, v1, v2;
inline void add(int x, int w) {
  for (; x <= n + n; x += x & -x) tr[x] += w;
}
inline int ask(int x) {
  int ss = 0;
  for (; x; x -= x & -x) ss += tr[x];
  return ss;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i++)
    scanf("%d%d", &x, &y), to[x] = y, to[y] = x;
  ans = (long long)n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= n + n; i++) {
    if (i < to[i]) continue;
    int x = ask(i) - ask(to[i] - 1), z = i - to[i] - 1 - x - x;
    int y = n - 1 - x - z;
    add(to[i], 1);
    v1 += (long long)x * y, v2 += (long long)(x + y) * z;
  }
  printf("%I64d\n", ans - v1 - v2 / 2);
  return 0;
}
