#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
void build() {}
int BIT[404040], n;
int lb(int x) { return x & (-x); }
void modify(int x, int dlt) {
  for (int i = x; i < 404040; i += lb(i)) BIT[i] += dlt;
}
int query(int x) {
  int ret = 0;
  for (int i = x; i; i -= lb(i)) ret += BIT[i];
  return ret;
}
int a[404040], b[404040];
void init() {
  n = getint();
  for (int i = 0; i < n; i++) {
    a[i] = getint();
    b[i] = getint();
    if (a[i] > b[i]) swap(a[i], b[i]);
  }
}
int cc[404040][2];
void solve() {
  vector<pair<pair<int, int>, pair<int, int>>> vv;
  for (int i = 0; i < n; i++) {
    vv.push_back({{b[i], a[i]}, {-1, 0}});
    vv.push_back({{a[i] + n + n, b[i]}, {-1, 0}});
    vv.push_back({{b[i] + n + n, a[i] + n + n}, {-1, 0}});
    vv.push_back({{b[i], a[i]}, {i, 0}});
    vv.push_back({{a[i] + n + n, b[i]}, {i, 1}});
  }
  sort(vv.begin(), vv.end());
  int tmp = 0;
  for (auto j : vv) {
    if (j.second.first == -1) {
      modify(j.first.second, 1);
      tmp++;
      continue;
    }
    int i = j.second.first;
    int which = j.second.second;
    cc[i][which] = tmp - query(j.first.second);
  }
  long long ans = (long long)n * (n - 1) * (n - 2) / 6;
  long long iii = 0, ix = 0;
  for (int i = 0; i < n; i++) {
    iii += (long long)cc[i][0] * cc[i][1];
    long long inter = n - 1 - cc[i][0] - cc[i][1];
    ix += (long long)inter * (cc[i][0] + cc[i][1]);
  }
  ans = ans - iii - ix / 2;
  cout << ans << endl;
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
