Merging Stones
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Walk Alone has n piles of stones, and there are a_i stones in the i-th pile.

He can do an operation to these stones for n-1 times. In each operation, he can select two piles of stones of size x and y, and merge them (the two piles will become a larger pile of size ), and he will get score after that.

Walk Alone wants to know the maximal total score he can get. Can you help him?

输入描述:

The first line contains an integer , the number of piles of stones.

The second line contains n integers. The i-th integer indicates the number of stones in the i-th pile.

输出描述:

Output an integer representing the maximal score Walk Alone can get.
示例1

输入

复制
3
1 2 3

输出

复制
11
示例2

输入

复制
6
1 1 4 5 1 4

输出

复制
98