#include <bits/stdc++.h>
using namespace std;
int n;
int xs[200000];
pair<int, int> points[200010];
int bit[200010];
bool used[200010];
long long sum(int x) {
  int sum = 0;
  for (; x > 0; x -= x & -x) sum += bit[x];
  return sum;
}
void add(int x) {
  for (; x <= n; x += x & -x) bit[x]++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    points[i] = {-y, x};
    xs[i] = x;
  }
  sort(points, points + n);
  sort(xs, xs + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    auto p = points[i];
    int index = upper_bound(xs, xs + n, p.second) - xs;
    if (!used[index]) {
      add(index);
      used[index] = true;
    }
    if (i == n - 1 || p.first != points[i + 1].first) {
      ans += sum(index) * (sum(n) - sum(index) + 1);
    } else {
      int index2 = upper_bound(xs, xs + n, points[i + 1].second) - xs;
      ans += sum(index) * (sum(index2 - 1) - sum(index) + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
