#coding: utf-8
import numpy as np
N = int(input())
A = np.array(input().split(" ")).astype(np.int32)

base = np.arange(N)
ex = base.reshape(1, -1)
for i in range(N):
  for j in range(N):
    if j != i:
      for ex1 in ex:
        koho = ex1.copy()
        v = koho[j]
        koho[j] = koho[i]
        koho[i] = v
        if not np.all(ex == koho, axis = 1).any():
          ex = np.append(ex, koho.reshape(1, -1), axis = 0)
champ = 0
for ex1 in ex:
  champ = max(champ, (A * np.abs(base - ex1)).sum())
print(champ)
      