Share the Ruins Preservation

Time Limit : 2 sec, Memory Limit : 524288 KB

Share the Ruins Preservation

Two organizations International Community for Preservation of Constructions (ICPC) and Japanese Archaeologist Group (JAG) engage in ruins preservation. Recently, many ruins were found in a certain zone. The two organizations decided to share the preservation of the ruins by assigning some of the ruins to ICPC and the other ruins to JAG.

Now, ICPC and JAG make a rule for assignment as follows:

  1. Draw a vertical straight line from the north to the south, avoiding to intersect ruins.
  2. Ruins located to the west of the line are preserved by ICPC. On the other hand, ruins located to the east of the line are preserved by JAG. (It is possible that no ruins are located to the east/west of the line; in this case, ICPC/JAG will preserve no ruins.)

A problem is where to draw a straight line. For each organization, the way to preserve its assigned ruins is to make exactly one fence such that all the assigned ruins are in the region surrounded by the fence. Furthermore, they should minimize the length of such a fence for their budget. If the surrounded areas are vast, expensive costs will be needed to maintain the inside of areas. Therefore, they want to minimize the total preservation cost, i.e. the sum of the areas surrounded by two fences. Your task is to write a program computing the minimum sum of the areas surrounded by two fences, yielded by drawing an appropriate straight line.


The input consists of a single test case.

$x_1$ $y_1$
$x_2$ $y_2$
$x_N$ $y_N$

The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which is the number of founded ruins. The following $N$ lines represent the location of the ruins. The $i$-th line of them consists of two integers $x_i$ and $y_i$, which indicate the location of the $i$-th ruin is $x_i$ east and $y_i$ north from a certain location in the zone. You can assume the following things for the ruins:

  • $-10^9 \leq x_i, y_i \leq 10^9$
  • You can ignore the sizes of ruins. That is, you can assume ruins are points.
  • No pair of ruins has the same location.


Print the minimum total preservation cost yielded by drawing an appropriate straight line. You should round off the cost to the nearest integer.

Sample Input 1

-10 0
-10 5
-5 5
-5 0
10 0
10 -5
5 -5
5 0

Output for the Sample Input 1


Sample Input 2

0 0
0 1
0 2
1 0
1 1

Output for the Sample Input 2


Sample Input 3

1 5
1 6
0 5
0 -5
-1 -5
-1 -6

Output for the Sample Input 3


Sample Input 4

2 5
4 6
9 5
8 8
1 3
6 4
5 9
7 3
7 7
3 9

Output for the Sample Input 4


Source: JAG Practice Contest for ACM-ICPC Asia Regional 2016 , Japan, 2016-9-4