#include <bits/stdc++.h>
using namespace std;
long long N, M, K;
vector<int> vy, vx;
vector<pair<int, int>> v;
set<int> s;
int tree[1231231];
void add(int x, int v) {
  while (x <= N) {
    tree[x] += v;
    x += (x & -x);
  }
}
int get(int x) {
  int res = 0;
  while (x) {
    res += tree[x];
    x -= (x & -x);
  }
  return res;
}
int sum(int x, int y) {
  if (x > y) return 0;
  return get(y) - get(x - 1);
}
map<int, int> h;
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < (N); ++i) {
    int x, y;
    cin >> x >> y;
    vy.push_back(y);
    v.push_back(make_pair(y, x));
    vx.push_back(x);
  }
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  for (int i = 0; i < ((int)(vx).size()); ++i) {
    h[vx[i]] = i + 1;
  }
  for (int i = 0; i < ((int)(v).size()); ++i) {
    v[i].second = h[v[i].second];
  }
  reverse(vy.begin(), vy.end());
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  int ind = 0;
  long long ret = 0;
  for (auto y : vy) {
    set<int> sx;
    while (ind < (int)(v).size() && v[ind].first >= y) {
      sx.insert(v[ind].second);
      ++ind;
    }
    int last = 0;
    for (auto x : sx) {
      long long val = sum(last + 1, x - 1);
      ret -= 1LL * val * (val + 1) / 2;
      last = x;
    }
    long long val = sum(last + 1, N);
    ret -= 1LL * val * (val + 1) / 2;
    for (auto x : sx) {
      if (s.find(x) == s.end()) {
        add(x, 1);
      }
    }
    s.insert(sx.begin(), sx.end());
    ret += 1LL * (int)(s).size() * ((int)(s).size() + 1) / 2;
  }
  cout << ret << endl;
}
