from collections import deque

n = int(eval(input()))

a = [int(eval(input())) for _ in range(n)]



a.sort()

a = deque(a)



b = deque([a.pop()])



ans = 0

for _ in range(n - 1):

    x = max(

        abs(a[0] - b[0]),

        abs(a[0] - b[-1]),

        abs(a[-1] - b[0]),

        abs(a[-1] - b[-1]),

    )

    if x == abs(a[0] - b[0]):

        b.appendleft(a.popleft())

    elif x == abs(a[0] - b[-1]):

        b.append(a.popleft())

    elif x == abs(a[-1] - b[0]):

        b.appendleft(a.pop())

    else:  # x == abs(a[-1] - b[-1]):

        b.append(a.pop())

    ans += x



print(ans)

n = int(eval(input()))

a = [int(eval(input())) for _ in range(n)]



cand1 = [0] * n

cand2 = [0] * n

for i in range(n - 1):

    if i % 2 == 0:

        cand1[i] -= 1

        cand1[i + 1] += 1

        cand2[i] += 1

        cand2[i + 1] -= 1

    else:

        cand1[i] += 1

        cand1[i + 1] -= 1

        cand2[i] -= 1

        cand2[i + 1] += 1



cand1.sort()

cand2.sort()

a.sort()



ans = max(

    sum(a[i] * cand1[i] for i in range(n)),

    sum(a[i] * cand2[i] for i in range(n)),

)

print(ans)

from collections import deque

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a.sort()
a = deque(a)
b = deque([a.pop()])
ans = 0
for _ in range(n - 1):
    x = max(
        abs(a[0] - b[0]),
        abs(a[0] - b[-1]),
        abs(a[-1] - b[0]),
        abs(a[-1] - b[-1]),
    )
    if x == abs(a[0] - b[0]):
        b.appendleft(a.popleft())
    elif x == abs(a[0] - b[-1]):
        b.append(a.popleft())
    elif x == abs(a[-1] - b[0]):
        b.appendleft(a.pop())
    else:  # x == abs(a[-1] - b[-1]):
        b.append(a.pop())
    ans += x
print(ans)

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
cand1 = [0] * n
cand2 = [0] * n
for i in range(n - 1):
    if i % 2 == 0:
        cand1[i] -= 1
        cand1[i + 1] += 1
        cand2[i] += 1
        cand2[i + 1] -= 1
    else:
        cand1[i] += 1
        cand1[i + 1] -= 1
        cand2[i] -= 1
        cand2[i + 1] += 1
cand1.sort()
cand2.sort()
a.sort()
ans = max(
    sum(a[i] * cand1[i] for i in range(n)),
    sum(a[i] * cand2[i] for i in range(n)),
)
print(ans)

-from collections import deque - +cand1 = [0] * n +cand2 = [0] * n +for i in range(n - 1): +    if i % 2 == 0: +        cand1[i] -= 1 +        cand1[i + 1] += 1 +        cand2[i] += 1 +        cand2[i + 1] -= 1 +    else: +        cand1[i] += 1 +        cand1[i + 1] -= 1 +        cand2[i] -= 1 +        cand2[i + 1] += 1 +cand1.sort() +cand2.sort() -a = deque(a) -b = deque([a.pop()]) -ans = 0 -for _ in range(n - 1): -    x = max( -        abs(a[0] - b[0]), -        abs(a[0] - b[-1]), -        abs(a[-1] - b[0]), -        abs(a[-1] - b[-1]), -    ) -    if x == abs(a[0] - b[0]): -        b.appendleft(a.popleft()) -    elif x == abs(a[0] - b[-1]): -        b.append(a.popleft()) -    elif x == abs(a[-1] - b[0]): -        b.appendleft(a.pop()) -    else:  # x == abs(a[-1] - b[-1]): -        b.append(a.pop()) -    ans += x +ans = max( +    sum(a[i] * cand1[i] for i in range(n)), +    sum(a[i] * cand2[i] for i in range(n)), +)