#include <bits/stdc++.h>
using namespace std;
int x[200010], y[200010], C[200010], n;
struct Q {
  int x, y;
} A[200010];
vector<int> B[200010];
int cmp(Q l, Q r) {
  if (l.x == r.x) return l.y > r.y;
  return l.x < r.x;
}
long long sum[2][200010];
void update(int u, int v, int id) {
  for (; u <= n; u += u & -u) sum[id][u] += v;
}
long long query(int u, int id) {
  long long ans = 0;
  for (; u; u -= u & -u) ans += sum[id][u];
  return ans;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &A[i].x, &A[i].y);
    x[i] = A[i].x;
    y[i] = A[i].y;
  }
  sort(x + 1, x + 1 + n);
  sort(y + 1, y + 1 + n);
  for (i = 1; i <= n; i++) {
    A[i].x = lower_bound(x + 1, x + 1 + n, A[i].x) - x;
    A[i].y = lower_bound(y + 1, y + 1 + n, A[i].y) - y;
  }
  sort(A + 1, A + 1 + n, cmp);
  for (i = 1; i <= n; i++) B[A[i].x].push_back(A[i].y);
  int k = 0, j;
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    if (B[i].size()) {
      k++;
      update(B[i][0], 1, 0);
      for (j = 0; j < B[i].size(); j++) {
        int v = B[i][j];
        update(v, -C[v], 1);
        C[v] = k - query(v - 1, 0);
        update(v, C[v], 1);
        ans += C[v];
        ans += query(v - 1, 1);
        if (j + 1 != B[i].size()) ans -= query(B[i][j + 1], 1);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
