import numpy as np

n = int(input())
A = list(map(int, input().split()))

lis = []

for i in range(n):
  p = [a * abs(i - itr) for itr, a in enumerate(A)]
  lis.append(p)

selected = [False] * n

# print(lis)

ans = 0
for i in range(n // 2):
  u = np.array([-1 if selected[itr] else v for itr, v in enumerate(lis[i])])
  d = np.array([-1 if selected[itr] else v for itr, v in enumerate(lis[-(i+1)])])
  # print(u, d)
  ua = u.argsort()
  da = d.argsort()
  # print(ua, da)
  ufirst, usecond = ua[-1], ua[-2]
  dfirst, dsecond = da[-1], da[-2]

  if ufirst != dfirst:
    selected[ufirst] = True
    selected[dfirst] = True
    ans += u[ufirst]
    ans += d[dfirst]
  else:
    if u[usecond] > d[dsecond]:
      ans += u[usecond]
      ans += d[dfirst]
    else:
      ans += u[ufirst]
      ans += d[dsecond]

if n % 2 == 1:
  idx = selected.index(False)
  ans += lis[n//2][idx]

print(ans)
# print(ans)