#include <bits/stdc++.h>
using namespace std;
const long long N = 500001;
long long bit[2][N];
map<long long, long long> unq;
void update(long long idx, long long x) {
  if (idx == 0) {
    while (x) {
      bit[idx][x] += 1;
      x -= (x & -x);
    }
  } else {
    while (x < N) {
      bit[idx][x] += 1;
      x += (x & -x);
    }
  }
}
long long query(long long idx, long long pos) {
  long long ans = 0;
  if (idx == 0) {
    while (pos < N) {
      ans += bit[idx][pos];
      pos += (pos & -pos);
    }
  } else {
    while (pos) {
      ans += bit[idx][pos];
      pos -= (pos & -pos);
    }
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long ans = 0;
  vector<pair<long long, long long>> v(n);
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> v[i].second >> v[i].first;
    m[v[i].second] = 1;
    m[v[i].first] = 1;
  }
  long long c = 1;
  for (auto& it : m) {
    it.second = c;
    c++;
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < n; i++) {
    v[i].second = m[v[i].second];
    v[i].first = m[v[i].first];
  }
  set<long long> s;
  vector<long long> rn(n), ln(n);
  for (long long i = n - 1; i >= 0; i--) {
    if (unq[v[i].second] == 0) {
      update(0, v[i].second);
      unq[v[i].second] = 1;
    }
    rn[i] = query(0, v[i].second);
  }
  unq.clear();
  for (long long i = n - 1; i >= 0; i--) {
    long long j = i;
    for (; j >= 0; j--) {
      if (v[i].first != v[j].first) break;
      if (unq[v[j].second] == 0) {
        update(1, v[j].second);
        unq[v[j].second] = 1;
      }
    }
    for (long long k = i; k > j; k--) {
      ln[k] = query(1, v[k].second);
    }
    i = j + 1;
  }
  for (long long i = 0; i < n; i++) {
    long long j;
    long long prev = 0;
    for (j = i + 1; j < n; j++) {
      if (v[i].first != v[j].first) break;
      if (v[j].second != v[j - 1].second) {
        ans += rn[j - 1] * (ln[j - 1] - prev);
        prev = ln[j - 1];
      }
    }
    ans += rn[j - 1] * (ln[j - 1] - prev);
    i = j - 1;
  }
  cout << ans;
}
