#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int MAXN = 100007;
int n, l[MAXN], r[MAXN];
const int INSERT_EVENT = 0;
const int QUERY_EVENT = 1;
struct Event {
  int at;
  int type, idx;
  Event(int at, int type, int idx) : at(at), type(type), idx(idx) {}
  bool operator<(const Event &o) const { return at < o.at; }
};
int startPointLeft[MAXN], breakPointLeft[MAXN];
int startPointRight[MAXN], breakPointRight[MAXN];
int BIT1[MAXN * 4];
int BIT2[MAXN * 4];
void add(int x, int y, int BIT[]) {
  ++x;
  while (x <= 4 * n) {
    BIT[x] += y;
    x += x & -x;
  }
}
int sum(int x, int BIT[]) {
  ++x;
  int ret = 0;
  while (x) {
    ret += BIT[x];
    x -= x & -x;
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l[i], &r[i]);
    if (l[i] > r[i]) swap(l[i], r[i]);
    --l[i], --r[i];
  }
  memset(BIT1, 0, sizeof(BIT1));
  memset(BIT2, 0, sizeof(BIT2));
  vector<Event> events;
  for (int i = 0; i < n; i++) {
    events.push_back(Event(l[i], QUERY_EVENT, i));
    events.push_back(Event(r[i], INSERT_EVENT, i));
    add(l[i], 1, BIT1);
    add(r[i], 1, BIT2);
  }
  sort(events.begin(), events.end());
  for (typeof(events.begin()) e = events.begin(); e != events.end(); e++) {
    int i = e->idx;
    if (e->type == INSERT_EVENT) {
    } else {
      add(l[i], -1, BIT1);
      add(r[i], -1, BIT2);
      startPointRight[e->idx] = sum(r[i], BIT1) - sum(l[i], BIT1);
      breakPointRight[e->idx] = sum(r[i], BIT2) - sum(l[i], BIT2);
      add(r[i], 1, BIT1);
      add(l[i], 1, BIT2);
    }
  }
  memset(BIT1, 0, sizeof(BIT1));
  memset(BIT2, 0, sizeof(BIT2));
  events.clear();
  for (int i = 0; i < n; i++) {
    events.push_back(Event(r[i], QUERY_EVENT, i));
    events.push_back(Event(l[i], INSERT_EVENT, i));
    add(r[i] + n * 2, 1, BIT2);
    add(l[i] + n * 2, 1, BIT1);
  }
  sort(events.begin(), events.end());
  reverse(events.begin(), events.end());
  for (typeof(events.begin()) e = events.begin(); e != events.end(); e++) {
    int i = e->idx;
    if (e->type == INSERT_EVENT) {
    } else {
      add(l[i] + n * 2, -1, BIT1);
      add(r[i] + n * 2, -1, BIT2);
      startPointLeft[e->idx] =
          sum(r[i] + n * 2, BIT1) - sum(l[i] + n * 2, BIT1);
      startPointLeft[e->idx] = sum(4 * n - 1, BIT1) - startPointLeft[e->idx];
      breakPointLeft[e->idx] =
          sum(r[i] + n * 2, BIT2) - sum(l[i] + n * 2, BIT2);
      breakPointLeft[e->idx] = sum(4 * n - 1, BIT2) - breakPointLeft[e->idx];
      add(r[i] + n * 2, 1, BIT1);
      add(l[i] + n * 2, 1, BIT2);
    }
  }
  long long notCross = 0, cross = 0;
  for (int i = 0; i < n; i++) {
    notCross += breakPointLeft[i] * (long long)breakPointRight[i];
    cross += (startPointRight[i] - breakPointRight[i]) *
             (long long)breakPointLeft[i];
    cross +=
        (startPointLeft[i] - breakPointLeft[i]) * (long long)breakPointRight[i];
  }
  assert(cross % 2 == 0);
  cout << n * (n - 1ll) * (n - 2ll) / 6 - notCross - cross / 2 << endl;
  return 0;
}
