#include <bits/stdc++.h>
const int MAXN = 8e5 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 9;
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n;
typedef struct node {
  long long x, y, z;
} node;
int sz;
node d[MAXN];
vector<long long> vec;
bool vis[MAXN];
vector<int> ans[MAXN];
int get_id(int x) { return x & (-x); }
bool cmp(int x, int y) { return d[x].x < d[y].x; }
long long sum[MAXN];
void update(int x) {
  for (int i = x; i <= sz + 1; i += get_id(i)) sum[i]++;
}
long long query(int x) {
  long long ans1 = 0;
  for (int i = x; i > 0; i -= get_id(i)) ans1 += sum[i];
  return ans1;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    d[i].x = read(), d[i].y = read(), vec.push_back(d[i].x),
    vec.push_back(d[i].y), vec.push_back(d[i].x - 1);
  sort(vec.begin(), vec.end());
  sz = unique(vec.begin(), vec.end()) - vec.begin();
  for (int i = 1; i <= n; i++) {
    d[i].z = lower_bound(vec.begin(), vec.begin() + sz, d[i].x - 1) -
             vec.begin() + 1;
    d[i].x =
        lower_bound(vec.begin(), vec.begin() + sz, d[i].x) - vec.begin() + 1;
    d[i].y =
        lower_bound(vec.begin(), vec.begin() + sz, d[i].y) - vec.begin() + 1;
    ans[d[i].y].push_back(i);
  }
  for (int i = 1; i <= sz; i++) sort(ans[i].begin(), ans[i].end(), cmp);
  long long ans1 = 0;
  for (int i = sz; i >= 1; i--) {
    if (!ans[i].size()) continue;
    int last = 0;
    for (int j = 0; j < ans[i].size(); j++) {
      long long t1 = query(d[ans[i][j]].z) - query(last);
      ans1 -= 1ll * t1 * (t1 + 1) / 2;
      if (!vis[d[ans[i][j]].x]) vis[d[ans[i][j]].x] = 1, update(d[ans[i][j]].x);
      last = d[ans[i][j]].x;
    }
    long long t3 = query(sz + 1) - query(last);
    ans1 -= 1ll * t3 * (t3 + 1) / 2;
    long long t2 = query(sz + 1);
    ans1 += 1ll * t2 * (t2 + 1) / 2;
  }
  printf("%lld\n", ans1);
  return 0;
}
