#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 69;
int n;
pair<int, int> P[N], P1[N];
long long ans;
int A[N], fix[N];
void upd(int pos) {
  while (pos <= 4e5) {
    A[pos] += 1;
    pos += (pos & -pos);
  }
}
int get(int pos) {
  int ans = 0;
  while (pos) {
    ans += A[pos];
    pos -= (pos & -pos);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> P[i].first >> P1[i].first;
    P[i].second = i;
  }
  sort(P + 1, P + 1 + n);
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    if (P[i].first == P[i - 1].first) {
      P1[P[i].second].second = P1[P[i - 1].second].second;
    } else {
      tot++;
      P1[P[i].second].second = tot;
    }
  }
  sort(P1 + 1, P1 + 1 + n);
  reverse(P1 + 1, P1 + 1 + n);
  for (int i = 1; i <= n;) {
    int j = i;
    while (P1[i].first == P1[j].first && j <= n) {
      j++;
    }
    long long last = 0;
    for (int t = j - 1; t >= i; t--) {
      if (fix[P1[t].second] == 0) {
        upd(P1[t].second);
        fix[P1[t].second] = 1;
      }
    }
    for (int t = j - 1; t >= i; t--) {
      long long x = get(P1[t].second);
      long long sul = get(4e5);
      ans += (x - last) * (sul - x + 1);
      last = x;
    }
    i = j;
  }
  cout << ans << endl;
}
