# At code
def DFS(deep,ret):
    global N, a, use, num_list, result
    if deep == N:
        if ret > result:
            ret, result = result, ret
        return

    for i in range(0, N):
        if use[i] != 1:
            num_list[deep] = a[i]
            use[i] = 1
            DFS(deep + 1, ret + a[i]*abs(deep - i))
            use[i] = 0


if __name__ == "__main__":
    N = int(input())
    a = list(map(int, input().split(' ')))
    use = [0 for i in range(len(a))]
    num_list = [0 for i in range(len(a))]
    result = 0
    DFS(0, 0)
    print(result)
