#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T, class U>
inline void print(T first, U second) {
  printsp(first);
  println(second);
}
template <class T, class U, class V>
inline void print(T first, U second, V z) {
  printsp(first);
  printsp(second);
  println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
const int E = 200020;
int B[E], in[E], out[E], dis[E], nn;
pair<int, int> p[E];
void update(int u) {
  for (; u < nn; u += u & -u) B[u]++;
}
int calc(int u) {
  int ans = 0;
  for (; u; u -= u & -u) ans += B[u];
  return ans;
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
void solve_E() {
  int n;
  gn(n);
  nn = n * 2 + 1;
  for (int i = 1; i <= n; i++) {
    gn(p[i].first, p[i].second);
    if (p[i].first > p[i].second) swap(p[i].first, p[i].second);
  }
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    in[i] = calc(p[i].second) - calc(p[i].first);
    update(p[i].first);
    dis[i] = p[i].second - p[i].first - 1 - in[i] * 2;
    out[i] = n - in[i] - dis[i] - 1;
  }
  long long first = 0, second = 0, z = 0;
  for (int i = 1; i <= n; i++) {
    first += (long long)in[i] * out[i];
    second += (long long)dis[i] * (dis[i] - 1) / 2;
    z += (long long)in[i] * (in[i] - 1) / 2 +
         (long long)out[i] * (out[i] - 1) / 2;
  }
  println((second + z - first - (long long)n * (n - 1) * (n - 2) / 6) / 2);
  exit(0);
}
int main() {
  solve_E();
  return 0;
}
