5323: ABC163——Task E:Active Infants
[Creator : ]
Description
There are NN children standing in a line from left to right. The activeness of the ii-th child from the left is AiAi.
You can rearrange these children just one time in any order you like.
When a child who originally occupies the xx-th position from the left in the line moves to the yy-th position from the left, that child earns Ax×|x−y|Ax×|x−y| happiness points.
Find the maximum total happiness points the children can earn.
Input
Input is given from Standard Input in the following format:
N A1 A2 ... AN
Output
Print the maximum total happiness points the children can earn.
Sample 1 Input
4
1 3 4 2
Sample 1 Output
20