#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> x;
vector<int> st;
bool cmp(const pair<int, int> &p1, const pair<int, int> &p2) {
  if (p1.second > p2.second) {
    return true;
  }
  if (p1.second == p2.second && p1.first < p2.first) {
    return true;
  }
  return false;
}
void update(int v, int l, int r, int i) {
  if (i < l || i > r) {
    return;
  }
  if (l == r) {
    st[v] = 1;
    return;
  }
  int mid = l + (r - l) / 2;
  update(2 * v, l, mid, i);
  update(2 * v + 1, mid + 1, r, i);
  st[v] = st[2 * v] + st[2 * v + 1];
}
int query(int v, int l, int r, int ql, int qr) {
  if (qr < l || ql > r) {
    return 0;
  }
  if (ql <= l && qr >= r) {
    return st[v];
  }
  int mid = l + (r - l) / 2;
  return query(2 * v, l, mid, ql, qr) + query(2 * v + 1, mid + 1, r, ql, qr);
}
void update(int xi) {
  int i_xi = lower_bound(x.begin(), x.end(), xi) - x.begin();
  update(1, 0, n - 1, i_xi);
}
pair<int, int> query(int l, int mid) {
  int i_l = lower_bound(x.begin(), x.end(), l) - x.begin();
  int i_mid = lower_bound(x.begin(), x.end(), mid) - x.begin();
  return {query(1, 0, n - 1, i_l, i_mid), query(1, 0, n - 1, i_mid, n - 1)};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<pair<int, int> > p(n);
  x = vector<int>(n);
  st = vector<int>(4 * n);
  unordered_set<int> x_set;
  for (int i = 0, j = 0; i < n; ++i) {
    cin >> p[i].first >> p[i].second;
    if (x_set.count(p[i].first) == 0) {
      x_set.insert(p[i].first);
      x[j++] = p[i].first;
    }
  }
  sort(x.begin(), x.end());
  sort(p.begin(), p.end(), cmp);
  long long ans = 0;
  update(p[0].first);
  int j = 0;
  for (int i = 1; i < n; ++i) {
    if (p[i].second != p[i - 1].second) {
      int prev_x = 0;
      while (j < i) {
        auto res = query(prev_x + 1, p[j].first);
        ans += (long long)res.first * res.second;
        prev_x = p[j].first;
        ++j;
      }
    }
    update(p[i].first);
  }
  int prev_x = 0;
  while (j < n) {
    auto res = query(prev_x + 1, p[j].first);
    ans += (long long)res.first * res.second;
    prev_x = p[j].first;
    ++j;
  }
  cout << ans << '\n';
  return 0;
}
