#include <bits/stdc++.h>
using namespace std;
int n, p[222222], first[444444], N, num[222222], X[222222], Y[222222];
void add(int x, int d) {
  while (x < N + N) {
    first[x] += d;
    x = (x | (x + 1));
  }
}
int sum(int x) {
  int r = 0;
  while (x >= 0) {
    r += first[x];
    x = (x & (x + 1)) - 1;
  }
  return r;
}
int get(int l, int r) { return sum(r) - sum(l - 1); }
int main() {
  scanf("%d", &n);
  N = n * 2;
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    p[a] = b, p[b] = a;
    num[a] = i;
    num[b] = i;
  }
  for (int i = 0; i < N + N; ++i) {
    if (i < N) {
      int j = p[i], nn = num[i];
      if (j < i) {
        X[nn] = get(j, i);
        add(j, 1);
      }
    } else {
      int j = p[i - N], nn = num[i - N];
      if (j > i - N) {
        Y[nn] = get(j, i);
        add(j, 1);
      } else {
        add(N + j, 1);
      }
    }
  }
  long long total = 1LL * n * (n - 1) * (n - 2) / 6;
  long long otm = 0;
  for (int i = 0; i < n; ++i)
    otm += 1LL * (n - 1 - X[i] - Y[i]) * (X[i] + Y[i]);
  otm /= 2;
  for (int i = 0; i < n; ++i) otm += 1LL * X[i] * Y[i];
  cout << total - otm << endl;
  return 0;
}
