#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 3e5 + 10;
int n, ls[maxn];
long long ans, vis[maxn];
long long c[maxn];
int lowbit(int x) { return x & (-x); }
long long sum(int x) {
  long long ret = 0;
  for (int i = x; i; i -= lowbit(i)) ret += c[i];
  return ret;
}
void add(int x) {
  for (int i = x; i <= n; i += lowbit(i)) c[i] += 1;
}
struct Node {
  int x, y;
  bool operator<(const Node A) const { return y == A.y ? x < A.x : y > A.y; }
} a[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    ls[i] = a[i].x;
  }
  sort(a, a + n);
  sort(ls, ls + n);
  for (int i = 0; i < n; i++) a[i].x = lower_bound(ls, ls + n, a[i].x) - ls + 1;
  for (int i = 0; i < n; i++) {
    if (!vis[a[i].x]) add(a[i].x), vis[a[i].x] = 1;
    long long l = sum(a[i].x);
    long long r = sum(n) - sum(a[i].x) + 1;
    if (i != n - 1 && a[i].y == a[i + 1].y)
      r = sum(a[i + 1].x - 1) - sum(a[i].x) + 1;
    ans += l * r;
  }
  printf("%lld\n", ans);
}
