#CF16EXHIBITIONFINALF. Intervals

Intervals

Score : 10001000 points

Problem Statement

Snuke received NN intervals as a birthday present. The ii-th interval was [Li,Ri][-L_i, R_i]. It is guaranteed that both LiL_i and RiR_i are positive. In other words, the origin is strictly inside each interval.

Snuke doesn't like overlapping intervals, so he decided to move some intervals. For any positive integer dd, if he pays dd dollars, he can choose one of the intervals and move it by the distance of dd. That is, if the chosen segment is [a,b][a, b], he can change it to either [a+d,b+d][a+d, b+d] or [ad,bd][a-d, b-d].

He can repeat this type of operation arbitrary number of times. After the operations, the intervals must be pairwise disjoint (however, they may touch at a point). Formally, for any two intervals, the length of the intersection must be zero.

Compute the minimum cost required to achieve his goal.

Constraints

  • 1N50001 \leq N \leq 5000
  • 1Li,Ri1091 \leq L_i, R_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

L1L_1 R1R_1

:

LNL_N RNR_N

Output

Print the minimum cost required to achieve his goal.

4
2 7
2 5
4 1
7 5
22

One optimal solution is as follows:

  • Move the interval [2,7][-2, 7] to [6,15][6, 15] with 88 dollars
  • Move the interval [2,5][-2, 5] to [1,6][-1, 6] with 11 dollars
  • Move the interval [4,1][-4, 1] to [6,1][-6, -1] with 22 dollars
  • Move the interval [7,5][-7, 5] to [18,6][-18, -6] with 1111 dollars

The total cost is 8+1+2+11=228 + 1 + 2 + 11 = 22 dollars.

20
97 2
75 25
82 84
17 56
32 2
28 37
57 39
18 11
79 6
40 68
68 16
40 63
93 49
91 10
55 68
31 80
57 18
34 28
76 55
21 80
7337