from collections import *

a = sorted(int(eval(input())) for _ in range(int(eval(input()))))

q = deque(a)

rq = deque([q.popleft()])

while q:

    rq.appendleft(q.pop())

    if q: 

        rq.append(q.pop())

    if q:

        rq.appendleft(q.popleft())

    if q: 

        rq.append(q.popleft())

r1 = sum(abs(i-j) for i, j in zip(rq, list(rq)[1:]))



q = deque(a[::-1])

rq = deque([q.popleft()])

while q:

    rq.appendleft(q.pop())

    if q: 

        rq.append(q.pop())

    if q:

        rq.appendleft(q.popleft())

    if q: 

        rq.append(q.popleft())

r2 = sum(abs(i-j) for i, j in zip(rq, list(rq)[1:]))

print((max(r1, r2)))
n = int(eval(input()))

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

if n == 2:

    print((abs(a[0] - a[1])))

elif n%2 == 1:

    r1 = a[n//2] + a[n//2+1] + sum(a[n//2+2:])*2 - sum(a[:n//2])*2

    r2 = sum(a[n//2+1:])*2 - sum(a[:n//2-1])*2 - a[n//2-1] - a[n//2]

    print((max(r1, r2)))

else:

    r1 = sum(a[n//2+1:])*2 + a[n//2] - sum(a[:n//2-1])*2 - a[n//2-1]

    print(r1)
from collections import *

a = sorted(int(eval(input())) for _ in range(int(eval(input()))))
q = deque(a)
rq = deque([q.popleft()])
while q:
    rq.appendleft(q.pop())
    if q:
        rq.append(q.pop())
    if q:
        rq.appendleft(q.popleft())
    if q:
        rq.append(q.popleft())
r1 = sum(abs(i - j) for i, j in zip(rq, list(rq)[1:]))
q = deque(a[::-1])
rq = deque([q.popleft()])
while q:
    rq.appendleft(q.pop())
    if q:
        rq.append(q.pop())
    if q:
        rq.appendleft(q.popleft())
    if q:
        rq.append(q.popleft())
r2 = sum(abs(i - j) for i, j in zip(rq, list(rq)[1:]))
print((max(r1, r2)))

n = int(eval(input()))
a = sorted(int(eval(input())) for _ in range(n))
if n == 2:
    print((abs(a[0] - a[1])))
elif n % 2 == 1:
    r1 = a[n // 2] + a[n // 2 + 1] + sum(a[n // 2 + 2 :]) * 2 - sum(a[: n // 2]) * 2
    r2 = sum(a[n // 2 + 1 :]) * 2 - sum(a[: n // 2 - 1]) * 2 - a[n // 2 - 1] - a[n // 2]
    print((max(r1, r2)))
else:
    r1 = sum(a[n // 2 + 1 :]) * 2 + a[n // 2] - sum(a[: n // 2 - 1]) * 2 - a[n // 2 - 1]
    print(r1)

-from collections import * - -a = sorted(int(eval(input())) for _ in range(int(eval(input())))) -q = deque(a) -rq = deque([q.popleft()]) -while q: -    rq.appendleft(q.pop()) -    if q: -        rq.append(q.pop()) -    if q: -        rq.appendleft(q.popleft()) -    if q: -        rq.append(q.popleft()) -r1 = sum(abs(i - j) for i, j in zip(rq, list(rq)[1:])) -q = deque(a[::-1]) -rq = deque([q.popleft()]) -while q: -    rq.appendleft(q.pop()) -    if q: -        rq.append(q.pop()) -    if q: -        rq.appendleft(q.popleft()) -    if q: -        rq.append(q.popleft()) -r2 = sum(abs(i - j) for i, j in zip(rq, list(rq)[1:])) -print((max(r1, r2))) +n = int(eval(input())) +a = sorted(int(eval(input())) for _ in range(n)) +if n == 2: +    print((abs(a[0] - a[1]))) +elif n % 2 == 1: +    r1 = a[n // 2] + a[n // 2 + 1] + sum(a[n // 2 + 2 :]) * 2 - sum(a[: n // 2]) * 2 +    r2 = sum(a[n // 2 + 1 :]) * 2 - sum(a[: n // 2 - 1]) * 2 - a[n // 2 - 1] - a[n // 2] +    print((max(r1, r2))) +else: +    r1 = sum(a[n // 2 + 1 :]) * 2 + a[n // 2] - sum(a[: n // 2 - 1]) * 2 - a[n // 2 - 1] +    print(r1)