#include <bits/stdc++.h>
using namespace std;
int n, m;
long long ans;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
struct point {
  int x, y;
  bool operator<(const point &a) const { return y > a.y; }
} p[200005], tp[200005];
bool cmp(point a, point b) { return a.x < b.x; }
int v[200005];
bool vis[200005];
struct bits_array {
  int c[200005];
  void change(int i, int v) {
    for (; i <= n; i += i & -i) c[i] += v;
  }
  int query(int i) {
    int ret = 0;
    for (; i; i -= i & -i) ret += c[i];
    return ret;
  }
} bits_l, bits_r;
void solve(int l, int r) {
  if (l > r) return;
  int mid = (l + r) >> 1, midl = mid, midr = mid;
  while (midl > l && p[midl - 1].x == p[midl].x) --midl;
  while (midr < r && p[midr + 1].x == p[midr].x) ++midr;
  if (midl == l && midr == r) {
    ans += r - l + 1;
    return;
  }
  if (midl == l)
    mid = midr;
  else
    mid = midl - 1;
  int cnt = 0, resl = 0, resr = 0;
  for (int i = l; i <= r; i++) tp[++cnt] = p[i];
  sort(tp + 1, tp + cnt + 1);
  for (int i = 1; i <= cnt; i++) v[i] = tp[i].x;
  sort(v + 1, v + cnt + 1);
  int pps = unique(v + 1, v + cnt + 1) - v - 1;
  for (int i = 1; i <= cnt; i++)
    tp[i].x = lower_bound(v + 1, v + pps + 1, tp[i].x) - v;
  int line = lower_bound(v + 1, v + pps + 1, p[mid].x) - v;
  for (int l = 1, r = 1; l <= cnt; l = r) {
    int mn = n + 1, mx = 0;
    while (r <= cnt && tp[r].y == tp[l].y) {
      if (tp[r].x <= line) {
        if (!vis[tp[r].x]) vis[tp[r].x] = 1, bits_l.change(tp[r].x, 1), ++resl;
        mx = max(mx, tp[r].x);
      } else {
        if (!vis[tp[r].x]) vis[tp[r].x] = 1, bits_r.change(tp[r].x, 1), ++resr;
        mn = min(mn, tp[r].x);
      }
      ++r;
    }
    ans += 1ll * resl * resr;
    ans -= 1ll * (resl - bits_l.query(mx)) * bits_r.query(mn - 1);
  }
  for (int i = 1; i <= cnt; i++) {
    if (tp[i].x <= line) {
      if (vis[tp[i].x]) vis[tp[i].x] = 0, bits_l.change(tp[i].x, -1);
    } else {
      if (vis[tp[i].x]) vis[tp[i].x] = 0, bits_r.change(tp[i].x, -1);
    }
  }
  solve(l, mid), solve(mid + 1, r);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read();
  sort(p + 1, p + n + 1, cmp);
  solve(1, n);
  cout << ans << endl;
  return 0;
}
