Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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:

 Draw a vertical straight line from the north to the south, avoiding to intersect ruins.

 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.

Input

The input consists of a single test case.

$N$

$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.

Output

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

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

Output for the Sample Input 1

50

Sample Input 2

5
0 0
0 1
0 2
1 0
1 1

Output for the Sample Input 2

0

Sample Input 3

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

Output for the Sample Input 3

6

Sample Input 4

10
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

17



Sample input:
8
-10 0
-10 5
-5 5
-5 0
10 0
10 -5
5 -5
5 0


Sample output:
50

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross3(p0, p1, p2):
    return (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0])

def solve():
    N = int(readline())
    mp = defaultdict(list)
    for i in range(N):
        x, y = map(int, readline().split())
        mp[x].append(y)
    *S, = mp.items()
    S.sort()
    def calc(S, k):
        P = []; Q = []
        r = 0; R = [0]
        for x, ys in S:
            ys.sort(reverse=k)
            for y in ys:
                p = (x, y)
                while len(P) >= 2 and cross3(P[-2], P[-1], p) <= 0:
                    r += abs(cross3(P[-2], P[-1], p))
                    P.pop()
                P.append(p)
                while len(Q) >= 2 and cross3(Q[-2], Q[-1], p) >= 0:
                    r += abs(cross3(Q[-2], Q[-1], p))
                    Q.pop()
                Q.append(p)
            R.append(r)
        return R
    R0 = calc(S, 0)
    S.reverse()
    R1 = calc(S, 1)

    L = len(S)
    ans = 10**20
    for i in range(L+1):
        ans = min(ans, R0[i] + R1[-1-i])
    write("%d\n" % ((ans+1) // 2))
solve()