#include <bits/stdc++.h>
using namespace std;
long long a[200005], n, m, p[200005];
long long lowbit(long long x) { return x & (-x); }
void add(long long x, long long v) {
  for (long long i = x; i <= n; i += lowbit(i)) a[i] += v;
}
long long getsum(long long x) {
  long long ans = 0;
  for (long long i = x; i; i -= lowbit(i)) ans += a[i];
  return ans;
}
int main() {
  long long i, j;
  scanf("%lld", &m);
  n = m * 2;
  for (i = 1; i <= m; i++) {
    long long u, v;
    scanf("%lld%lld", &u, &v);
    p[u] = v;
    p[v] = u;
  }
  long long f = 0, g = 0;
  for (i = 1; i <= n; i++) {
    if (p[i] > i) continue;
    long long x = getsum(i) - getsum(p[i] - 1);
    long long z = (i - p[i] - 1) - x * 2;
    long long y = m - x - z - 1;
    add(p[i], 1);
    f += x * y;
    g += z * (x + y);
  }
  long long l = m;
  long long s = l * (l - 1) * (l - 2) / 6;
  cout << s - f - g / 2 << endl;
  return 0;
}
