#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long ln, lk, lm;
int B;
int match[100005 * 2];
vector<pair<int, int>> vp;
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first / B == b.first / B) return a.second < b.second;
  return a.first / B < b.first / B;
}
int nowl = 1, nowr = 0;
int inner, cross;
void del(int k) {
  if (nowl <= match[k] && match[k] <= nowr) {
    inner--;
    cross++;
  } else
    cross--;
}
void add(int k) {
  if (nowl <= match[k] && match[k] <= nowr) {
    inner++;
    cross--;
  } else
    cross++;
}
int main() {
  scanf("%d", &n);
  B = sqrt(n + n);
  int a, b;
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    scanf("%d%d", &a, &b);
    if (a > b) swap(a, b);
    match[a] = b;
    match[b] = a;
    vp.push_back({a, b});
  }
  sort(vp.begin(), vp.end(), cmp);
  long long ans = (long long)n * (n - 1) * (n - 2) / 6, sc = 0, w = 0;
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    while (nowl < vp[i].first) del(nowl++);
    while (nowl > vp[i].first) add(--nowl);
    while (nowr < vp[i].second) add(++nowr);
    while (nowr > vp[i].second) del(nowr--);
    sc += (long long)cross * (n - 1 - cross);
    w += (long long)(inner - 1) * (n - cross - inner);
  }
  printf("%lld\n", ans - sc / 2 - w);
  return 0;
}
