e=enumerate

n,*a=list(map(int,open(0).read().split()))

d=[0]

for j,(a,i)in e(sorted((a,i)for i,a in e(a))[::-1]):d=[d[0]+a*(~i-j+n)]+[max(d[k]+a*(~i-j+n+k),d[k-1]+a*abs(i-k+1))for k in range(1,j+1)]+[d[j]+a*abs(i-j)]

print((max(d)))
e=enumerate

n,*a=list(map(int,open(0).read().split()))

d=[0]

for j,(a,i)in e(sorted((a,i)for i,a in e(a))[::-1]):d=[d[0]+a*(~i-j+n)]+[max(d[k+1]+a*(n+k-i-j),d[k]+a*abs(i-k))for k in range(j)]+[d[j]+a*abs(i-j)]

print((max(d)))
e = enumerate
n, *a = list(map(int, open(0).read().split()))
d = [0]
for j, (a, i) in e(sorted((a, i) for i, a in e(a))[::-1]):
    d = (
        [d[0] + a * (~i - j + n)]
        + [
            max(d[k] + a * (~i - j + n + k), d[k - 1] + a * abs(i - k + 1))
            for k in range(1, j + 1)
        ]
        + [d[j] + a * abs(i - j)]
    )
print((max(d)))

e = enumerate
n, *a = list(map(int, open(0).read().split()))
d = [0]
for j, (a, i) in e(sorted((a, i) for i, a in e(a))[::-1]):
    d = (
        [d[0] + a * (~i - j + n)]
        + [max(d[k + 1] + a * (n + k - i - j), d[k] + a * abs(i - k)) for k in range(j)]
        + [d[j] + a * abs(i - j)]
    )
print((max(d)))

-        + [ -            max(d[k] + a * (~i - j + n + k), d[k - 1] + a * abs(i - k + 1)) -            for k in range(1, j + 1) -        ] +        + [max(d[k + 1] + a * (n + k - i - j), d[k] + a * abs(i - k)) for k in range(j)]