#abc251e. [abc251_e]Tahakashi and Animals
[abc251_e]Tahakashi and Animals
Problem Statement
Takahashi is with animals. The animals are called Animal , Animal , , Animal .
Takahashi will perform the following kinds of action. Each action can be performed any number of (possibly zero) times.
- Pay yen (the currency in Japan) to feed Animals and .
- Pay yen to feed Animals and .
- Pay yen to feed Animals and .
- Pay yen to feed Animals and .
- Pay yen to feed Animals and .
- Pay yen to feed Animals and .
- Pay yen to feed Animals and .
Note that the -th action above feeds "Animals and ."
Print the minimum possible total cost to feed every animal at least once.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible total cost to feed every animal at least once.
Sample Input 1
5
2 5 3 2 5
Sample Output 1
7
If Takahashi performs the -st, -rd, and -th actions once each, Animals , , , , and are fed once, once, once, twice, once, respectively, so every animal is fed at least once. The total cost to do so is yen, which is the minimum possible.
Sample Input 2
20
29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62
Sample Output 2
426