def main():
    n = int(input())
    active = [int(i) for i in input().split()]
    moved = [1 for _ in range(n)]
    visited = [1 for _ in range(n)]
    score = []
    for i, a in enumerate(active):
        for j in range(n):
            score.append((a * abs(i-j), a , i, j))
    score = sorted(score, key=lambda x: x[0] + 1/x[1], reverse=True)
    res = 0
    for sc in score:
        infant = sc[2]
        pos = sc[3]
        if visited[pos] and moved[infant]:
            res += sc[0]
            visited[pos] = 0
            moved[infant] = 0
    print(res)
    
if __name__ == '__main__':
    main()

