#! /usr/bin/env python3

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N = int(input())
A = [int(_) for _ in input().split()]

com = permutations(range(0, N), N)

rets = []
for hoge in com:
    ret = 0
    for i, pos in enumerate(hoge):
        ret += A[i] * abs(i - pos)
    rets += [ret]
print(max(rets))