Three Points

Count triples of points where the x coordinates increase and the y coordinates order as r < b < g.

Medium7SortingPrefix sumCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

There are N points on an infinite two-dimensional plane. The points are numbered 0 through N-1, and point i lies at (xi,yi)(x_i, y_i). No two points share an x coordinate, and no two points share a y coordinate.

Pick three of the points and color one red, one green, and one blue. Let rr be the number of the red point, gg the number of the green point, and bb the number of the blue point. The coloring must satisfy xr<xg<xbx_r < x_g < x_b and yr<yb<ygy_r < y_b < y_g at the same time.

Given the coordinates of the points, write a program that counts the colorings satisfying both conditions.

Input

The first line contains N. Each of the next N lines contains the coordinates xx and yy of one point, separated by a space. (1N300,0001 \le N \le 300{,}000, 0x,y<1,000,000,0000 \le x, y < 1{,}000{,}000{,}000)

Output

Print the number of colorings that satisfy the conditions. This value can exceed the range of a 32-bit integer.