#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Data {
  int x, y;
} f[200000 + 1109];
bool cmp(const Data &A, const Data &B) {
  return A.y > B.y || (A.y == B.y && A.x < B.x);
}
int a[200000 + 1109];
int LSH[200000 + 1109];
int NUM[200000 + 1109];
int b[200000 + 1109];
map<int, int> mp;
long long N;
long long Ans = 0;
long long C2(long long x) { return x * (x + 1) / 2; }
void ADD(int x, int y) {
  int i = x;
  while (i <= n) {
    a[i] += y;
    i += (i & (-i));
  }
}
int COUNT(int x) {
  int i = x, SUM = 0;
  while (i) {
    SUM += a[i];
    i -= (i & (-i));
  }
  return SUM;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &f[i].x, &f[i].y);
    LSH[i] = f[i].x;
  }
  sort(LSH + 1, LSH + 1 + n);
  m = unique(LSH + 1, LSH + 1 + n) - LSH - 1;
  N = m;
  for (int i = 1; i <= m; i++) mp[LSH[i]] = i;
  for (int i = 1; i <= n; i++) f[i].x = mp[f[i].x];
  sort(f + 1, f + 1 + n, cmp);
  for (int i = 1; i <= n; i++) b[f[i].x]++;
  for (int i = 1; i <= m; i++) ADD(i, 1);
  int l, r;
  for (int i = n; i >= 1; i--) {
    r = i;
    for (int j = i; j >= 1; j--) {
      l = j;
      if (f[j].y != f[j - 1].y) break;
    }
    Ans += N * (N + 1) / 2;
    Ans -= C2(COUNT(f[l].x - 1));
    for (int j = l + 1; j <= r; j++) {
      Ans -= C2(COUNT(f[j].x - 1) - COUNT(f[j - 1].x));
    }
    Ans -= C2(COUNT(m) - COUNT(f[r].x));
    for (int j = l; j <= r; j++) {
      b[f[j].x]--;
      if (b[f[j].x] == 0) ADD(f[j].x, -1), N--;
    }
    i = l;
  }
  printf("%I64d", Ans);
  return 0;
}
