#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
} h[(200000 + 5)];
int ql, qr;
namespace Seg_tree {
int hn, hv[(15000000 + 5)], ch[(15000000 + 5)][2];
void Modify(int &o, int L, int R, int p) {
  if (!o) o = ++hn;
  if (L == R) {
    ++hv[o];
    return;
  }
  if (p <= ((L + R) >> 1))
    Modify(ch[o][0], L, ((L + R) >> 1), p);
  else
    Modify(ch[o][1], ((L + R) >> 1) + 1, R, p);
  hv[o] = hv[ch[o][0]] + hv[ch[o][1]];
}
int Query(int &o, int L, int R) {
  if (!o) return 0;
  if (ql <= L && qr >= R) return hv[o];
  int ret = 0;
  if (ql <= ((L + R) >> 1)) ret += Query(ch[o][0], L, ((L + R) >> 1));
  if (qr > ((L + R) >> 1)) ret += Query(ch[o][1], ((L + R) >> 1) + 1, R);
  return ret;
}
};  // namespace Seg_tree
using namespace Seg_tree;
int n, ml[(200000 + 5)], mr[(200000 + 5)], mc[(200000 + 5)], rt[(200000 + 5)];
inline int lowbit(int x) { return x & (-x); }
void Add(int x, int y) {
  while (x <= (n << 1)) {
    Modify(rt[x], 1, (n << 1), y);
    x += lowbit(x);
  }
}
int Sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += Query(rt[x], 1, n << 1);
    x -= lowbit(x);
  }
  return ret;
}
int Qus(int l1, int r1, int l2, int r2) {
  if (l1 > r1 || l2 > r2) return 0;
  ql = l2;
  qr = r2;
  return Sum(r1) - Sum(l1 - 1);
}
void Init() {
  for (int i = (1); i <= (int)(n); ++i) Add(h[i].l, h[i].r);
  for (int i = (1); i <= (int)(n); ++i) {
    ml[i] = Qus(h[i].l + 1, h[i].r - 1, h[i].l + 1, h[i].r - 1);
    mc[i] = Qus(1, h[i].l - 1, h[i].l + 1, h[i].r - 1) +
            Qus(h[i].l + 1, h[i].r - 1, h[i].r + 1, n << 1);
    mr[i] = n - 1 - ml[i] - mc[i];
  }
}
int Calc(node a, int v) {
  if (v > a.l && v < a.r) return true;
  return false;
}
bool Cross(node a, node b) {
  int t1 = Calc(a, b.l), t2 = Calc(a, b.r);
  return t1 ^ t2;
}
bool Check(node me, node a, node b) {
  int ta = Calc(me, a.l), tb = Calc(me, b.l);
  return ta == tb;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)(n); ++i) {
    scanf("%d%d", &h[i].l, &h[i].r);
    if (h[i].l > h[i].r) swap(h[i].l, h[i].r);
  }
  if (n < 3) {
    puts("0");
    return 0;
  }
  if (n > 10000)
    Init();
  else {
    for (int i = (1); i <= (int)(n); ++i)
      for (int j = (1); j <= (int)(n); ++j)
        if (i != j) {
          if (Cross(h[i], h[j]))
            ++mc[i];
          else {
            if (Calc(h[i], h[j].l))
              ++ml[i];
            else
              ++mr[i];
          }
        }
  }
  long long ans = 1ll * n * (n - 1) * (n - 2) / 6;
  for (int i = (1); i <= (int)(n); ++i) ans -= 1ll * ml[i] * mr[i];
  long long cnt = 0;
  for (int i = (1); i <= (int)(n); ++i) cnt += 1ll * mc[i] * (ml[i] + mr[i]);
  cnt /= 2;
  ans -= cnt;
  printf("%I64d\n", ans);
  return 0;
}
