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

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

  result = None
  for j in dst:
    next_dst = [v for v in dst if v != j]
    val = arr[i] * abs(i - j) + cal(i - 1, next_dst)
    result = max(result, val) if result else val

  return result

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