#B3963. Apple Nutrition Selection

    ID: 11620 Type: Default 1000ms 256MiB

Apple Nutrition Selection

Apple Nutrition Selection

You are given \(n\) apples with nutritional values \(a_1, a_2, \cdots, a_n\). You must select exactly two apples: one apple with the maximum nutritional value for gza, and one apple with the minimum nutritional value for gza's friend azg.

Note that the nutritional values may be negative due to factors like infestation. Even in such cases, you must select exactly two apples. The cost you need to pay is the sum of the nutritional values of the two selected apples.

Your task is to output the cost you need to pay.

inputFormat

The first line contains an integer \(n\) representing the number of apples.

The second line contains \(n\) space-separated integers \(a_1, a_2, \cdots, a_n\), which denote the nutritional values of the apples.

outputFormat

Output a single integer which is the cost (i.e., the sum of the maximum and minimum nutritional values) required to pay.

sample

2
1 2
3