N = int(eval(input()))

A = [int(eval(input())) for i in range(N)]



A_ = sorted(A)

A_r = list(reversed(A_))



l = []

for i, (x, y) in enumerate(zip(A_[:N//2], A_r[:N//2])):

    if i % 2 == 0:

        l.append(x)

        l.insert(0, y)

    else:

        l.append(y)

        l.insert(0, x)



if N % 2 != 0:

    m = A_[N//2]

    if abs(l[0] - m) > abs(l[-1] - m):

        l.insert(0, m)

    else:

        l.append(m)



def g(L):

    for i, j in zip(L[:-1], L[1:]):

        yield abs(i - j)



print((sum(g(l))))

N = int(eval(input()))

A = [int(eval(input())) for i in range(N)]



A_ = sorted(A)

A_r = list(reversed(A_))



n = (A_[0], A_r[0])

sum = abs(n[0] - n[1])

for i, (x, y) in enumerate(zip(A_[1:N//2], A_r[1:N//2])):

    sum += abs(n[0] - y) + abs(n[1] - x)

    n = (x, y)



if N%2 != 0:

    m = A_[N//2]

    sum += max(abs(n[0] - m), abs(n[1] - m))



print(sum)

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_ = sorted(A)
A_r = list(reversed(A_))
l = []
for i, (x, y) in enumerate(zip(A_[: N // 2], A_r[: N // 2])):
    if i % 2 == 0:
        l.append(x)
        l.insert(0, y)
    else:
        l.append(y)
        l.insert(0, x)
if N % 2 != 0:
    m = A_[N // 2]
    if abs(l[0] - m) > abs(l[-1] - m):
        l.insert(0, m)
    else:
        l.append(m)


def g(L):
    for i, j in zip(L[:-1], L[1:]):
        yield abs(i - j)


print((sum(g(l))))

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_ = sorted(A)
A_r = list(reversed(A_))
n = (A_[0], A_r[0])
sum = abs(n[0] - n[1])
for i, (x, y) in enumerate(zip(A_[1 : N // 2], A_r[1 : N // 2])):
    sum += abs(n[0] - y) + abs(n[1] - x)
    n = (x, y)
if N % 2 != 0:
    m = A_[N // 2]
    sum += max(abs(n[0] - m), abs(n[1] - m))
print(sum)

-l = [] -for i, (x, y) in enumerate(zip(A_[: N // 2], A_r[: N // 2])): -    if i % 2 == 0: -        l.append(x) -        l.insert(0, y) -    else: -        l.append(y) -        l.insert(0, x) +n = (A_[0], A_r[0]) +sum = abs(n[0] - n[1]) +for i, (x, y) in enumerate(zip(A_[1 : N // 2], A_r[1 : N // 2])): +    sum += abs(n[0] - y) + abs(n[1] - x) +    n = (x, y) -    if abs(l[0] - m) > abs(l[-1] - m): -        l.insert(0, m) -    else: -        l.append(m) - - -def g(L): -    for i, j in zip(L[:-1], L[1:]): -        yield abs(i - j) - - -print((sum(g(l)))) +    sum += max(abs(n[0] - m), abs(n[1] - m)) +print(sum)