#include <bits/stdc++.h>
template <typename T>
void scan(T &x) {
  x = 0;
  register bool _ = 0;
  register T c = getchar();
  _ = c == 45;
  c = _ ? getchar() : c;
  while (c < 48 || c > 57) c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
  x = _ ? -x : x;
}
template <typename T>
void printn(T n) {
  register bool _ = 0;
  _ = n < 0;
  n = _ ? -n : n;
  char snum[65];
  int i = 0;
  do {
    snum[i++] = n % 10 + 48;
    n /= 10;
  } while (n);
  --i;
  if (_) putchar(45);
  while (i >= 0) putchar(snum[i--]);
}
template <typename First, typename... Ints>
void scan(First &arg, Ints &...rest) {
  scan(arg);
  scan(rest...);
}
template <typename T>
void print(T n) {
  printn(n);
  putchar(10);
}
template <typename First, typename... Ints>
void print(First arg, Ints... rest) {
  printn(arg);
  putchar(32);
  print(rest...);
}
using namespace std;
const int MM = 2e5 + 5;
long long ans;
int n, bit[MM], ln[MM], rn[MM];
bool done[MM];
int last[MM];
map<int, int> mp;
struct st {
  int x, y;
} a[MM];
void add(int i) {
  i = MM - i;
  for (; i < MM; i += i & -i) bit[i]++;
}
void sub(int i) {
  i = MM - i;
  for (; i < MM; i += i & -i) bit[i]--;
}
int query(int i) {
  i = MM - i;
  int ret = 0;
  for (; i > 0; i -= i & -i) ret += bit[i];
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].y;
    mp[a[i].y] = 0;
  }
  int t = 0;
  for (auto &x : mp) x.second = ++t;
  sort(a, a + n, [](st x, st y) {
    if (x.x != y.x) return x.x < y.x;
    return x.y < y.y;
  });
  for (int i = 0; i < n; i++) {
    a[i].y = mp[a[i].y];
    if (i && a[i].x == a[i - 1].x) {
      sub(a[i - 1].y);
      add(a[i].y);
    } else {
      add(a[i].y);
    }
    ln[i] = query(a[i].y);
    int tp = ln[i];
    if (last[a[i].y]) {
      ln[i] -= last[a[i].y];
    }
    last[a[i].y] = tp;
  }
  memset(bit, 0, sizeof bit);
  for (int i = n - 1; i >= 0; i--) {
    if (i != n - 1 && a[i + 1].x == a[i].x) {
    } else {
      add(a[i].y);
    }
    rn[i] = query(a[i].y);
    ans += (long long)ln[i] * rn[i];
  }
  cout << ans << '\n';
  return 0;
}
