#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
void useiostream() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n;
struct point {
  int x, y;
  point() {}
  point(int a, int b) {
    x = a;
    y = b;
  }
  bool operator==(const point& a) const {
    if (x == a.x && y == a.y)
      return true;
    else
      return false;
  }
  bool operator>(const point& a) const {
    if (x > a.x)
      return true;
    else
      return false;
  }
  bool operator<(const point& a) const {
    if (x < a.x)
      return true;
    else
      return false;
  }
  bool operator>(const int& a) const {
    if (x > a)
      return true;
    else
      return false;
  }
  bool operator<(const int& a) const {
    if (x < a)
      return true;
    else
      return false;
  }
  bool operator>=(const point& a) const {
    if (x >= a.x)
      return true;
    else
      return false;
  }
  bool operator<=(const point& a) const {
    if (x <= a.x)
      return true;
    else
      return false;
  }
};
struct Node {
  int left, right, val;
  int mid() { return (left + right) >> 1; }
  Node() {}
  Node(int a, int b, int c) {
    left = a;
    right = b;
    val = c;
  }
} node[maxn << 2];
void build(int num, int left, int right) {
  node[num].left = left;
  node[num].right = right;
  node[num].val = 0;
  if (left == right) return;
  int m = node[num].mid();
  build(num << 1, left, m);
  build(num << 1 | 1, m + 1, right);
}
void pushup(int num) {
  if (num == 1) return;
  int fa = num / 2;
  int m = fa << 1;
  node[fa].val = node[m].val + node[m | 1].val;
  pushup(fa);
}
void add(int num, int val) {
  if (node[num].left == node[num].right && node[num].left == val) {
    if (node[num].val == 0) node[num].val = 1;
    pushup(num);
    return;
  }
  int m = node[num].mid();
  if (val <= m) {
    add(num << 1, val);
  } else {
    add(num << 1 | 1, val);
  }
}
long long find(int num, int l, int r) {
  long long sum = 0;
  if (r < l) return 0;
  if (l <= 0) return 0;
  if (r > n) return 0;
  if (node[num].left == l && node[num].right == r) {
    return node[num].val;
  }
  int m = node[num].mid();
  if (l <= m) {
    if (r > m)
      sum += find(num << 1, l, m) + find(num << 1 | 1, m + 1, r);
    else
      sum += find(num << 1, l, r);
  } else if (l > m) {
    sum += find(num << 1 | 1, l, r);
  }
  return sum;
}
point p[maxn];
vector<point> vis;
bool cmp(point a, point b) { return a.x < b.x; }
bool cmp1(point a, point b) {
  if (a.y == b.y) return a.x < b.x;
  return a.y > b.y;
}
int gettid(int num) {
  return lower_bound(vis.begin(), vis.end(), num) - vis.begin() + 1;
}
int arr[maxn] = {0};
vector<int> vis1;
int main() {
  useiostream();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y;
    vis.push_back(p[i]);
  }
  build(1, 1, n);
  sort(vis.begin(), vis.end(), cmp);
  vis.erase(unique(vis.begin(), vis.end()), vis.end());
  for (int i = 0; i < n; i++) {
    p[i].x = gettid(p[i].x);
  }
  long long sum = 0;
  sort(p, p + n, cmp1);
  long long num = 0;
  long long now = 0;
  long long last = -1;
  long long now1 = 0;
  for (int i = 0; i < n; i++) {
    if (p[i].y != last) {
      last = p[i].y;
      num += now;
      long long lins = num * (num - 1) / 2;
      for (int j = 1; j < vis1.size(); j++) {
        int lef = vis1[j - 1] + 1;
        int rig = vis1[j] - 1;
        long long k = find(1, lef, rig);
        lins -= k * (k - 1) / 2;
      }
      if (vis1.size() != 0) {
        int lef = vis1[0] - 1;
        long long k = find(1, 1, lef);
        lins -= k * (k - 1) / 2;
        int rig = vis1[vis1.size() - 1] + 1;
        k = find(1, rig, n);
        lins -= k * (k - 1) / 2;
      }
      sum += lins;
      if (!arr[p[i].x]) {
        arr[p[i].x] = 1;
        now = 1;
      } else
        now = 0;
      vis1.clear();
      vis1.push_back(p[i].x);
    } else {
      if (!arr[p[i].x]) {
        arr[p[i].x] = 1;
        now++;
      }
      vis1.push_back(p[i].x);
    }
    add(1, p[i].x);
    if (i == n - 1) {
      num += now;
      long long lins = num * (num - 1) / 2;
      for (int j = 1; j < vis1.size(); j++) {
        int lef = vis1[j - 1] + 1;
        int rig = vis1[j] - 1;
        long long k = find(1, lef, rig);
        lins -= k * (k - 1) / 2;
      }
      if (vis1.size() != 0) {
        int lef = vis1[0] - 1;
        long long k = find(1, 1, lef);
        lins -= k * (k - 1) / 2;
        int rig = vis1[vis1.size() - 1] + 1;
        k = find(1, rig, n);
        lins -= k * (k - 1) / 2;
      }
      sum += lins;
    }
  }
  cout << sum + (long long)n << endl;
}
