def func(a_list, index_list):

    if len(a_list) == 0:
        score = 0
    else:
        i,x = a_list.pop()
        hoge = []
        for j in index_list:
            tmp = index_list.copy()
            tmp.pop(tmp.index(j))
            hoge.append(x*abs(i-j)+func(a_list.copy(), tmp))

        score = max(hoge)

    return score

def slove(n, k):
    a_list = sorted([(i, int(x)) for i,x in enumerate(k.split(), 1)],
                    key= lambda x:x[1], reverse=True)
    index_list = list(range(1,n+1))
    a = func(a_list, index_list)
    return a

if __name__ == "__main__":
    n = int(input())
    k = input()
    print(slove(n, k))