#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = (int)5e5 + 5;
int n;
struct node {
  int x, y;
} a[MAXN];
struct BIT {
  long long sum[MAXN];
  int n;
  void init(int _n) {
    n = _n;
    memset(sum, 0, sizeof(sum));
    ;
  }
  int lowbit(int x) { return x & -x; }
  void update(int x, long long num) {
    while (x <= n) {
      sum[x] += num;
      x += lowbit(x);
    }
    return;
  }
  long long query(int x) {
    long long ans = 0;
    while (x) {
      ans += sum[x];
      x -= lowbit(x);
    }
    return ans;
  }
} bita;
vector<int> v;
int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }
map<int, int> mpx;
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++)
      scanf("%d%d", &a[i].x, &a[i].y), v.push_back(a[i].x), v.push_back(a[i].y);
    sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
    for (int i = 1; i <= n; i++) {
      a[i].x = getid(a[i].x);
      a[i].y = getid(a[i].y);
    }
    sort(a + 1, a + 1 + n, [](node a, node b) {
      if (a.y != b.y) return a.y > b.y;
      return a.x < b.x;
    });
    mpx.clear();
    bita.init(MAXN);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      int xx = a[i].x, yy = a[i].y, pre = 0;
      int now = i;
      while (a[now].y == a[i].y && now <= n) {
        if (!mpx[a[now].x]) {
          mpx[a[now].x] = 1;
          bita.update(a[now].x, 1ll);
        }
        now++;
      }
      now--;
      for (int j = i; j <= now; j++) {
        long long l = bita.query(a[j].x - 1) - bita.query(pre);
        long long r = bita.query(2 * n + 1) - bita.query(a[j].x);
        pre = a[j].x;
        ans += (long long)l * r + l + r + 1;
      }
      i = now;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
