#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int ch[maxn << 5][2], key[maxn << 5], num[maxn << 5];
int a[maxn], cnt;
int build(int l, int r) {
  if (l > r) return 0;
  int mid = (l + r) / 2, n = ++cnt;
  key[n] = a[mid];
  num[n] = r - l + 1;
  ch[n][0] = build(l, mid - 1);
  ch[n][1] = build(mid + 1, r);
  return n;
}
int root[maxn << 3];
void dfs(int n, int *arr, int &c) {
  if (!n) return;
  dfs(ch[n][0], arr, c);
  arr[++c] = key[n];
  dfs(ch[n][1], arr, c);
}
int b[maxn], c[maxn];
int rht[maxn << 3], lft[maxn << 3], pos[maxn << 1];
void buildt(int n, int l, int r) {
  lft[n] = l, rht[n] = r;
  if (l == r) {
    if (pos[l]) {
      a[1] = pos[l];
      root[n] = build(1, 1);
    } else
      root[n] = 0;
    return;
  }
  int mid = (lft[n] + rht[n]) / 2;
  buildt(n << 1, l, mid);
  buildt((n << 1) + 1, mid + 1, r);
  int n1 = 0, n2 = 0;
  dfs(root[n << 1], b, n1);
  dfs(root[(n << 1) + 1], c, n2);
  int nn = 0, i = 1, j = 1;
  while (i <= n1 || j <= n2) {
    if (i <= n1 && (j > n2 || b[i] < c[j]))
      a[++nn] = b[i++];
    else
      a[++nn] = c[j++];
  }
  root[n] = build(1, nn);
}
int get1(int n, int k) {
  int ans = 0;
  while (n) {
    if (key[n] <= k)
      ans += num[n] - num[ch[n][1]], n = ch[n][1];
    else
      n = ch[n][0];
  }
  return ans;
}
int get2(int n, int k) {
  int ans = 0;
  while (n) {
    if (key[n] >= k)
      ans += num[n] - num[ch[n][0]], n = ch[n][0];
    else
      n = ch[n][1];
  }
  return ans;
}
int get(int n, int l, int r, int ll, int rr) {
  if (l == lft[n] && r == rht[n])
    return get1(root[n], ll - 1) + get2(root[n], rr + 1);
  int mid = (lft[n] + rht[n]) / 2;
  if (r <= mid)
    return get(n << 1, l, r, ll, rr);
  else if (l > mid)
    return get((n << 1) + 1, l, r, ll, rr);
  return get(n << 1, l, mid, ll, rr) + get((n << 1) + 1, mid + 1, r, ll, rr);
}
int cc[maxn << 1];
int woca(int n) {
  int ans = 0;
  while (n) ans += cc[n], n -= n & (-n);
  return ans;
}
void upd(int n) {
  while (n <= 200000) cc[n]++, n += n & (-n);
}
struct NN {
  int l, r;
} nn[maxn];
int cmp(NN a, NN b) { return a.l < b.l; }
int S[maxn << 1], SS[maxn << 1];
int LL[maxn], RR[maxn];
int main() {
  int n, i, j, k;
  long long ans = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &LL[i], &RR[i]);
    if (LL[i] > RR[i]) swap(LL[i], RR[i]);
    pos[RR[i]] = LL[i];
    pos[LL[i]] = RR[i];
    S[LL[i]]++;
    SS[RR[i]]++;
    nn[i].l = LL[i], nn[i].r = RR[i];
  }
  for (i = 200000; i >= 1; i--) S[i] += S[i + 1];
  for (i = 1; i <= 200000; i++) SS[i] += SS[i - 1];
  sort(nn + 1, nn + 1 + n, cmp);
  buildt(1, 1, n * 2);
  for (i = 1; i <= n; i++) {
    long long t = 0;
    if (LL[i] + 1 <= RR[i] - 1) t = get(1, LL[i] + 1, RR[i] - 1, LL[i], RR[i]);
    ans += (n - 1 - t) * t;
  }
  ans /= 2;
  long long t = n, tt = n;
  t *= tt - 1;
  t *= tt - 2;
  t /= 6;
  t -= ans;
  for (i = n; i >= 1; i--) {
    t -= (S[nn[i].r + 1] + 0ll + SS[nn[i].l - 1] +
          get(1, 1, nn[i].l, -1, nn[i].r)) *
         woca(nn[i].r);
    upd(nn[i].r);
  }
  cout << t << endl;
}
