#include <bits/stdc++.h>
using namespace std;
int dadsadasda;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;
long long BIT[MAXN];
void updBIT(int p, long long val) {
  p++;
  for (; p < MAXN; p += p & -p) BIT[p] += val;
}
long long sumBIT(int p) {
  p++;
  long long ret = 0;
  for (; p; p -= p & -p) ret += BIT[p];
  return ret;
}
long long sum(int l, int r) {
  if (r < l) return 0;
  if (l == 0)
    return sumBIT(r);
  else
    return sumBIT(r) - sumBIT(l - 1);
}
void comprimir(vector<pair<int, int> > &a) {
  int n = (int)a.size();
  set<int> val;
  map<int, int> h;
  for (int i = 0; i < n; i++) val.insert(a[i].first);
  int pos = 0;
  for (auto e : val) h[e] = ++pos;
  for (int i = 0; i < n; i++) a[i].first = h[a[i].first];
  val.clear();
  for (int i = 0; i < n; i++) val.insert(a[i].second);
  pos = 0;
  for (auto e : val) h[e] = ++pos;
  for (int i = 0; i < n; i++) a[i].second = h[a[i].second];
}
long long C2(long long n) { return n * (n + 1) / 2; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  comprimir(a);
  vector<pair<int, int> > he[n + 1];
  for (int i = 0; i < n; i++) he[a[i].second].push_back(a[i]);
  long long ans = 0;
  for (int i = n; i > 0; i--) {
    for (pair<int, int> p : he[i])
      if (!sum(p.first, p.first)) updBIT(p.first, 1);
    sort(he[i].begin(), he[i].end());
    long long sumT = C2(sum(1, n));
    int prev = 0;
    for (pair<int, int> p : he[i]) {
      sumT -= C2(sum(prev + 1, p.first - 1));
      prev = p.first;
    }
    sumT -= C2(sum(prev + 1, n));
    ans += sumT;
  }
  cout << ans << '\n';
  return 0;
}
