#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 2;
int n, fen[N], used[N];
pair<int, int> a[N];
long long ans;
set<int> st;
vector<int> vec;
void upd(int pos, int val) {
  for (; pos < N; pos |= pos + 1) fen[pos] += val;
}
int get(int r) {
  int ret = 0;
  for (; r > 0; r = (r & (r + 1)) - 1) ret += fen[r];
  return ret;
}
int get(int l, int r) {
  if (l > r) return 0;
  return get(r) - get(l - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].second, &a[i].first);
    vec.push_back(a[i].first);
    vec.push_back(a[i].second);
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (int i = 1; i <= n; i++) {
    a[i].first =
        lower_bound(vec.begin(), vec.end(), a[i].first) - vec.begin() + 1;
    a[i].second =
        lower_bound(vec.begin(), vec.end(), a[i].second) - vec.begin() + 1;
  }
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; i--) {
    int pt = i;
    set<int> f;
    f.insert(a[pt].second);
    while (pt - 1 > 0 && a[pt - 1].first == a[i].first) {
      pt--;
      f.insert(a[pt].second);
    }
    vec.clear();
    for (auto x : f) {
      vec.push_back(x);
    }
    int val;
    if (vec.size()) {
      for (int i = 1; i < vec.size(); i++) {
        int val = get(vec[i - 1] + 1, vec[i] - 1);
        ans -= (val + 1) * 1ll * val / 2;
      }
      val = get(1, vec[0] - 1);
      ans -= (val + 1) * 1ll * val / 2;
      val = get(vec.back() + 1, N - 1);
      ans -= (val + 1) * 1ll * val / 2;
      for (int x : vec) {
        if (!used[x]) upd(x, 1);
        used[x] = 1;
        st.insert(x);
      }
    }
    val = st.size();
    ans += (val + 1) * 1ll * val / 2;
    i = pt;
  }
  cout << ans << endl;
}
