def main():
    n = int(input())
    arr = [int(e) for e in input().split(' ')]

    ls = []
    for i in range(0, n):
        for j in range(0, n):
            ls.append((i, j, arr[i] * abs(i - j)))
    
    ls = list(sorted(ls, key=lambda x: x[2], reverse=True))
    ch = set()
    pos = set()

    s = 0
    for tp in ls:
        i, j, c = tp
        if i in ch or j in pos:
            continue
        s += c
        ch.add(i)
        pos.add(j)

    print(s)
    return 0

if __name__ == "__main__":
    main()