#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000 + 10;
const int NUM = 20;
int n, len;
int a[MAX], b[MAX], to[MAX];
struct Node {
  Node *lc, *rc;
  int sum;
} tree[MAX * NUM], *root[MAX];
int cnt;
Node* newnode() {
  Node* p = tree + (cnt++);
  p->lc = p->rc = 0;
  p->sum = 0;
  return p;
}
Node* add(Node* u, int l, int r, int first) {
  Node* p = newnode();
  if (u) *p = *u;
  ++p->sum;
  if (l != r) {
    int mid = (l + r) / 2;
    if (first <= mid)
      p->lc = add(u ? u->lc : 0, l, mid, first);
    else
      p->rc = add(u ? u->rc : 0, mid + 1, r, first);
  }
  return p;
}
int ask(Node* u, int l, int r, int a, int b) {
  if (r < a || b < l || !u || a > b) return 0;
  if (a <= l && r <= b) return u->sum;
  int mid = (l + r) / 2;
  return ask(u->lc, l, mid, a, b) + ask(u->rc, mid + 1, r, a, b);
}
int ask(int a, int b, int c, int d) {
  return ask(root[b], 1, len, c, d) - ask(root[a - 1], 1, len, c, d);
}
int main() {
  int i;
  scanf("%d", &n);
  for ((i) = (1); (i) <= (n); ++(i)) {
    scanf("%d%d", &a[i], &b[i]);
    to[a[i]] = b[i];
    to[b[i]] = a[i];
  }
  len = 2 * n;
  for ((i) = (1); (i) <= (len); ++(i))
    root[i] = add(root[i - 1], 1, len, to[i]);
  long long ans = (long long)n * (n - 1) * (n - 2) / 3;
  for ((i) = (1); (i) <= (n); ++(i)) {
    if (a[i] > b[i]) swap(a[i], b[i]);
    int in = ask(a[i] + 1, b[i] - 1, b[i] + 1, len) +
             ask(a[i] + 1, b[i] - 1, 1, a[i] - 1);
    ans -= (long long)in * (n - 1 - in);
  }
  ans /= 2;
  for ((i) = (1); (i) <= (n); ++(i)) {
    int l = ask(a[i] + 1, b[i] - 1, a[i] + 1, b[i] - 1) / 2;
    int r = ask(1, a[i] - 1, 1, a[i] - 1) + ask(1, a[i] - 1, b[i] + 1, len) +
            ask(b[i] + 1, len, 1, a[i] - 1) + ask(b[i] + 1, len, b[i] + 1, len);
    r /= 2;
    ans -= (long long)l * r;
  }
  cout << ans << endl;
  return 0;
}
