#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  bool operator<(const P &a) const {
    if (x != a.x) return x < a.x;
    return y < a.y;
  }
};
long long x, y, z, mod = 998244353;
vector<int> v;
int i, n, m, k, a, d, b, c;
int e;
int o[611111];
int l[1];
int j[1];
queue<int> q;
P u[211111];
map<int, int> p;
bool as(P a, P b) {
  if (a.y != b.y) return a.y > b.y;
  return a.x > b.x;
}
int f(int n, int m) {
  int k = 0;
  for (; n < m;) {
    if (n % 2)
      k += o[n], n++;
    else if (m % 2 == 0)
      k += o[m], m--;
    else
      n /= 2, m /= 2;
  }
  return o[n] + k;
}
int main() {
  scanf("%d", &a);
  for (int t = 1; t <= a; t++) {
    scanf("%d %d", &n, &m);
    u[t] = {n, m};
    v.push_back(n);
  }
  v.push_back(0);
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (int h = 1; h < v.size(); h++) p[v[h]] = h;
  for (i = 1; i < v.size(); i *= 2)
    ;
  sort(u + 1, u + a + 1, as);
  for (int t = 1; t <= a; t++) {
    int h = i + p[u[t].x] - 1;
    o[i + p[u[t].x] - 1] = 1;
    h /= 2;
    for (; h; h /= 2) o[h] = o[h * 2] + o[h * 2 + 1];
    int m = 1;
    if (u[t + 1].y == u[t].y) m = p[u[t + 1].x] + 1;
    x += (long long)f(i + m - 1, i + p[u[t].x] - 1) *
         f(i + p[u[t].x] - 1, i + v.size() - 2);
  }
  printf("%lld", x);
}
