import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

start = [False]*(N+1)
visited = [False]*(N+1)

heappop = heapq.heappop
heappush = heapq.heappush
d = []

for i in range(N):
  for j in range(max(i, N-i-1) +1):
    if 0 <= i-j < N and 0 <= i+j < N:
      heappush(d, (-a[i]*j, i, [i-j, i+j])) # (score, st, ed)
    elif 0 <= i+j < N:
      heappush(d, (-a[i]*j, i, [i+j])) # (score, st, ed)
    elif 0 <= i-j < N:
      heappush(d, (-a[i]*j, i, [i-j])) # (score, st, ed)

ans = 0
while d:
  num,st,ed = heappop(d)
  if start[st] == False:
    if len(ed) == 1:
      if visited[ed[0]] == False:
        ans += num
        start[st] = True
        visited[ed[0]] = True
    else:
      for e in ed:
        if visited[e] == False:
          ans += num
          start[st] = True
          visited[e] = True
          break
print(-ans)