#include <bits/stdc++.h>
const int N = 400005;
std::vector<std::pair<int*, int>> query[N];
std::vector<int> modify[N];
int n, l[N], r[N], bit[N];
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n;
  for (int i = 1; i <= n; ++i) {
    int a, b;
    std::cin >> a >> b;
    if (a > b) std::swap(a, b);
    query[b - 1].emplace_back(l + i, a + 1);
    query[a + 2 * n - 1].emplace_back(r + i, b + 1);
    modify[b].emplace_back(a);
    modify[a + 2 * n].emplace_back(b);
    modify[b + 2 * n].emplace_back(a + 2 * n);
  }
  for (int i = 1; i <= 4 * n; ++i) {
    for (int p : modify[i])
      for (int j = p; j; j &= j - 1) ++bit[j];
    for (auto p : query[i])
      for (int j = p.second; j <= 4 * n; j += j & -j) *p.first += bit[j];
  }
  long long s0 = (long long)n * (n - 1) * (n - 2) / 6, s1 = 0;
  for (int i = 1; i <= n; ++i)
    s0 -= (long long)l[i] * r[i],
        s1 += (long long)(n - 1 - l[i] - r[i]) * (l[i] + r[i]);
  std::cout << s0 - s1 / 2 << '\n';
  return 0;
}
