#abc256e. [abc256_e]Takahashi's Anguish
[abc256_e]Takahashi's Anguish
Problem Statement
There are people numbered through .
Takahashi has decided to choose a sequence that is a permutation of integers from through , and give a candy to Person , Person , , and Person , in this order.
Since Person dislikes Person , if Takahashi gives a candy to Person prior to Person , then Person gains frustration of ; otherwise, Person 's frustration is .
Takahashi may arbitrarily choose . What is the minimum possible sum of their frustration?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
2 3 2
1 10 100
Sample Output 1
10
If he lets , only Person gains a positive amount of frustration, in which case the sum of their frustration is .
Since it is impossible to make the sum of frustration smaller, the answer is .
Sample Input 2
8
7 3 5 5 8 4 1 2
36 49 73 38 30 85 27 45
Sample Output 2
57