#include <bits/stdc++.h>
using namespace std;
const int MAXN(200001);
const int MAXE(5000010);
const int MAXK(100010);
const int MAXC(2);
const int INF((INT_MAX - 1) / 2);
const int BASE(20);
const double LIM(1e50);
const double EPS(1e-5);
const double PER(0.02);
const double MUL(3.5);
template <typename T>
inline bool checkmax(T &a, const T &b) {
  return b > a ? ((a = b), true) : false;
}
template <typename T>
inline bool checkmin(T &a, const T &b) {
  return b < a ? ((a = b), true) : false;
}
template <typename T>
inline T ABS(T a) {
  return a < 0 ? -a : a;
}
struct E {
  int v, i;
  friend bool operator<(const E &a, const E &b) { return a.v < b.v; }
};
struct BIT {
  long long arr[MAXN];
  int sz;
  void init(int sz) { this->sz = sz; }
  int lb(int i) { return i & -i; }
  void update(int i, long long v) {
    for (; i > 0; i -= lb(i)) arr[i] += v;
  }
  long long query(int i) {
    long long ret = 0;
    for (; i <= sz; i += lb(i)) ret += arr[i];
    return ret;
  }
} bi;
int L[MAXN];
int main() {
  int n, tn, l, r;
  scanf("%d", &n);
  tn = n * 2;
  bi.init(tn);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &l, &r);
    if (l > r) swap(l, r);
    L[r] = l;
  }
  long long a1 = 0, a2 = 0;
  for (int i = 1; i <= tn; ++i)
    if (L[i] != 0) {
      long long t = bi.query(L[i] + 1);
      long long inter = (i - L[i] - 1) - t * 2;
      a1 += t * ((tn - (i - L[i] + 1) - inter) / 2);
      a2 += inter * (n - 1 - inter);
      bi.update(L[i], 1);
    }
  a2 /= 2;
  long long ans = n;
  ans = ans * (ans - 1) * (ans - 2) / 6 - a1 - a2;
  cout << ans << endl;
  return 0;
}
