Happy Cow

No attempts yetTime limit2sMemory limit512 MB

Problem

Minho keeps one cow that he cares about. The cow's happiness is his own happiness, so he spent everything he had on NN portions of the tastiest feed.

To keep the feed tidy Minho put the portions in order into a warehouse that is narrow but very long, and he calls them feed 1, feed 2, feed 3, ..., feed NN counting from the left. Each portion can make the cow feel a different amount of happiness. Eating feed 1 may give the cow 20 happiness while feed 2 gives 10. Call that number the happiness value of the portion.

Feed ripens as days pass and tastes better. If the cow eats a portion with happiness value HH on day dd, the cow feels H×dH \times d happiness. The day of the purchase is day 1 and the next day is day 2.

Feed aged for a million years would be bliss for the cow, but Minho cannot wait that long. He decided to give the cow one portion a day, from the day he bought the feed through day NN. The warehouse is too narrow to pull a portion out of the middle, so he can only take one from the left end or from the right end. That is, if portions ii through jj (1ijN1 \le i \le j \le N) are left, Minho must pick feed ii or feed jj. He cannot give any portion other than ii or jj.

Minho wants the cow to be as happy as possible. Find the maximum total happiness the cow feels when all portions are given over NN days.

Input

The first line contains the number of portions NN (1N20001 \le N \le 2000).

The second line contains the NN happiness values H1,H2,,HNH_1, H_2, \dots, H_N (1Hi10001 \le H_i \le 1000), separated by spaces.

Output

Print the maximum total happiness the cow feels when all portions are given over NN days.