#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
pair<int, int> a[N];
int tr[N], p[N], i, j, n, t, k;
map<int, bool> mp;
long long ans;
void add(int second) {
  for (; second <= n; second += second & -second) tr[second]++;
}
int query(int second) {
  int s = 0;
  for (; second; second ^= second & -second) s += tr[second];
  return s;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d%d", &a[i].second, &a[i].first), a[i].first = -a[i].first,
                                              p[i] = a[i].second;
  sort(a + 1, a + n + 1);
  sort(p + 1, p + n + 1);
  for (i = 1; i <= n; i++)
    a[i].second = lower_bound(p + 1, p + n + 1, a[i].second) - p;
  for (i = 1; i <= n; i++) {
    if (!mp[a[i].second]) mp[a[i].second] = 1, add(a[i].second);
    j = query(a[i].second),
    k = (a[i].first == a[i + 1].first ? query(a[i + 1].second - 1)
                                      : mp.size()) -
        j + 1;
    ans += 1ll * j * k;
  }
  printf("%lld", ans);
}
