#include <bits/stdc++.h>
using namespace std;
struct FenwickTree {
  vector<int> bit;
  int n;
  void build(vector<int> a) {
    n = a.size();
    bit.resize(n);
    for (int i = 0; i < a.size(); i++) add(i, a[i]);
  }
  int sum(int r) {
    int ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
  void add(int idx, int delta) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta;
  }
};
int main() {
  int n;
  cin >> n;
  map<int, vector<int> > m;
  map<int, int> mind;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    m[-y].push_back(x);
    s.insert(x);
  }
  set<int>::iterator itr;
  int ind = 1;
  for (itr = s.begin(); itr != s.end(); itr++) {
    mind[*itr] = ind;
    ++ind;
  }
  vector<int> temp(ind, 0);
  FenwickTree F;
  F.build(temp);
  s.clear();
  int cnt = 0;
  long long int ans = 0;
  map<int, vector<int> >::iterator it;
  for (it = m.begin(); it != m.end(); it++) {
    vector<int> t = it->second;
    for (int i = 0; i < t.size(); i++) t[i] = mind[t[i]];
    t.push_back(-1);
    sort(t.begin(), t.end());
    vector<int> temp;
    for (int i = 1; i < t.size(); i++) {
      int sum = F.sum(t[i - 1] + 1, t[i] - 1);
      temp.push_back(sum);
      if (s.find(t[i]) == s.end()) {
        s.insert(t[i]);
        F.add(t[i], 1);
      }
    }
    int sum = F.sum(t[t.size() - 1] + 1, ind - 1);
    temp.push_back(sum);
    int tot = F.sum(0, ind - 1);
    ans += (tot * 1LL * (tot + 1)) / 2;
    for (int i = 0; i < temp.size(); i++)
      ans -= (temp[i] * 1LL * (temp[i] + 1)) / 2;
  }
  cout << ans << endl;
}
