Score : $500$ points
Takahashi is with $N$ animals. The $N$ animals are called Animal $1$, Animal $2$, $\ldots$, Animal $N$.
Takahashi will perform the following $N$ kinds of action. Each action can be performed any number of (possibly zero) times.
Note that the $N$-th action above feeds "Animals $N$ and $1$."
Print the minimum possible total cost to feed every animal at least once.
Input is given from Standard Input in the following format:
$N$ $A_1$ $A_2$ $\ldots$ $A_N$
Print the minimum possible total cost to feed every animal at least once.
5 2 5 3 2 5
7
If Takahashi performs the $1$-st, $3$-rd, and $4$-th actions once each, Animals $1$, $2$, $3$, $4$, and $5$ are fed once, once, once, twice, once, respectively, so every animal is fed at least once. The total cost to do so is $A_1 + A_3 + A_4 = 2 + 3 + 2 = 7$ yen, which is the minimum possible.
20 29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62
426