#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
 private:
  int n;
  vector<int> node;

 public:
  SegmentTree(int sz) {
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; i++) node[i + n - 1] = 1;
    for (int i = n - 2; i >= 0; i--)
      node[i] = node[2 * i + 1] + node[2 * i + 2];
  }
  void dec(int x) {
    x += (n - 1);
    node[x]--;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = node[2 * x + 1] + node[2 * x + 2];
    }
  }
  long long getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    long long vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    long long vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
  }
};
struct point {
  int x;
  int y;
};
int main() {
  long long n;
  cin >> n;
  vector<point> p(n);
  map<int, pair<int, int>> mp;
  set<int> aa;
  for (int i = 0; i < (n); i++) {
    cin >> p[i].x >> p[i].y;
    mp[p[i].x].first = max(mp[p[i].x].first, p[i].y);
  }
  int sz = 0;
  for (auto &pp : mp) {
    pp.second.second = sz++;
  }
  SegmentTree seg(sz);
  sort((p).begin(), (p).end(),
       [](point &l, point &r) { return l.y == r.y ? l.x < r.x : l.y < r.y; });
  long long ans = 0;
  long long pre = 0;
  long long idx = 0;
  queue<int> q;
  for (int i = 0; i < (n); i++) {
    if (pre == p[i].y) {
      ans += (seg.getsum(0, mp[p[i].x].second) - idx) *
             (seg.getsum(mp[p[i].x].second + 1, sz) + 1);
    } else {
      while (!q.empty()) {
        seg.dec(q.front());
        q.pop();
      }
      ans += (seg.getsum(0, mp[p[i].x].second) + 1) *
             (seg.getsum(mp[p[i].x].second + 1, sz) + 1);
    }
    if (mp[p[i].x].first == p[i].y) q.push(mp[p[i].x].second);
    pre = p[i].y;
    idx = seg.getsum(0, mp[p[i].x].second);
  }
  cout << ans << endl;
  return 0;
}
