#include <bits/stdc++.h>
using namespace std;
const int MAXN(101);
const int MAXE(5000010);
const int MAXK(100010);
const int MAXC(2);
const int INF((INT_MAX - 1) / 2);
const int BASE(20);
const double LIM(1e50);
const double EPS(1e-5);
const double PER(0.02);
const double MUL(3.5);
int IT;
template <typename T>
inline bool checkmax(T &a, const T &b) {
  return b > a ? ((a = b), true) : false;
}
template <typename T>
inline bool checkmin(T &a, const T &b) {
  return b < a ? ((a = b), true) : false;
}
template <typename T>
inline T ABS(T a) {
  return a < 0 ? -a : a;
}
struct BIT {
  int arr[200001], sz;
  int lb(int i) { return i & -i; }
  void ini(int sz) {
    this->sz = sz;
    memset(arr + 1, 0, sizeof(arr[0]) * sz);
  }
  void add(int i, int v) {
    for (; i <= sz; i += lb(i)) arr[i] += v;
  }
  int query(int i) {
    int ret = 0;
    for (; i > 0; i -= lb(i)) ret += arr[i];
    return ret;
  }
};
BIT bi;
int a[100001], b[100001], p[200001], id[200001];
int inside[100001], inter[100001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", a + i, b + i);
    if (a[i] > b[i]) swap(a[i], b[i]);
    p[a[i]] = b[i];
    p[b[i]] = a[i];
    id[a[i]] = i;
    id[b[i]] = i;
  }
  bi.ini(2 * n);
  for (int i = 1; i <= 2 * n; ++i)
    if (p[i] < i) {
      inside[id[i]] = bi.query(i) - bi.query(p[i] - 1);
      bi.add(p[i], 1);
    }
  for (int i = 1; i <= n; ++i) inter[i] = b[i] - a[i] - 1 - 2 * inside[i];
  long long ans = (long long)n * (n - 1) * (n - 2) / 6, cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; ++i) {
    cnt1 += (long long)inter[i] * (n - inter[i] - 1);
    cnt2 += (long long)inside[i] * (n - inter[i] - inside[i] - 1);
  }
  ans = ans - cnt1 / 2 - cnt2;
  cout << ans << endl;
  return 0;
}
