#include <bits/stdc++.h>
using namespace std;
int N, st[210000], en[210000], id[210000];
int in[210000], out[210000], cross[210000];
int sum[210000];
bool cmp(int u, int v) { return en[u] < en[v]; }
int bit[210000];
int calc(int u) {
  int ans = 0;
  while (u < 210000) {
    ans += bit[u];
    u += u & -u;
  }
  return ans;
}
void update(int u, int x) {
  while (u) {
    bit[u] += x;
    u -= u & -u;
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d%d", &st[i], &en[i]);
  for (int i = 0; i < N; i++) {
    if (st[i] > en[i]) swap(st[i], en[i]);
    sum[st[i]]++;
    sum[en[i]]++;
  }
  for (int i = 1; i <= N * 2; i++) sum[i] += sum[i - 1];
  for (int i = 0; i < N; i++) id[i] = i;
  sort(id, id + N, cmp);
  for (int i = 0; i < N; i++) {
    int u = id[i];
    in[u] = calc(st[u]);
    cross[u] = sum[en[u]] - sum[st[u] - 1] - in[u] * 2 - 2;
    out[u] = N - 1 - in[u] - cross[u];
    update(st[u], 1);
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans -= (long long)in[i] * out[i];
    ans += (long long)in[i] * (in[i] - 1) / 2;
    ans += (long long)out[i] * (out[i] - 1) / 2;
    ans += (long long)cross[i] * (cross[i] - 1) / 2;
  }
  ans -= (long long)N * (N - 1) * (N - 2) / 6;
  ans /= 2;
  printf("%I64d\n", ans);
  return 0;
}
