#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename S37, typename... Args>
void err(istream_iterator<string> it, S37 a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const long long N = 300100, mod = 1e9 + 7, mod2 = 1e9 + 9, mod3 = 998244353,
                sq = 450, base = 37, lg = 25, inf = 1e18 + 10, del = 79589;
long long n, m, x, y, z, w, X, Y, Z, W, t, k, q, ans;
map<long long, long long> mp;
set<long long> s;
pair<long long, long long> p[N];
vector<long long> v[N];
void add(long long xx) {
  while (xx < N) {
    mp[xx]++;
    xx += (xx) & (-xx);
  }
}
long long sum(long long xx, long long yy = 0) {
  while (xx > 0) {
    yy += mp[xx];
    xx -= (xx) & (-xx);
  }
  return yy;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> p[i].second >> p[i].first, s.insert(p[i].second);
  while (!s.empty()) {
    x = *s.begin();
    s.erase(x);
    mp[x] = ++t;
  }
  for (int i = 0; i < n; i++) p[i].second = mp[p[i].second];
  t = 0;
  mp.clear();
  for (int i = 0; i < n; i++) s.insert(p[i].first);
  while (!s.empty()) {
    x = *s.begin();
    s.erase(x);
    mp[x] = ++t;
  }
  for (int i = 0; i < n; i++) p[i].first = mp[p[i].first];
  mp.clear();
  for (int i = 0; i < n; i++) v[p[i].first].push_back(p[i].second);
  for (int i = N - 1000; i >= 0; i--) {
    if (v[i].size() == 0) continue;
    sort(v[i].begin(), v[i].end());
    for (int j = 0; j < v[i].size(); j++)
      if (s.find(v[i][j]) == s.end()) y++, s.insert(v[i][j]), add(v[i][j]);
    ans += y * (y + 1) / 2;
    x = 0;
    for (int j = 0; j < v[i].size(); j++) {
      w = sum(v[i][j] - 1) - sum(x);
      ans -= w * (w + 1) / 2;
      x = v[i][j];
    }
    w = sum(N - 1) - sum(x);
    ans -= w * (w + 1) / 2;
  }
  cout << ans;
  return 0;
}
