

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
個の白いボールが入った袋が 個あります。 個目の袋にはそれぞれ整数 と が書かれたボールが 個ずつ入っています。
あなたはこの袋それぞれについて、片方のボールを赤く塗り、もう片方を青く塗ります。
そのあと 個のボールを、塗られた色で分類します。
そして
- 赤く塗られたボールに書かれた整数の最大値を
- 赤く塗られたボールに書かれた整数の最小値を
- 青く塗られたボールに書かれた整数の最大値を
- 青く塗られたボールに書かれた整数の最小値を
としたときに、 の最小値を求めてください。
制約
入力
入力は以下の形式で標準入力から与えられる。
:
出力
問題の答えを出力する。
入力例 1Copy
3 1 2 3 4 5 6
出力例 1Copy
15
, , の書かれたボールを赤色に塗り、 , , の書かれたボールを青色に塗ると最適解になります。
入力例 2Copy
3 1010 10 1000 1 20 1020
出力例 2Copy
380
入力例 3Copy
2 1 1 1000000000 1000000000
出力例 3Copy
999999998000000001
Score : points
Problem Statement
There are bags, each containing two white balls. The -th box contains two balls with integers and written on them, respectively.
For each of these bags, you will paint one of the balls red, and paint the other blue.
Afterwards, the balls will be classified according to color.
Then, we will define the following:
- : the maximum integer written on a ball painted in red
- : the minimum integer written on a ball painted in red
- : the maximum integer written on a ball painted in blue
- : the minimum integer written on a ball painted in blue
Find the minimum possible value of .
Constraints
Input
Input is given from Standard Input in the following format:
:
Output
Print the minimum possible value.
Sample Input 1Copy
3 1 2 3 4 5 6
Sample Output 1Copy
15
The optimal solution is to paint the balls with , , red, and paint the balls with , , blue.
Sample Input 2Copy
3 1010 10 1000 1 20 1020
Sample Output 2Copy
380
Sample Input 3Copy
2 1 1 1000000000 1000000000
Sample Output 3Copy
999999998000000001