1480. Cards

单点时限: 2.0 sec

内存限制: 256 MB

TASK

Adam has a fancy for numbers. Once he found a batch of empty paper cards in his drawer, wrote random numbers on both sides of each card and thought of the following puzzle: what smallest possible value can be obtained by putting all cards in an arbitrary order (and upturned if necessary) to the expression of the following form:

_ - _ + _ - _ + _ - _ + … _

After a while Adam came up with a solution. Could you do that too? Write a program to solve the puzzle described above.

输入格式

The first line contains the number of cards N (2 <= N <=10 0000, N is an even integer). Each of the following N lines contains two integers ai and bi (-2000 ≤ ai, bi ≤ 2000; i = 1…N). These are the numbers written on separate sides of the i-th card.

输出格式

The first and the only line should contain the minimal value that can be obtained by putting all the cards to the expression as described above.

样例

Input
6
-8 12
0 5
7 -3
10 -7
-2 7
1 4
Output
-34
Hint:
Cards are put to the expression in this order: 1st, 2nd, 3rd, 5th, 4th, 6th.
(-8) - 5 + (-3) - 7 + (-7) - 4 = -34

4 人解决,7 人已尝试。

7 份提交通过,共有 34 份提交。

8.1 EMB 奖励。

创建: 17 年,3 月前.

修改: 7 年,2 月前.

最后提交: 1 年,4 月前.

来源: BOI 2005

题目标签