#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long Hashimoto = 0;
  bool Kanna = 1;
  char I_Love = getchar();
  while (I_Love < '0' || I_Love > '9') {
    if (I_Love == '-') Kanna = 0;
    I_Love = getchar();
  }
  while (I_Love >= '0' && I_Love <= '9') {
    Hashimoto = Hashimoto * 10 + I_Love - '0';
    I_Love = getchar();
  }
  return (Kanna ? Hashimoto : -Hashimoto);
}
template <typename T1, typename T2>
inline void Umax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void Umin(T1 &a, T2 b) {
  if (a > b) a = b;
}
int n;
int xa[211111], ya[211111];
vector<int> num[211111];
vector<int> X, Y;
void pre() {
  n = read();
  for (int i = 0; i < (n); ++i) {
    xa[i] = read();
    ya[i] = read();
    X.push_back(xa[i]);
    Y.push_back(ya[i]);
  }
  sort(X.begin(), X.end());
  ;
  X.erase(unique(X.begin(), X.end()), X.end());
  ;
  sort(Y.begin(), Y.end());
  ;
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  ;
  for (int i = 0; i < (n); ++i) {
    int a = lower_bound(X.begin(), X.end(), xa[i]) - X.begin();
    int b = lower_bound(Y.begin(), Y.end(), ya[i]) - Y.begin();
    num[b].push_back(a);
  }
}
struct node {
  node *ls, *rs;
  int vl, pr, sz;
};
void update(node *x) {
  x->sz = 1;
  if (x->ls) x->sz += x->ls->sz;
  if (x->rs) x->sz += x->rs->sz;
}
node *merge(node *x, node *y) {
  if (x == NULL) return y;
  if (y == NULL) return x;
  if (x->pr > y->pr) {
    x->rs = merge(x->rs, y);
    update(x);
    return x;
  } else {
    y->ls = merge(x, y->ls);
    update(y);
    return y;
  }
}
pair<node *, node *> split(node *root, int x) {
  if (root == NULL) return {NULL, NULL};
  if (root->vl >= x) {
    pair<node *, node *> ret = split(root->ls, x);
    root->ls = ret.second;
    update(root);
    return {ret.first, root};
  } else {
    pair<node *, node *> ret = split(root->rs, x);
    root->rs = ret.first;
    update(root);
    return {root, ret.second};
  }
}
void insert(node *&root, node *x) {
  pair<node *, node *> ret = split(root, x->vl);
  node *nroot = merge(ret.first, merge(x, ret.second));
  root = nroot;
}
void erase(node *&root, int x) {
  pair<node *, node *> p1 = split(root, x);
  pair<node *, node *> p2 = split(p1.second, x + 1);
  node *nroot = merge(p1.first, p2.second);
  root = nroot;
}
int find(node *&root, int x) {
  int ans = 0;
  if (root->ls) {
    if (root->vl > x)
      return find(root->ls, x);
    else
      ans += root->ls->sz;
  }
  if (root->vl == x) {
    return ans;
  }
  ans++;
  return find(root->rs, x) + ans;
}
node pool[2222222], *node_maker = pool;
set<int> s;
int ran = 19990203;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  pre();
  node *root = node_maker++;
  root->ls = root->rs = NULL;
  root->sz = 1;
  root->vl = -1;
  ran = (ran * 7ll + 20031025ll) % (1000000007ll);
  root->pr = ran;
  long long ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (num[i].size() == 0) continue;
    sort(num[i].begin(), num[i].end());
    for (int j = 0; j < (num[i].size()); ++j) {
      if (s.find(num[i][j]) == s.end()) {
        s.insert(num[i][j]);
        node *nnode = node_maker++;
        nnode->ls = nnode->rs = NULL;
        nnode->sz = 1;
        nnode->vl = num[i][j];
        ran = (ran * 7ll + 20031025ll) % (1000000007ll);
        nnode->pr = ran;
        insert(root, nnode);
      }
    }
    int lastpos = -1;
    for (int j = 0; j < (num[i].size()); ++j) {
      int pos = find(root, num[i][j]) - 1;
      long long len1 = pos - lastpos, len2 = (s.size() - pos);
      ans += len1 * len2;
      lastpos = pos;
    }
  }
  cout << ans << endl;
  return 0;
}
