#include <bits/stdc++.h>
const int inf = 1039074182;
using namespace std;
int n;
int a[200005];
int h[200005];
int bit[400005];
int numh, numa;
vector<int> mh;
vector<int> ma;
int nn;
vector<int> vec[200005];
bool appear[200005];
void add(int x) {
  while (x <= nn) {
    bit[x]++;
    x += x & -x;
  }
}
int query(int x) {
  int res = 0;
  while (x) {
    res += bit[x];
    x &= x - 1;
  }
  return res;
}
int sum(int l, int r) {
  l++;
  r--;
  if (l > r) return 0;
  return query(r) - (l ? query(l - 1) : 0);
}
long long calc(int x) { return 1LL * x * (x + 1) / 2; }
int main() {
  cin >> n;
  nn = 1;
  while (nn < n) {
    nn <<= 1;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d%d", a + i, h + i);
  }
  for (int i = 0; i < n; i++) {
    ma.push_back(a[i]);
    mh.push_back(h[i]);
  }
  sort(ma.begin(), ma.end());
  sort(mh.begin(), mh.end());
  ma.erase(unique(ma.begin(), ma.end()), ma.end());
  mh.erase(unique(mh.begin(), mh.end()), mh.end());
  numa = ma.size();
  numh = mh.size();
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(ma.begin(), ma.end(), a[i]) - ma.begin() + 1;
  }
  for (int i = 0; i < n; i++) {
    vec[lower_bound(mh.begin(), mh.end(), h[i]) - mh.begin() + 1].push_back(
        a[i]);
  }
  for (int i = 1; i <= numh; i++) {
    sort(vec[i].begin(), vec[i].end());
  }
  long long res = 0;
  int size = 0;
  for (int height = numh; height >= 1; height--) {
    res -= calc(sum(0, vec[height].front()));
    for (int i = 0; i < (int)vec[height].size() - 1; i++) {
      res -= calc(sum(vec[height][i], vec[height][i + 1]));
    }
    res -= calc(sum(vec[height].back(), numa + 1));
    for (auto x : vec[height]) {
      if (appear[x]) continue;
      size++;
      appear[x] = true;
      add(x);
    }
    res += calc(size);
  }
  cout << res << endl;
  return 0;
}
