#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
pair<int, int> p[MAXN];
int a[MAXN], b[MAXN];
int n;
int lowbit(int x) { return x & -x; }
void add(int i, int val) {
  for (; i <= n; i += lowbit(i)) a[i] += val;
}
int get(int i) {
  int res = 0;
  for (; i; i -= lowbit(i)) res += a[i];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + n, [](const pair<int, int>& x, const pair<int, int>& y) {
    return x.first < y.first;
  });
  int idx = 0;
  for (int i = 0; i < n; i++) {
    if (!i || p[i].first != p[i - 1].first) idx++;
    a[i] = idx;
  }
  for (int i = 0; i < n; i++) {
    p[i].first = a[i];
  }
  sort(p, p + n, [](const pair<int, int>& x, const pair<int, int>& y) {
    return x.second > y.second || (x.second == y.second && x.first < y.first);
  });
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  int i = 0, j = 0;
  long long res = 0;
  while (i < n) {
    for (j = i; j < n && p[j].second == p[i].second; j++) {
      if (!b[p[j].first]) {
        add(p[j].first, 1);
        b[p[j].first] = 1;
      }
    }
    long long tmp = get(n);
    res += (tmp + 1) * tmp / 2;
    tmp = get(p[i].first - 1);
    res -= (tmp + 1) * tmp / 2;
    for (int ii = i + 1; ii < j; ii++) {
      tmp = get(p[ii].first - 1) - get(p[ii - 1].first);
      res -= (tmp + 1) * tmp / 2;
    }
    tmp = get(n) - get(p[j - 1].first);
    res -= (tmp + 1) * tmp / 2;
    i = j;
  }
  cout << res << endl;
  return 0;
}
