#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
} a[200010];
map<int, int> mp;
bool cmp1(point x, point y) { return x.x < y.x; }
bool cmp2(point x, point y) { return x.y != y.y ? x.y > y.y : x.x < y.x; }
int tree[200010], b[200010], n;
int lowbit(int x) { return (-x) & x; }
int sum(int x) {
  int ans = 0;
  while (x) {
    ans += tree[x];
    x -= lowbit(x);
  }
  return ans;
}
void add(int x) {
  while (x <= n) {
    tree[x]++;
    x += lowbit(x);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  sort(a + 1, a + n + 1, cmp1);
  for (int i = 1; i <= n; i++) {
    mp[a[i].x] = i;
  }
  sort(a + 1, a + n + 1, cmp2);
  a[n + 1].y = 0x7fffffff;
  long long ans = 0;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!b[mp[a[i].x]]) {
      b[mp[a[i].x]] = 1;
      add(mp[a[i].x]);
      cnt++;
    }
    int tmp = sum(mp[a[i].x]);
    ans += 1LL * tmp *
           (sum(a[i].y != a[i + 1].y ? n : mp[a[i + 1].x]) - tmp + 1 -
            (int)(a[i].y == a[i + 1].y && b[mp[a[i + 1].x]]));
  }
  cout << ans << endl;
  return 0;
}
