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>
import java.util.*;

public class TokitsukazeAndStrangeRectangle {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Point[] points = new Point[n];
        Point[] pointsByX = new Point[n];
        Map<Integer, Integer> amtAtX = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            points[i] = new Point(x, y);
            pointsByX[i] = points[i];
            amtAtX.merge(x, 1, (a, b) -> a + b);
        }
        Arrays.sort(points);
        Arrays.sort(pointsByX, (p1, p2) -> {
            if (p1.x != p2.x) {
                return p1.x - p2.x;
            } else {
                return p1.y - p2.y;
            }
        });
        for (int i = 0, ix = 1; i < n; i++) {
            if (i > 0 && pointsByX[i].x > pointsByX[i - 1].x) {
                ix++;
            }
            pointsByX[i].xix = ix;
        }
        int maxix = pointsByX[n - 1].xix;
        SegmentTree segTree = new SegmentTree(1, maxix);
        for (int i = 1; i <= maxix; i++) {
            segTree.update(i, 1);
        }
        long answer = 0;
        for (int i = 0; i < n;) {
            int y = points[i].y;
            int iMin = i;
            for (; i < n && points[i].y == y; i++) {
                amtAtX.merge(points[i].x, -1, (a, b) -> a + b);
                if (amtAtX.get(points[i].x) == 0) {
                    segTree.update(points[i].xix, 0);
                }
            }
            int iMax = i;
            long amtHere = iMax - iMin;
            answer += amtHere;
            long prev = segTree.query(1, points[iMin].xix - 1);
            //System.out.println("iMin = " + iMin + ", iMax = " + iMax + ", answer = " + answer + ", prev = " + prev);
            for (i = iMin; i < iMax; i++) {
                answer += prev;
                prev++;
                long next = segTree.query(points[i].xix + 1, i < iMax - 1 ? (points[i + 1].xix - 1) : maxix);
                answer += prev * next;
                prev += next;
                //System.out.println("points[" + i + "] = " + points[i] + ", prev = " + prev + ", next = " + next + ", answer = " + answer);
            }
            i = iMax;
        }
        System.out.println(answer);
    }

    static class Point implements Comparable<Point> {
        final int x;
        final int y;
        int xix = -1;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Point o) {
            if (y != o.y) {
                return y - o.y;
            } else {
                return x - o.x;
            }
        }

        @Override
        public String toString() {
            return "Point{" +
                    "x=" + x +
                    ", y=" + y +
                    ", xix=" + xix +
                    '}';
        }
    }

    static class SegmentTree {
        final long[] val;
        final int treeFrom;
        final int treeTo;

        public static final long IDENTITY = 0;

        long combine(long a, long b) {
            return a + b;
        }

        SegmentTree(int treeFrom, int treeTo) {
            this.treeFrom = treeFrom;
            this.treeTo = treeTo;
            int length = treeTo - treeFrom + 1;
            int l;
            for (l = 0; (1 << l) < length; l++);
            val = new long[1 << (l + 1)];
        }

        void update(int index, long newVal) {
            update(1, treeFrom, treeTo, index, newVal);
        }

        void update(int node, int segFrom, int segTo, int index, long newVal) {
            if (segFrom == segTo) {
                val[node] = newVal;
            } else {
                int mid = (segFrom + segTo) >> 1;
                if (index <= mid) {
                    update(node << 1, segFrom, mid, index, newVal);
                } else {
                    update((node << 1) + 1, mid + 1, segTo, index, newVal);
                }
                val[node] = combine(val[node << 1], val[(node << 1) + 1]);
            }
        }

        long query(int from, int to) {
            if (to < from) {
                return 0;
            }
            return query(1, treeFrom, treeTo, from, to);
        }

        long query(int node, int segFrom, int segTo, int from, int to) {
            if(segTo < from || segFrom > to) return IDENTITY;
            if(segFrom >= from && segTo <= to) {
                return val[node];
            }
            int mid = (segFrom + segTo) >> 1;
            return combine(
                    query(node << 1, segFrom, mid, from, to),
                    query((node << 1) + 1, mid + 1, segTo, from, to)
            );
        }
    }
}