#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int len = 2 * N;
int n, cnt;
int fwk[2 * len], used[len];
long long ans;
map<int, int> mp;
pair<int, int> pt[N];
void add(int x) {
  for (x; x < len; x += (x & -x)) fwk[x]++;
}
int get(int x) {
  int ret = 0;
  for (x; x > 0; x -= (x & -x)) ret += fwk[x];
  return ret;
}
int query(int l, int r) { return get(r) - get(l - 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> pt[i].first >> pt[i].second;
    mp[pt[i].first]++;
    mp[pt[i].second]++;
  }
  for (auto &p : mp) {
    p.second = ++cnt;
  }
  for (int i = 1; i <= n; i++) {
    pt[i].first = mp[pt[i].first];
    pt[i].second = mp[pt[i].second];
  }
  for (int i = 1; i <= n; i++) {
    swap(pt[i].first, pt[i].second);
  }
  sort(pt + 1, pt + n + 1);
  pt[n + 1].first = pt[n].first;
  vector<int> vc;
  for (int i = n; i >= 1; i--) {
    if (pt[i].first == pt[i + 1].first)
      vc.push_back(pt[i].second);
    else {
      sort(vc.begin(), vc.end());
      int p = 0;
      for (auto c : vc) {
        if (!used[c]) {
          add(c);
          used[c]++;
        }
      }
      for (auto c : vc) {
        ans += 1ll * query(p, c) * query(c, 2 * N);
        p = c + 1;
      }
      vc.clear();
      vc.push_back(pt[i].second);
    }
  }
  sort(vc.begin(), vc.end());
  int p = 0;
  for (auto c : vc) {
    if (!used[c]) {
      add(c);
      used[c]++;
    }
  }
  for (auto c : vc) {
    ans += 1ll * query(p, c) * query(c, 2 * N);
    p = c + 1;
  }
  vc.clear();
  cout << ans;
  return 0;
}
