N = int(eval(input()))



def left(a, i, prev):

  yield 0

  for l, s in enumerate(prev, 1-i):

    yield s+abs(l)*a

    

def right(a, i, prev):

  for r, s in enumerate(prev, N - len(prev) - i + 1):

    yield s+abs(r)*a

  yield 0



pd = [0]

A = list(map(int, input().split()))

for a,i in sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True):

  pd = [*list(map(max, list(zip(left(a,i, pd), right(a,i, pd)))))]



print((max(pd)))

N = int(eval(input()))



def solve(a, i, prev):

  r = N - len(prev) - i + 1

  p = -i*a

  for j, s in enumerate(prev):

    yield p+abs(j-i)*a, s+abs(j+r)*a

    p = s

  yield s+abs(len(prev)-i)*a,



pd = [0]

A = list(map(int, input().split()))

for a,i in sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True):

  pd = [*list(map(max, solve(a,i, pd)))]



print((max(pd)))

N = int(eval(input()))


def left(a, i, prev):
    yield 0
    for l, s in enumerate(prev, 1 - i):
        yield s + abs(l) * a


def right(a, i, prev):
    for r, s in enumerate(prev, N - len(prev) - i + 1):
        yield s + abs(r) * a
    yield 0


pd = [0]
A = list(map(int, input().split()))
for a, i in sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True):
    pd = [*list(map(max, list(zip(left(a, i, pd), right(a, i, pd)))))]
print((max(pd)))

N = int(eval(input()))


def solve(a, i, prev):
    r = N - len(prev) - i + 1
    p = -i * a
    for j, s in enumerate(prev):
        yield p + abs(j - i) * a, s + abs(j + r) * a
        p = s
    yield s + abs(len(prev) - i) * a,


pd = [0]
A = list(map(int, input().split()))
for a, i in sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True):
    pd = [*list(map(max, solve(a, i, pd)))]
print((max(pd)))

-def left(a, i, prev): -    yield 0 -    for l, s in enumerate(prev, 1 - i): -        yield s + abs(l) * a - - -def right(a, i, prev): -    for r, s in enumerate(prev, N - len(prev) - i + 1): -        yield s + abs(r) * a -    yield 0 +def solve(a, i, prev): +    r = N - len(prev) - i + 1 +    p = -i * a +    for j, s in enumerate(prev): +        yield p + abs(j - i) * a, s + abs(j + r) * a +        p = s +    yield s + abs(len(prev) - i) * a, -    pd = [*list(map(max, list(zip(left(a, i, pd), right(a, i, pd)))))] +    pd = [*list(map(max, solve(a, i, pd)))]