#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
unordered_map<int, int> m;
int arr[400005];
int x[400005];
int y[400005];
set<int> s;
vector<int> level[400005];
set<int> s1;
int table[400005] = {0};
int n;
void compress() {
  int t = 1;
  for (auto it = s.begin(); it != s.end(); it++) {
    int no = *it;
    m[no] = t;
    t++;
  }
}
int pref_sum(int i) {
  int sum = 0;
  while (i > 0) {
    sum += table[i];
    i -= i & -i;
  }
  return sum;
}
int sum(int l, int r) {
  if (l > r) return 0;
  return pref_sum(r) - pref_sum(l - 1);
}
void update(int i, int delta) {
  if (sum(i, i) != 0) return;
  while (i <= 400002) {
    table[i] += delta;
    i += (i & -i);
  }
}
int main() {
  cin >> n;
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    s.insert(x[i]);
    s.insert(y[i]);
  }
  compress();
  for (int i = 0; i < n; i++) {
    x[i] = m[x[i]];
    y[i] = m[y[i]];
    level[y[i]].push_back(x[i]);
  }
  long long int ans = 0;
  for (int i = 400003; i >= 1; i--) {
    sort(level[i].begin(), level[i].end());
    long long int temp = 0;
    int x = level[i].size();
    if (level[i].size() > 0) {
      long long int points1 = sum(1, level[i][0] - 1);
      long long int points2 = sum(level[i][x - 1] + 1, 400002);
      temp += (points1 * (points1 + 1)) / 2;
      temp += (points2 * (points2 + 1)) / 2;
    } else
      continue;
    for (int j = 0; j < x - 1; j++) {
      if (level[i][j] == level[i][j + 1] || level[i][j] + 1 == level[i][j + 1])
        continue;
      int low = level[i][j] + 1;
      int high = level[i][j + 1] - 1;
      long long int p = sum(low, high);
      temp += (p * (p + 1)) / 2;
    }
    for (int j = 0; j < x; j++) {
      update(level[i][j], 1);
    }
    long long int total_points = sum(1, 400002);
    ans += (total_points * (total_points + 1)) / 2;
    ans -= temp;
  }
  cout << ans << endl;
  return 0;
}
