#include <bits/stdc++.h>
using namespace std;
char buf[1 << 20], *p1, *p2;
template <class T>
inline void read(T &n) {
  char ch =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
           ? 0
           : *p1++);
  T w = 1, x = 0;
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch =
        (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? 0
             : *p1++);
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch =
        (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? 0
             : *p1++);
  }
  n = x * w;
}
const int maxn = 500005;
int n, t[maxn << 1];
inline int lowbit(int x) { return x & (-x); }
inline void update(int x, int val) {
  for (int i = x; i <= n * 2; i += lowbit(i)) t[i] += val;
}
inline int query(int x) {
  int res = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) res += t[i];
  return res;
}
int L[maxn], R[maxn];
struct line {
  int x, y, id;
} s[maxn];
bool cmp1(line a, line b) { return a.x < b.x; }
bool cmp2(line a, line b) { return a.y < b.y; }
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(s[i].x), read(s[i].y);
    if (s[i].x > s[i].y) swap(s[i].x, s[i].y);
    s[i].id = i;
  }
  sort(s + 1, s + n + 1, cmp1);
  for (int i = 1; i <= n; i++) {
    L[s[i].id] = query(s[i].x - 1) + i - 1 - query(s[i].y);
    update(s[i].y, 1);
  }
  memset(t, 0, sizeof(t));
  for (int i = n; i >= 1; i--) {
    R[s[i].id] = query(s[i].y) - query(s[i].x);
    update(s[i].y, 1);
  }
  sort(s + 1, s + n + 1, cmp2);
  memset(t, 0, sizeof(t));
  for (int i = n; i >= 1; i--) {
    L[s[i].id] += n - i - query(s[i].y);
    update(s[i].x, 1);
  }
  long long ans = 1ll * n * (n - 1) * (n - 2) / 6, res = 0;
  for (int i = 1; i <= n; i++) {
    ans -= 1ll * L[i] * R[i];
    res += 1ll * (L[i] + R[i]) * (n - 1 - L[i] - R[i]);
  }
  cout << ans - res / 2 << endl;
  return 0;
}
