#include <bits/stdc++.h>
using namespace std;
const int intmax = 0x3f3f3f3f;
const long long lldmax = 0x3f3f3f3f3f3f3f3fll;
double eps = 1e-8;
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T lowbit(T n) {
  return (n ^ (n - 1)) & n;
}
template <class T>
inline int countbit(T n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
template <class T>
inline T checkmod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T euclid(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclid(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclid(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclid(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <class T>
inline int dblcmp(T a, const T b) {
  a -= b;
  return a > eps ? 1 : (a < -eps ? -1 : 0);
}
template <class T>
inline int sgn(T a) {
  return a > eps ? 1 : (a < -eps ? -1 : 0);
}
const int N = 4100000;
struct BIT {
  int a[N];
  int query(int p) {
    int ans = 0;
    for (; p; p = p & (p - 1)) ans += a[p];
    return ans;
  }
  int query(int s, int t) { return query(t) - query(s - 1); }
  void add(int p, int v) {
    for (; p < N; p += p & (-p)) a[p] += v;
  }
} bit;
int a[N], b[N];
int main() {
  long long n;
  int ta, tb;
  cin >> n;
  memset(bit.a, 0, sizeof(bit.a));
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &ta, &tb);
    if (ta > tb) swap(ta, tb);
    a[ta] = tb;
    a[tb] = ta;
    bit.add(ta, 1);
    bit.add(tb, -1);
  }
  long long ans = n * (n - 1) * (n - 2) / 6, sum = 0;
  for (int i = 1; i <= 2 * n; ++i) {
    long long q = bit.query(i, a[i]);
    long long l = a[i] - i - 1;
    sum += (l - q) / 2 * (2 * n - 2 - l - q) / 2;
    sum += (l - q) / 2 * q;
    bit.add(a[i], 2);
    bit.add(2 * n + i, -1);
    a[2 * n + i] = a[i];
    a[a[i]] = 2 * n + i;
  }
  cout << ans - sum / 2 << endl;
  return 0;
}
