#include <bits/stdc++.h>
using namespace std;
int n, a[200005], tp, cnt, c[200005];
long long ans;
struct node {
  int x, y;
} s[200005];
map<int, int> ls;
bool cmp(node a, node b) { return a.x == b.x ? a.y > b.y : a.x < b.x; }
struct Node {
  long long tr[200005];
  void add(int i, long long v) {
    for (; i <= n; i += i & -i) tr[i] += v;
  }
  long long ask(int i) {
    long long sum = 0;
    for (; i; i -= i & -i) sum += tr[i];
    return sum;
  }
} A, B;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &s[i].x, &s[i].y);
    a[i] = s[i].y;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (!ls[a[i]]) ls[a[i]] = ++tp;
  }
  sort(s + 1, s + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    A.add(ls[s[i].y], 1);
    cnt++;
    int j = i;
    for (; s[j].x == s[i].x; j++) {
      int t = ls[s[j].y];
      long long x = cnt - A.ask(t - 1);
      B.add(t, x - c[t]);
      c[t] = x;
      ans += x;
      ans += B.ask(t - 1);
      long long tmp = B.ask(ls[s[j + 1].y]);
      if (s[j + 1].x == s[j].x) ans -= tmp;
    }
    i = j - 1;
  }
  cout << ans << endl;
  return 0;
}
