#include <bits/stdc++.h>
using namespace std;
struct node {
  int ch[2];
  int sum, v, fa;
} t[2000010];
int tot;
void update(int x) {
  int l = t[x].ch[0], r = t[x].ch[1];
  t[x].sum = ((l) ? t[l].sum : 0) + ((r) ? t[r].sum : 0) + 1;
}
int identify(int x) { return t[t[x].fa].ch[1] == x; }
void connect(int x, int fa, int son) { t[x].fa = fa, t[fa].ch[son] = x; }
void crepoint(int v, int fa, int son) {
  t[++tot].v = v;
  t[tot].sum = 1;
  connect(tot, fa, son);
}
void rotate(int x) {
  int y = t[x].fa;
  int mroot = t[y].fa;
  int yson = identify(x);
  int mson = identify(y);
  int z = t[x].ch[yson ^ 1];
  connect(z, y, yson);
  connect(y, x, yson ^ 1);
  connect(x, mroot, mson);
  update(y), update(x);
}
void splay(int x, int to) {
  to = t[to].fa;
  while (t[x].fa != to) {
    int up = t[x].fa;
    if (t[up].fa == to)
      rotate(x);
    else if (identify(x) == identify(up))
      rotate(up), rotate(x);
    else
      rotate(up), rotate(x);
  }
}
int find(int x, int v) {
  int nxt = t[x].v < v;
  if (!t[x].ch[nxt] || t[x].v == v) return x;
  return find(t[x].ch[nxt], v);
}
void push(int v) {
  int x = find(t[0].ch[1], v);
  if (t[x].v == v)
    splay(x, t[0].ch[1]);
  else {
    if (t[x].v > v)
      crepoint(v, x, 0);
    else
      crepoint(v, x, 1);
    splay(tot, t[0].ch[1]);
  }
}
int lesser(int v) {
  push(v);
  int ans = ((t[t[0].ch[1]].ch[0]) ? t[t[t[0].ch[1]].ch[0]].sum : 0);
  return ans;
}
struct point {
  int x, y;
} p[2000010];
bool cmp(point a, point b) {
  if (a.y == b.y) return a.x < b.x;
  return a.y > b.y;
}
int r[2000010], at;
int main() {
  t[0].v = -2000000000 - 1;
  push(-2000000000), push(2000000000);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].x, &p[i].y);
  sort(p + 1, p + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    push(p[i].x);
    r[0] = -2000000000;
    r[at = 1] = p[i].x;
    while (p[i + 1].y == p[i].y) {
      ++i;
      push(p[i].x);
      r[++at] = p[i].x;
    }
    r[++at] = 2000000000;
    for (int j = 1; j <= at; j++) {
      int tmp = lesser(r[j]) - lesser(r[j - 1]);
      ans -= 1ll * tmp * (tmp - 1) / 2;
    }
    int tmp = lesser(2000000000);
    ans += 1ll * tmp * (tmp - 1) / 2;
  }
  printf("%I64d", ans);
  return 0;
}
