Problem5323--ABC163——Task E:Active Infants

5323: ABC163——Task E:Active Infants

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

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×|xy|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

HINT

【样例数据 1 说明】
If we move the 11-st child from the left to the 33-rd position from the left, the 22-nd child to the 44-th position, the 33-rd child to the 11-st position, and the 44-th child to the 22-nd position, the children earns 1×|13|+3×|24|+4×|31|+2×|42|=201×|1−3|+3×|2−4|+4×|3−1|+2×|4−2|=20 happiness points in total.
【样例数据 2 输入】
6
5 5 6 1 1 1
【样例输出 2 输出】
58
【样例数据 2 输入】
6
8 6 9 1 2 1
【样例输出 2 输出】
85
【数据范围】
【题目出处】
AtCoder Beginner Contest 163,Task E。https://atcoder.jp/contests/abc163/tasks/abc163_e

Source/Category

AtCoder_ABC 100.163.ABC163