A few years ago, a popular puzzle game named AniPip that particularly appealed to older people like XIRHXQ was hot. And XIRHXQ tries his best to get the highest scores. However, the game is full of randomness and the rules are too complex, so XIRHXQ has a hard time finding an absolutely optimal way to eliminate all the blocks. As a result, XIRHXQ invented a game with simpler rules as a daily pastime, in which he was able to calculate the highest score he could obtain in this game within the time complexity of $$$O(1)$$$.
The rules are as follows.
Though XIRHXQ can calculate the highest score which the player can achieve immediately, he still gives you the assignment because he wants to play AniPop. When you get the objects and values, you should work out the highest score a player can get, and of course, without the limitation of time complexity of $$$O(1)$$$.
When there are 4 objects and the values are [1,2,3,4] respectively, players can eliminate objects in the order shown below and end up with 84 points!
Two lines.
The first line exists a number $$$n$$$ ($$$1 \le n \le 500$$$) which means there are $$$n$$$ objects.
The second line contains $$$n$$$ values $$$a_{i}(1 \le i \le n , 1 \le a_i \le 100)$$$, they are the values given to the objects.
A number which indicates the highest score the player can get.
4 1 2 3 4
84
10 45 29 8 3 32 54 88 68 70 83
2304371