#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)2e5 + 7;
int tree[N << 1];
void update(int x, int n) {
  x += n;
  if (tree[x]) return;
  while (x) {
    tree[x]++;
    x >>= 1;
  }
}
int query(int l, int r, int n) {
  int re = 0;
  l += n, r += n;
  while (l <= r) {
    if (l & 1) re += tree[l++];
    if (~r & 1) re += tree[r--];
    l >>= 1, r >>= 1;
  }
  return re;
}
pair<int, int> p[N];
vector<int> x;
int l[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d%d", &p[i].first, &p[i].second);
    x.push_back(p[i].first);
  }
  sort((x).begin(), (x).end());
  sort(p, p + n);
  for (int i = (0); i < (n); ++i) {
    p[i].first = lower_bound((x).begin(), (x).end(), p[i].first) - x.begin();
    swap(p[i].first, p[i].second);
  }
  sort(p, p + n);
  long long ans = 0;
  for (int i = n - 1, j; i >= 0; i = j) {
    for (j = i; j >= 0 && p[i].first == p[j].first; j--)
      ;
    int z = 0;
    for (int k = (j + 1); k < (i + 1); ++k) {
      l[k] = query(z, p[k].second - 1, n);
      update(p[k].second, n);
      z = p[k].second + 1;
    }
    for (int k = (j + 1); k < (i + 1); ++k) {
      ans += (long long)(l[k] + 1) * (query(p[k].second + 1, n, n) + 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
