#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
int n;
int tree[530000];
const int key = 262144;
pair<int, int> arr[200100];
vector<int> com;
set<int> se;
void upd(int idx) {
  idx += key;
  tree[idx] = 1;
  idx /= 2;
  while (idx) {
    tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
    idx /= 2;
  }
}
int getv(int s, int e) {
  s += key;
  e += key;
  int ans = 0;
  while (s <= e) {
    if (s & 1) ans += tree[s++];
    if (~e & 1) ans += tree[e--];
    s /= 2;
    e /= 2;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &arr[i].first, &arr[i].second);
    com.push_back(arr[i].first);
  }
  sort(com.begin(), com.end());
  com.erase(unique(com.begin(), com.end()), com.end());
  for (int i = 0; i < n; i++)
    arr[i].first =
        lower_bound(com.begin(), com.end(), arr[i].first) - com.begin();
  sort(arr, arr + n, [](pair<int, int> a, pair<int, int> b) {
    return a.second > b.second || (a.second == b.second && a.first < b.first);
  });
  int p = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i != n - 1 && arr[i].second == arr[i + 1].second) continue;
    for (int j = p; j <= i; j++) se.insert(arr[j].first);
    int s = se.size();
    ans += 1LL * s * (s + 1) / 2;
    for (int j = p; j <= i; j++) {
      int px = (j == p ? 0 : arr[j - 1].first + 1);
      int v = getv(px, arr[j].first - 1);
      ans -= 1LL * v * (v + 1) / 2;
      upd(arr[j].first);
    }
    int v = getv(arr[i].first + 1, (int)com.size() - 1);
    ans -= 1LL * v * (v + 1) / 2;
    p = i + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
