import copy

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


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

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

  return result

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