#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long MAX = 200100;
long long n;
pair<long long, long long> t[MAX];
long long id = 1;
long long dp[MAX];
void add(long long x) {
  for (; x <= id; x += x & -x) {
    dp[x]++;
  }
}
long long sum(long long x) {
  long long res = 0;
  for (; x; x -= x & -x) {
    res += dp[x];
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n;
  map<long long, long long> scal;
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    cin >> t[i].first >> t[i].second;
    scal[t[i].first] = 0;
  }
  for (auto &el : scal) {
    el.second = id;
    id++;
  }
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    t[i].first = scal[t[i].first];
  }
  sort(t, t + n,
       [](pair<long long, long long> x, pair<long long, long long> y) {
         if (x.second != y.second) {
           return x.second > y.second;
         }
         return x.first < y.first;
       });
  long long res = 0;
  set<long long> secik;
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    if (i && t[i] == t[i - 1]) continue;
    if (secik.insert(t[i].first).second) add(t[i].first);
    long long przed = sum(t[i].first - 1);
    if (i != n - 1 && t[i].second == t[i + 1].second) {
      (przed, sum(t[i + 1].first - 1));
      res += (przed + 1) * (sum(t[i + 1].first - 1) - przed);
    } else {
      res += (przed + 1) * (((long long)(secik).size()) - przed);
    }
    (res, ((long long)(secik).size()));
  }
  cout << res << "\n";
}
