#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long N = 200005;
const long long M = 1000000007;
const long long INF = 1e12;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
vector<long long> v[N];
set<long long> s;
long long fen[N];
void add(long long x, long long n) {
  while (x < n) {
    fen[x] += 1;
    x += (x & (-x));
  }
  return;
}
long long get(long long x) {
  long long ans = 0;
  while (x > 0) {
    ans += fen[x];
    x -= (x & (-x));
  }
  return ans;
}
long long A[N][2];
vector<long long> X;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> m1;
  long long ans = 0;
  map<long long, vector<long long> > m;
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    A[i][0] = x;
    A[i][1] = y;
    X.push_back(x);
  }
  sort(X.begin(), X.end());
  long long cnt = 1;
  for (auto i : X) {
    if (m1.count(i) == 0) {
      m1[i] = cnt;
      cnt++;
    }
  }
  for (long long i = 0; i < n; i++) {
    m[A[i][1]].push_back(m1[A[i][0]]);
  }
  for (auto i = m.rbegin(); i != m.rend(); i++) {
    for (auto j : i->second) {
      if (s.find(j) == s.end()) {
        add(j, cnt);
        s.insert(j);
      }
    }
    sort(i->second.begin(), i->second.end());
    long long last = 0, tot = 0;
    long long sz = s.size();
    for (auto j : i->second) {
      long long l = get(last);
      long long r = get(j);
      tot += (r - l);
      ans += (r - l) * (sz - tot + 1);
      last = j;
    }
  }
  cout << ans << "\n";
  return 0;
}
