#include <bits/stdc++.h>
using namespace std;
const long long N = 200010;
long long C[N], n;
long long lowbit(long long x) { return x & (-x); }
void add(long long x, long long ad) {
  for (; x <= n + n; x += lowbit(x)) C[x] += ad;
}
long long sum(long long x) {
  long long ret = 0;
  for (; x; x -= lowbit(x)) ret += C[x];
  return ret;
}
long long pa[N];
int main() {
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    pa[a] = b;
    pa[b] = a;
    add(b, 1);
  }
  long long ans = n * (n - 1) * (n - 2) / 6;
  long long c1 = 0, c2 = 0;
  for (long long i = 1; i <= n + n; ++i)
    if (i < pa[i]) {
      add(pa[i], -1);
      long long l = sum(pa[i]);
      long long x = pa[i] - i - 1 - 2 * l;
      long long r = n - 1 - l - x;
      c1 += (long long)l * r;
      c2 += (long long)x * (r + l);
    }
  ans -= c1 + c2 / 2;
  cout << ans << endl;
  return 0;
}
