import copy

n = int(input())
arr = tuple(map(int, input().split()))


def cal(i, dst):
  if i == -1:
    return 0

  results = []
  for j in range(n):
    if dst[j]:
      continue
    next_dst = copy.deepcopy(dst)
    next_dst[j] = i
    val = arr[i] * abs(i - j)
    results.append(val + cal(i - 1, next_dst))

  return max(results)

print(cal(n - 1, [None for _ in range(n)]))
