#include <bits/stdc++.h>
using namespace std;
struct line {
  int x, y, id;
} p[100010];
int tot, n, ord[200010], q[200010], Fl[200010], flag;
long long ans, sum1, sum2, sum3, sum4, L[200010], Ls[200010], Rs[200010];
bool vis[200010];
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
void Change() {
  tot = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i].x > p[i].y) swap(p[i].x, p[i].y);
    q[p[i].x] = i;
    q[p[i].y] = i;
    p[i].id = i;
  }
}
inline bool cmp1(line A, line B) {
  if (A.x == B.x) return A.y < B.y;
  return A.x < B.x;
}
inline bool cmp3(line A, line B) { return A.id < B.id; }
inline bool cmp2(int A, int B) {
  if (p[A].y == p[B].y) return p[A].x < p[B].x;
  return p[A].y < p[B].y;
}
void Do(int &cnt, int x) {
  if (Fl[x] != flag) Fl[x] = flag, vis[x] = 0;
  vis[x] ^= 1;
  if (vis[x])
    cnt++;
  else
    cnt--;
}
void Get(long long *ans) {
  sort(p + 1, p + n + 1, cmp1);
  int Block = sqrt(n) * 2, pre = 0, end;
  for (;;) {
    end = min(n, pre + Block);
    pre++;
    if (pre > end) break;
    sort(ord + pre, ord + end + 1, cmp2);
    int L = 1, R = 0, cnt = 0;
    flag++;
    for (int i = pre; i <= end; i++) {
      int l = p[ord[i]].x, r = p[ord[i]].y;
      for (int j = R + 1; j <= r; j++) Do(cnt, q[j]);
      for (int j = L - 1; j >= l; j--) Do(cnt, q[j]);
      for (int j = R; j > r; j--) Do(cnt, q[j]);
      for (int j = L; j < l; j++) Do(cnt, q[j]);
      L = l;
      R = r;
      ans[p[ord[i]].id] = cnt;
    }
    pre = end;
  }
}
inline long long C2(long long x) { return x * (x - 1) / 2; }
int main() {
  read(n);
  if (n < 3) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    read(p[i].x);
    read(p[i].y);
  }
  for (int i = 1; i <= 2 * n; i++) ord[i] = i;
  Change();
  Get(L);
  sort(p + 1, p + n + 1, cmp3);
  for (int i = 1; i <= n; i++) {
    Ls[i] = p[i].y - p[i].x;
    Rs[i] = n * 2 - 1 - Ls[i];
    Ls[i] = (Ls[i] - L[i]) >> 1;
    Rs[i] = (Rs[i] - L[i]) >> 1;
  }
  for (int i = 1; i <= n; i++) {
    sum1 += Ls[i] * Rs[i];
    sum2 += C2(Ls[i]) + C2(Rs[i]);
    sum3 += L[i] * (Ls[i] + Rs[i]);
    sum4 += C2(L[i]);
  }
  sum3 /= 2;
  ans = (sum2 + sum4 - sum1 * 2 - sum3) / 3;
  printf("%I64d\n", ans);
  return 0;
}
