#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gi() {
  T f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;
int n;
struct Node {
  int x, y, id;
} a[N];
int l[N], r[N];
inline bool cmp1(Node x, Node y) { return x.x > y.x; }
inline bool cmp2(Node x, Node y) { return x.y > y.y; }
inline bool cmp3(Node x, Node y) { return x.x < y.x; }
namespace BIT {
int tr[M];
void add(int x, int val) {
  for (int i = x; i <= n * 2; i += (i & (-i))) tr[i] += val;
}
int query(int x) {
  int res = 0;
  for (int i = x; i; i -= (i & (-i))) res += tr[i];
  return res;
}
}  // namespace BIT
int main() {
  n = gi<int>();
  for (int i = 1; i <= n; i += 1)
    a[i].x = gi<int>(), a[i].y = gi<int>(), a[i].id = i;
  for (int i = 1; i <= n; i += 1)
    if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
  sort(a + 1, a + 1 + n, cmp1);
  for (int i = 1; i <= n; i += 1)
    l[a[i].id] = BIT ::query(a[i].y - 1), BIT ::add(a[i].y, 1);
  memset(BIT ::tr, 0, sizeof BIT ::tr);
  sort(a + 1, a + 1 + n, cmp3);
  for (int i = 1; i <= n; i += 1)
    r[a[i].id] =
        BIT ::query(a[i].x - 1) + BIT ::query(n * 2) - BIT ::query(a[i].y),
    BIT ::add(a[i].y, 1);
  memset(BIT ::tr, 0, sizeof BIT ::tr);
  sort(a + 1, a + 1 + n, cmp2);
  for (int i = 1; i <= n; i += 1)
    r[a[i].id] += BIT ::query(2 * n) - BIT ::query(a[i].y),
        BIT ::add(a[i].x, 1);
  long long ans = 1ll * n * (n - 1) * (n - 2) / 6;
  for (int i = 1; i <= n; i += 1) ans -= 1ll * l[i] * r[i];
  long long res = 0;
  for (int i = 1; i <= n; i += 1)
    res += 1ll * (l[i] + r[i]) * (n - l[i] - r[i] - 1);
  cout << ans - res / 2 << endl;
  return 0;
}
