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))
    ans = 0
    for i, x in a_list:
        tmp = max([(j, x*abs(i-j)) for j in index_list], key=lambda x: x[1])
        ans += tmp[1]
        index_list.pop(index_list.index(tmp[0]))

    return ans

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