#include <bits/stdc++.h>
using namespace std;
int n, p[222222], BIT[222222];
void update(int k, int v) {
  for (int x = k; x <= 2 * n; x += (x & -x)) BIT[x] += v;
}
int query(int k) {
  int ret = 0;
  for (int x = k; x > 0; x -= (x & -x)) ret += BIT[x];
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    p[x] = y;
    p[y] = x;
  }
  long long ans1 = 0, ans2 = 0;
  for (int i = (1); i <= (2 * n); ++i) {
    if (p[i] > i) {
      update(i, 1);
    } else {
      update(i, 1);
      update(p[i], -2);
      long long intersect = (long long)(query(i - 1) - query(p[i]));
      long long inside = (long long)(((i - p[i] - 1) - intersect) / 2);
      long long outside = (long long)n - 1 - intersect - inside;
      ans1 += inside * outside;
      ans2 += intersect * (inside + outside);
    }
  }
  long long nn = (long long)n;
  long long ans = (nn * (nn - 1) * (nn - 2)) / 6LL - ans1 - ans2 / 2LL;
  cout << ans << endl;
  return 0;
}
