#include <bits/stdc++.h>
const long long MOD = 1e9 + 7, INF = 1e18 + 1;
using namespace std;
long long n, m, k, ptr;
long long sorted[1000000];
struct point {
  long long x, y;
  bool operator<(const point& b) const {
    return (y == b.y ? x < b.x : y > b.y);
  }
} a[1000000];
struct BIT {
  long long t[2000000];
  void update(long long x, long long d) {
    for (; x <= ptr; x = (x | (x + 1))) t[x] += d;
  }
  long long get(long long r) {
    long long sum = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) sum += t[r];
    return sum;
  }
  long long get(long long l, long long r) {
    if (l > r) return 0;
    return get(r) - get(l - 1);
  }
} t;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i].x, &a[i].y);
    sorted[ptr] = a[i].x;
    sorted[ptr + 1] = a[i].y;
    ptr += 2;
  }
  sort(a, a + n);
  sort(sorted, sorted + ptr);
  for (long long i = 0; i < n; i++) {
    a[i].x = lower_bound(sorted, sorted + ptr, a[i].x) - sorted;
    a[i].y = lower_bound(sorted, sorted + ptr, a[i].y) - sorted;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long one = t.get(0, a[i].x - 1) + 1;
    if (i + 1 == n || a[i + 1].y != a[i].y)
      one *= t.get(a[i].x + 1, ptr - 1) + 1;
    else
      one *= t.get(a[i].x + 1, a[i + 1].x - 1) + 1;
    ans += one;
    if (t.get(a[i].x, a[i].x) == 0) t.update(a[i].x, 1);
  }
  cout << ans;
}
