There are n points on the plane, the i-th of which is at (x_i, y_i). Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area.

The strange area is enclosed by three lines, x = l, y = a and x = r, as its left side, its bottom side and its right side respectively, where l, r and a can be any real numbers satisfying that l < r. The upper side of the area is boundless, which you can regard as a line parallel to the x-axis at infinity. The following figure shows a strange rectangular area.

<image>

A point (x_i, y_i) is in the strange rectangular area if and only if l < x_i < r and y_i > a. For example, in the above figure, p_1 is in the area while p_2 is not.

Tokitsukaze wants to know how many different non-empty sets she can obtain by picking all the points in a strange rectangular area, where we think two sets are different if there exists at least one point in one set of them but not in the other.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 × 10^5) — the number of points on the plane.

The i-th of the next n lines contains two integers x_i, y_i (1 ≤ x_i, y_i ≤ 10^9) — the coordinates of the i-th point.

All points are distinct.

Output

Print a single integer — the number of different non-empty sets of points she can obtain.

Examples

Input

3
1 1
1 2
1 3


Output

3


Input

3
1 1
2 1
3 1


Output

6


Input

4
2 1
2 2
3 1
3 2


Output

6

Note

For the first example, there is exactly one set having k points for k = 1, 2, 3, so the total number is 3.

For the second example, the numbers of sets having k points for k = 1, 2, 3 are 3, 2, 1 respectively, and their sum is 6.

For the third example, as the following figure shows, there are

  * 2 sets having one point; 
  * 3 sets having two points; 
  * 1 set having four points. 



Therefore, the number of different non-empty sets in this example is 2 + 3 + 0 + 1 = 6.

<image>
#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;
}
