#include <bits/stdc++.h>
using namespace std;
inline int getidx(const vector<int>& ar, int x) {
  return lower_bound(ar.begin(), ar.end(), x) - ar.begin();
}
inline long long GCD(long long a, long long b) {
  long long n;
  if (a < b) swap(a, b);
  while (b != 0) {
    n = a % b;
    a = b;
    b = n;
  }
  return a;
}
inline long long LCM(long long a, long long b) {
  if (a == 0 || b == 0) return GCD(a, b);
  return a / GCD(a, b) * b;
}
inline long long CEIL(long long n, long long d) {
  return n / d + (long long)(n % d != 0);
}
inline long long ROUND(long long n, long long d) {
  return n / d + (long long)((n % d) * 2 >= d);
}
const long long MOD = 1e9 + 7;
inline long long POW(long long a, long long n) {
  assert(0 <= n);
  long long ret;
  for (ret = 1; n; a = a * a % MOD, n /= 2) {
    if (n % 2) ret = ret * a % MOD;
  }
  return ret;
}
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << "[";
  int cnt = 0;
  for (auto vv : v) {
    os << vv;
    if (++cnt < v.size()) os << ",";
  }
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> v) {
  os << "[";
  int cnt = 0;
  for (auto vv : v) {
    os << vv;
    if (++cnt < v.size()) os << ",";
  }
  return os << "]";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
  return os << "(" << p.first << "," << p.second << ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H, debug_out(T...);
}
const int MAXN = 2e5 + 10;
struct fenwick {
  int n;
  vector<long long> t;
  void init(int _n) { n = _n, t = vector<long long>(n + 1, 0); }
  void add(int u, long long x) {
    for (++u; u < t.size(); u += (u & -u)) t[u] += x;
  }
  long long sum(int u) {
    long long ret = 0;
    for (++u; u > 0; u -= (u & -u)) ret += t[u];
    return ret;
  }
  long long sum(int u, int v) {
    if (u > v) return 0;
    return sum(v) - sum(u - 1);
  }
  long long sumfrom(int u) { return sum(n - 1) - sum(u); }
  long long operator[](int u) { return sum(u) - sum(u - 1); }
};
int n;
vector<pair<int, int> > pt;
vector<int> xs;
fenwick ft;
void input() {
  cin >> n;
  pt.resize(n);
  xs.resize(n);
  for (int(i) = (0); (i) < (int)(n); ++(i)) cin >> pt[i].first >> pt[i].second;
}
long long f(vector<int>& ar) {
  for (int i : ar) {
    int xidx = getidx(xs, pt[i].first);
    if (ft[xidx] == 0) ft.add(xidx, 1);
  }
  long long ans = ft.sum(ft.n - 1);
  ans = ans * (ans + 1) / 2;
  int pr = 0;
  for (int i : ar) {
    int idx = getidx(xs, pt[i].first);
    long long t = ft.sum(pr, idx - 1);
    t = t * (t + 1) / 2;
    ans -= t;
    pr = idx + 1;
  }
  long long t = ft.sum(pr, ft.n - 1);
  t = t * (t + 1) / 2;
  ans -= t;
  return ans;
}
int solve() {
  for (int(i) = (0); (i) < (int)(n); ++(i)) xs[i] = pt[i].first;
  sort(pt.begin(), pt.end(), [&](pair<int, int>& u, pair<int, int>& v) {
    if (u.second == v.second) return u.first < v.first;
    return u.second > v.second;
  });
  sort(xs.begin(), xs.end());
  (xs).resize(unique(xs.begin(), xs.end()) - (xs).begin());
  ft.init(xs.size() + 10);
  long long ans = 0;
  vector<int> ar;
  for (int(i) = (0); (i) < (int)(pt.size()); ++(i)) {
    if (ar.size() == 0 || pt[ar.back()].second == pt[i].second)
      ar.push_back(i);
    else
      ans += f(ar), ar.clear(), ar.push_back(i);
  }
  if (ar.size()) ans += f(ar);
  cout << ans << '\n';
  return 0;
}
void execute() { input(), solve(); }
int main(void) {
  cin.tie(0), ios_base::sync_with_stdio(false);
  execute();
  return 0;
}
