Under construction

Still being built. Things may change

Projected Array

Time limit3sMemory limit1024 MB

Summary
Rotate N numbered points around the origin, project them onto the x-axis, and find the minimum number of inversions in the resulting label order.
Level

Medium7 of 10

Topics
Geometry, Sorting, Implementation
Solved
No attempts yet

Problem

There are NN distinct points on a two-dimensional plane. Each point has a different integer from 11 to NN written on it.

Now rotate every point around the origin by a certain angle and project them onto the xx-axis. Read the points in increasing order of their xx-coordinates, and the numbers written on them form a sequence of length NN. However, no two points may have the same xx-coordinate after rotation. Among the sequences that can be made this way, find the minimum number of inversions.

Here, the number of inversions of a sequence A1,A2,⋯ ,AnA_1, A_2, \cdots, A_n is the number of pairs (i,j)(i, j) with 1≤i<j≤n1 \le i < j \le n and Ai>AjA_i > A_j.

Input

The first line contains the number of points NN. (1≤N≤20001 \le N \le 2000)

The next NN lines each contain two integers xix_i and yiy_i separated by a space, the coordinates of the point that has the integer ii written on it. (1≤i≤N1 \le i \le N; −109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9)

Output

On the first line, print the minimum possible number of inversions.

Examples1

  1. Example 1

    Input
    5
    11 5
    1 8
    9 7
    6 10
    4 3
    
    Expected output
    2