The Cross Covers Everything

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

A cross-shaped infinite area on the xx-yy plane can be specified by two distinct points as depicted on the figure below.

Figure J.1. The cross area specified by two points numbered 22 and 44

Given a set of points on the plane, you are asked to figure out how many pairs of the points form a cross-shaped area that covers all the points. To be more precise, when nn points with coordinates (x_i,y_i(x\_i , y\_i) (i=1,,ni = 1, \dots , n) are given, the ordered pair \<p,q>\<p, q> is said to cover a point (x,y)(x, y) if x_pxx_qx\_p ≤ x ≤ x\_q, y_pyy_qy\_p ≤ y ≤ y\_q, or both hold. Your task is to find how many pairs \<p,q>\<p, q> cover all the nn points. No two given points have the same xx-coordinate nor the same yy-coordinate.

입력

The input consists of a single test case of the following format.

\begin{align\*}& n \\\ & x\_1 \\, y\_1 \\\ & \vdots \\\ & x\_n \\, y\_n\end{align\*}

The first line contains an integer nn (2n2×1052 ≤ n ≤ 2 × 10^5), which is the number of points given. Two integers x_ix\_i and y_iy\_i in the ii-th line of the following nn lines are the coordinates of the ii-th point (1x_i1061 ≤ x\_i ≤ 10^6, 1y_i1061 ≤ y\_i ≤ 10^6). You may assume that x_jx_kx\_j \ne x\_k and y_jy_ky\_j \ne y\_k hold for all jkj \ne k.

출력

Print in a line the number of ordered pairs of points that satisfy the condition.

힌트

Figure J.1 depicts the cross specified by two points numbered 2 and 4, that are the second and the fourth points of the Sample Input 1. This is one of the crosses covering all the points.