#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
map<int, vector<int>> s;
int lowbit(int x) { return x & -x; };
map<int, int> bit;
void add(int x, int v) {
  while (x <= 1e9) {
    bit[x] += v;
    x += lowbit(x);
  }
}
int que(int x) {
  int sum = 0;
  while (x > 0) {
    sum += bit[x];
    x -= lowbit(x);
  }
  return sum;
}
long long f(int x) { return 1ll * x * (x + 1) / 2; }
int main() {
  int n;
  while (cin >> n) {
    s.clear();
    for (int i = 1; i <= n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      s[-y].push_back(x);
    }
    bit.clear();
    long long ans = 0;
    for (auto &a : s) {
      vector<int> &vec = a.second;
      sort(vec.begin(), vec.end());
      for (int i = 1; i < vec.size(); i++) {
        ans -= f(que(vec[i] - 1) - que(vec[i - 1]));
      }
      ans -= f(que(vec[0] - 1));
      ans -= f(que(1e9) - que(vec.back()));
      for (int i = 0; i < vec.size(); i++) {
        if (que(vec[i]) == que(vec[i] - 1)) add(vec[i], 1);
      }
      ans += f(que(1e9));
    }
    cout << ans << endl;
  }
  return 0;
}
