#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
  return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 212345;
map<long long, int> cx;
int n, m, k;
map<long long, vector<int> > p;
map<int, bool> mrk;
map<int, bool> sorted;
int bit[MAXN];
void upd(int i, int val) {
  i += 2;
  while (i < MAXN) {
    bit[i] += val;
    i += (i & -i);
  }
}
int qry(int i) {
  i += 2;
  int ans = 0;
  while (i > 0) {
    ans += bit[i];
    i -= (i & -i);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  vector<pair<long long, long long> > s(n);
  vector<long long> X;
  for (int a = 0; a < n; a++) {
    long long i, j;
    scanf("%lld%lld", &i, &j);
    s[a] = {i, j};
    X.push_back(i);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  for (int i = 0; i < X.size(); i++) cx[X[i]] = i;
  for (int a = 0; a < n; a++) {
    p[s[a].second].push_back(cx[s[a].first]);
  }
  for (int a = 0; a < n; a++) {
    if (sorted[s[a].second]) continue;
    sorted[s[a].second] = true;
    sort(p[s[a].second].begin(), p[s[a].second].end());
  }
  int sz = 0;
  long long res = 0;
  for (auto it = p.rbegin(); it != p.rend(); it++) {
    int y = it->first;
    ;
    vector<int> points = it->second;
    long long nsz = sz + points.size();
    for (int x : points) {
      if (mrk[x]) {
        nsz--;
        upd(x, -1);
      }
    }
    res += nsz * nsz;
    ;
    long long jafoi = 0;
    for (int x : points) {
      long long bef = qry(x);
      res -= (bef + 1 - jafoi) * bef;
      ;
      jafoi = bef + 1;
      mrk[x] = true;
      upd(x, 1);
    }
    res -= (nsz - jafoi) * nsz;
    ;
    sz = nsz;
  }
  printf("%lld\n", res);
}
