#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T &x) {
  char ch = getchar();
  int f = 1;
  x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  char ch = getchar();
  int f = 1;
  x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  read(args...);
}
int n, ch[200050 << 5][2], size[200050 << 5], tcnt, p[200050], root[200050];
pair<int, int> l[200050];
void copy(int u, int p) {
  ch[u][0] = ch[p][0], ch[u][1] = ch[p][1], size[u] = size[p];
}
void ins(int &u, int l, int r, int x) {
  int tmp = u;
  copy(u = ++tcnt, tmp);
  ++size[u];
  if (l == r) return;
  if (x <= ((l + r) >> 1))
    ins(ch[u][0], l, ((l + r) >> 1), x);
  else
    ins(ch[u][1], ((l + r) >> 1) + 1, r, x);
}
int query(int u, int l, int r, int tl, int tr) {
  if (!u || (tl <= l && r <= tr)) return size[u];
  int ret = 0;
  if (tl <= ((l + r) >> 1)) ret = query(ch[u][0], l, ((l + r) >> 1), tl, tr);
  if (((l + r) >> 1) < tr)
    ret += query(ch[u][1], ((l + r) >> 1) + 1, r, tl, tr);
  return ret;
}
int query(int l, int r, int tl, int tr) {
  return query(root[r], 1, n << 1, tl, tr) -
         query(root[l - 1], 1, n << 1, tl, tr);
}
int Left(int x, int y) {
  if (x > y) swap(x, y);
  return ((query(1, x, 1, x) + query(1, x, y, n << 1) + query(y, n << 1, 1, x) +
           query(y, n << 1, y, n << 1)) >>
          1) -
         1;
}
int Right(int x, int y) {
  if (x > y) swap(x, y);
  return (query(x, y, x, y) >> 1) - 1;
}
int main() {
  read(n);
  int x, y;
  for (register int i = 1; i <= n; ++i)
    read(x, y), l[i] = make_pair(x, y), p[p[x] = y] = x;
  for (register int i = 1; i <= n << 1; ++i)
    root[i] = root[i - 1], ins(root[i], 1, n << 1, p[i]);
  long long ans = 1ll * n * (n - 1) * (n - 2) / 6;
  for (register int i = 1; i <= n; ++i) {
    ans -= 1ll * Left(l[i].first, l[i].second) * Right(l[i].first, l[i].second);
  }
  long long bad = 0;
  for (register int i = 1; i <= n; ++i) {
    int no = Left(l[i].first, l[i].second) + Right(l[i].first, l[i].second);
    bad += 1ll * no * (n - no - 1);
  }
  bad >>= 1, ans -= bad;
  printf("%lld", ans);
  return 0;
}
