#include <bits/stdc++.h>
using namespace std;
int N;
long long Ans;
int other[102013 * 4], s[102013 * 4];
struct BIT {
  int f[102013 * 4];
  inline void upd(int x, int p) {
    for (; x <= 4 * N; x += ((x) & (-(x)))) f[x] += p;
  }
  inline int sum(int x) {
    int ret = 0;
    for (; x; x -= ((x) & (-(x)))) ret += f[x];
    return ret;
  }
} T;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    s[x]++;
    s[y]--;
    other[x] = y;
    other[y] = x;
  }
  for (int i = 1; i <= 2 * N; ++i) T.upd(i, s[i]);
  for (int i = 1; i <= 2 * N; ++i) {
    if (s[i] > 0) {
      T.upd(i, -1);
      T.upd(other[i], 2);
      long long x = other[i] - i - T.sum(other[i] - 1) - 1,
                y = 2 * N - other[i] + i - 1 - T.sum(other[i] - 1);
      x >>= 1;
      y >>= 1;
      long long t = N - 1 - x - y;
      Ans += 2 * x * y;
      Ans += (x + y) * t;
    } else
      T.upd(i, -1);
  }
  Ans /= 2;
  Ans = -Ans;
  Ans += 1LL * N * (N - 1) * (N - 2) / 6;
  cout << Ans;
  return 0;
}
