#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
const int MAX_N = 200025;
const int N = 200001;
namespace sgt {
int s[MAX_N << 2];
void update(int rt, int l, int r, int x) {
  if (l == r) {
    s[rt] = 1;
    return;
  }
  if (x <= ((l + r) >> 1))
    update(rt << 1, l, ((l + r) >> 1), x);
  else
    update(rt << 1 | 1, ((l + r) >> 1) + 1, r, x);
  s[rt] = s[rt << 1] + s[rt << 1 | 1];
}
int query(int rt, int l, int r, int x, int y) {
  if (x > y) return 0;
  if (x <= l && r <= y) {
    return s[rt];
  }
  if (x > ((l + r) >> 1))
    return query(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
  else if (y <= ((l + r) >> 1))
    return query(rt << 1, l, ((l + r) >> 1), x, y);
  else
    return query(rt << 1, l, ((l + r) >> 1), x, y) +
           query(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
}
}  // namespace sgt
struct node {
  int x, y;
  bool operator<(const node other) const & {
    if (y == other.y) return x < other.x;
    return y > other.y;
  }
} arr[MAX_N];
int b[MAX_N], c[MAX_N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &arr[i].x, &arr[i].y), b[i] = arr[i].x, c[i] = arr[i].y;
  sort(b + 1, b + 1 + n);
  sort(c + 1, c + 1 + n);
  int sz = unique(b + 1, b + 1 + n) - b - 1;
  int sz_ = unique(c + 1, c + 1 + n) - c - 1;
  for (int i = 1; i <= n; ++i)
    arr[i].x = lower_bound(b + 1, b + 1 + sz, arr[i].x) - b;
  for (int i = 1; i <= n; ++i)
    arr[i].y = lower_bound(c + 1, c + 1 + sz_, arr[i].y) - c;
  sort(arr + 1, arr + 1 + n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i != n && arr[i].y == arr[i + 1].y) {
      sgt::update(1, 1, N, arr[i].x);
      int R = i + 1;
      while (R <= n && arr[R].y == arr[i].y) {
        sgt::update(1, 1, N, arr[R].x);
        R++;
      }
      int l = sgt::query(1, 1, N, 1, arr[i].x - 1);
      int r = sgt::query(1, 1, N, arr[i].x + 1, N);
      ans += 1ll * (l + 1) * (r + 1);
      for (int j = i + 1; j < R; ++j) {
        int l = sgt::query(1, 1, N, arr[j - 1].x + 1, arr[j].x - 1);
        int r = sgt::query(1, 1, N, arr[j].x + 1, N);
        ans += 1ll * (l + 1) * (r + 1);
      }
      i = R - 1;
    } else {
      int l = sgt::query(1, 1, N, 1, arr[i].x - 1);
      int r = sgt::query(1, 1, N, arr[i].x + 1, N);
      ans += 1ll * (l + 1) * (r + 1);
      sgt::update(1, 1, N, arr[i].x);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

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>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
const int MAX_N = 200025;
const int N = 200001;
namespace sgt {
int s[MAX_N << 2];
void update(int rt, int l, int r, int x) {
  if (l == r) {
    s[rt] = 1;
    return;
  }
  if (x <= ((l + r) >> 1))
    update(rt << 1, l, ((l + r) >> 1), x);
  else
    update(rt << 1 | 1, ((l + r) >> 1) + 1, r, x);
  s[rt] = s[rt << 1] + s[rt << 1 | 1];
}
int query(int rt, int l, int r, int x, int y) {
  if (x > y) return 0;
  if (x <= l && r <= y) {
    return s[rt];
  }
  if (x > ((l + r) >> 1))
    return query(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
  else if (y <= ((l + r) >> 1))
    return query(rt << 1, l, ((l + r) >> 1), x, y);
  else
    return query(rt << 1, l, ((l + r) >> 1), x, y) +
           query(rt << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
}
}  // namespace sgt
struct node {
  int x, y;
  bool operator<(const node other) const & {
    if (y == other.y) return x < other.x;
    return y > other.y;
  }
} arr[MAX_N];
int b[MAX_N], c[MAX_N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &arr[i].x, &arr[i].y), b[i] = arr[i].x, c[i] = arr[i].y;
  sort(b + 1, b + 1 + n);
  sort(c + 1, c + 1 + n);
  int sz = unique(b + 1, b + 1 + n) - b - 1;
  int sz_ = unique(c + 1, c + 1 + n) - c - 1;
  for (int i = 1; i <= n; ++i)
    arr[i].x = lower_bound(b + 1, b + 1 + sz, arr[i].x) - b;
  for (int i = 1; i <= n; ++i)
    arr[i].y = lower_bound(c + 1, c + 1 + sz_, arr[i].y) - c;
  sort(arr + 1, arr + 1 + n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i != n && arr[i].y == arr[i + 1].y) {
      sgt::update(1, 1, N, arr[i].x);
      int R = i + 1;
      while (R <= n && arr[R].y == arr[i].y) {
        sgt::update(1, 1, N, arr[R].x);
        R++;
      }
      int l = sgt::query(1, 1, N, 1, arr[i].x - 1);
      int r = sgt::query(1, 1, N, arr[i].x + 1, N);
      ans += 1ll * (l + 1) * (r + 1);
      for (int j = i + 1; j < R; ++j) {
        int l = sgt::query(1, 1, N, arr[j - 1].x + 1, arr[j].x - 1);
        int r = sgt::query(1, 1, N, arr[j].x + 1, N);
        ans += 1ll * (l + 1) * (r + 1);
      }
      i = R - 1;
    } else {
      int l = sgt::query(1, 1, N, 1, arr[i].x - 1);
      int r = sgt::query(1, 1, N, arr[i].x + 1, N);
      ans += 1ll * (l + 1) * (r + 1);
      sgt::update(1, 1, N, arr[i].x);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

```