def calc_score(li):

    prev = li[0]

    ret = 0

    for el in li:

        ret += abs(el - prev)

        prev = el

    return ret





N, *A = list(map(int, open(0).read().split()))

A = sorted(A)

if N % 2:

    ans = 0

    li = [0] * N

    li[0] = A[N // 2]

    for i in range(N // 2):

        li[i * 2 + 1] = A[i + N // 2 + 1]

        li[i * 2 + 2] = A[i]

    ans = calc_score(li)

    li[N - 1] = A[N // 2]

    for i in range(N // 2):

        li[i * 2] = A[i + N // 2 + 1]

        li[i * 2 + 1] = A[i]

    print((max(ans, calc_score(li))))

else:

    li = [0] * N

    for i in range(N // 2):

        li[i * 2] = A[i + N // 2]

        li[i * 2 + 1] = A[i]

    print((calc_score(li)))

N, *A = list(map(int, open(0).read().split()))

M = N // 2

A.sort()

ans = 0

if N % 2:

    for i in range(1, M):

        ans += A[i + M + 1] - A[i - 1]

        ans += A[i + M + 1] - A[i]

    ans += A[M + 1] - A[0]

    ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1])

else:

    ans += A[M] - A[0]

    for i in range(1, M):

        ans += A[i + M] - A[i - 1]

        ans += A[i + M] - A[i]

print(ans)

def calc_score(li):
    prev = li[0]
    ret = 0
    for el in li:
        ret += abs(el - prev)
        prev = el
    return ret


N, *A = list(map(int, open(0).read().split()))
A = sorted(A)
if N % 2:
    ans = 0
    li = [0] * N
    li[0] = A[N // 2]
    for i in range(N // 2):
        li[i * 2 + 1] = A[i + N // 2 + 1]
        li[i * 2 + 2] = A[i]
    ans = calc_score(li)
    li[N - 1] = A[N // 2]
    for i in range(N // 2):
        li[i * 2] = A[i + N // 2 + 1]
        li[i * 2 + 1] = A[i]
    print((max(ans, calc_score(li))))
else:
    li = [0] * N
    for i in range(N // 2):
        li[i * 2] = A[i + N // 2]
        li[i * 2 + 1] = A[i]
    print((calc_score(li)))

N, *A = list(map(int, open(0).read().split()))
M = N // 2
A.sort()
ans = 0
if N % 2:
    for i in range(1, M):
        ans += A[i + M + 1] - A[i - 1]
        ans += A[i + M + 1] - A[i]
    ans += A[M + 1] - A[0]
    ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1])
else:
    ans += A[M] - A[0]
    for i in range(1, M):
        ans += A[i + M] - A[i - 1]
        ans += A[i + M] - A[i]
print(ans)

-def calc_score(li): -    prev = li[0] -    ret = 0 -    for el in li: -        ret += abs(el - prev) -        prev = el -    return ret - - -A = sorted(A) +M = N // 2 +A.sort() +ans = 0 -    ans = 0 -    li = [0] * N -    li[0] = A[N // 2] -    for i in range(N // 2): -        li[i * 2 + 1] = A[i + N // 2 + 1] -        li[i * 2 + 2] = A[i] -    ans = calc_score(li) -    li[N - 1] = A[N // 2] -    for i in range(N // 2): -        li[i * 2] = A[i + N // 2 + 1] -        li[i * 2 + 1] = A[i] -    print((max(ans, calc_score(li)))) +    for i in range(1, M): +        ans += A[i + M + 1] - A[i - 1] +        ans += A[i + M + 1] - A[i] +    ans += A[M + 1] - A[0] +    ans = max(A[M + 1] - A[M] + ans, ans + A[M] - A[M - 1]) -    li = [0] * N -    for i in range(N // 2): -        li[i * 2] = A[i + N // 2] -        li[i * 2 + 1] = A[i] -    print((calc_score(li))) +    ans += A[M] - A[0] +    for i in range(1, M): +        ans += A[i + M] - A[i - 1] +        ans += A[i + M] - A[i] +print(ans)