#include <bits/stdc++.h>
using namespace std;
struct Fenwick {
  int n;
  vector<int> arr;
  Fenwick(int n) : n(n), arr(n + 1) {}
  void update(int i, int x) {
    for (i++; i <= n; i += i & -i) arr[i] += x;
  }
  int query(int i) {
    int acc = 0;
    for (; i > 0; i -= i & -i) acc += arr[i];
    return acc;
  }
};
constexpr int maxn = 4e5 + 1;
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<array<long long, 2>> arr(n);
  vector<long long> cr(2 * n);
  for (long long i = 0; i < n; i++)
    cin >> arr[i][0] >> arr[i][1], cr[2 * i] = arr[i][0],
                                          cr[2 * i + 1] = arr[i][1];
  sort((cr).begin(), (cr).end());
  cr.resize(unique((cr).begin(), (cr).end()) - cr.begin());
  vector<vector<long long>> g(maxn);
  for (long long i = 0; i < n; i++) {
    arr[i][0] = lower_bound((cr).begin(), (cr).end(), arr[i][0]) - cr.begin();
    arr[i][1] = lower_bound((cr).begin(), (cr).end(), arr[i][1]) - cr.begin();
    g[arr[i][1]].push_back(arr[i][0]);
  }
  vector<bool> ex(maxn);
  Fenwick fw(maxn);
  long long res = 0;
  reverse((g).begin(), (g).end());
  for (vector<long long>& xs : g) {
    if (xs.empty()) continue;
    sort((xs).begin(), (xs).end());
    for (long long x : xs)
      if (!ex[x]) fw.update(x, 1), ex[x] = true;
    for (long long i = 0; i < xs.size() - 1; i++)
      if (xs[i] != xs[i + 1]) {
        long long c = fw.query(xs[i + 1]) - fw.query(xs[i] + 1);
        res -= c * (c + 1) / 2;
      }
    long long c = fw.query(xs[0]);
    res -= c * (c + 1) / 2;
    c = fw.query(fw.n) - fw.query(xs.back() + 1);
    res -= c * (c + 1) / 2;
    c = fw.query(fw.n);
    res += c * (c + 1) / 2;
  }
  cout << res << "\n";
}
