N = int(input())
A = list(map(int, input().split()))
B = [i for i in range(N)]
def score(X):
    s = 0
    for i in range(N):
        s += A[i]*abs(i-X[i])
    return s


flag = True
bestscore = 0
while flag:
    flag = False
    for i in range(N):
        for j in range(N):
            B[i], B[j] = B[j], B[i]
            sc = score(B)
            if sc > bestscore:
                bestscore = sc
                flag = True
            else:
                B[i], B[j] = B[j], B[i]
    
print(score(B))