#include <bits/stdc++.h>
using namespace std;
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
int N;
int A[1000005];
int B[1000005];
long long P[1000005];
long long Q[1000005];
int Order[1000005];
void Init() {
  Get(N);
  for (int i = 1; i <= N; i++) {
    Get(A[i]);
    Get(B[i]);
    if (A[i] > B[i]) std::swap(A[i], B[i]);
    Order[i] = i;
  }
}
bool Cmp(int X, int Y) { return A[X] < A[Y]; }
int T[1000005];
int Ask(int X) {
  int Ans = 0;
  for (; X >= 1; X -= X & -X) Ans += T[X];
  return Ans;
}
void Add(int X, int D) {
  for (; X <= N + N; X += X & -X) T[X] += D;
}
long long Ans;
void Work() {
  Ans = 1ll * N * (N - 1) * (N - 2) / 6;
  sort(Order + 1, Order + N + 1, Cmp);
  for (int k = N, i; k >= 1; k--) {
    i = Order[k];
    P[i] = Ask(B[i]);
    Add(B[i], 1);
  }
  memset(T, 0, sizeof T);
  for (int k = 1, i; k <= N; k++) {
    i = Order[k];
    Q[i] = Ask(N + N - B[i] + 1);
    Add(N + N - B[i] + 1, 1);
  }
  memset(T, 0, sizeof T);
  for (int k = 1, i; k <= N; k++) {
    i = Order[k];
    Q[i] += Ask(A[i]);
    Add(B[i], 1);
  }
  memset(T, 0, sizeof T);
  for (int k = N, i; k >= 1; k--) {
    i = Order[k];
    Q[i] += Ask(N + N - B[i] + 1);
    Add(N + N - A[i] + 1, 1);
  }
  for (int k = 1; k <= N; k++) Ans -= P[k] * Q[k];
  long long Ans2 = 0;
  for (int k = 1; k <= N; k++) Ans2 += (P[k] + Q[k]) * (N - P[k] - Q[k] - 1);
  Ans -= (Ans2 >> 1);
}
void Output() { printf("%I64d\n", Ans); }
int main() {
  Init();
  Work();
  Output();
  return 0;
}
