from collections import deque

N = int(eval(input()))

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



X = deque([A.popleft()])

ans = 0

for i in range(N - 1):

    # Aのどちらから取り出してXのどちらに入れるか

    left_left = abs(X[0] - A[0])

    left_right = abs(X[-1] - A[0])

    right_left = abs(X[0] - A[-1])

    right_right = abs(X[-1] - A[-1])



    if left_left >= max(left_right, right_left, right_right):

        ans += left_left

        X.appendleft(A.popleft())



    elif left_right >= max(left_left, right_left, right_right):

        ans += left_right

        X.append(A.popleft())



    elif right_left >= max(left_left, left_right, right_right):

        ans += right_left

        X.appendleft(A.pop())



    else:

        ans += right_right

        X.append(A.pop())



print(ans)

N = int(eval(input()))

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



if N % 2 == 0:

    X = [-2] * ((N - 2) // 2) + [-1, 1] + [2] * ((N - 2) // 2)

    ans = sum([a * x for a, x in zip(A, X)])

    print(ans)

else:

    X1 = [-2] * ((N - 2) // 2 + 1) + [1, 1] + [2] * ((N - 2) // 2)

    X2 = [-2] * ((N - 2) // 2) + [-1, -1] + [2] * ((N - 2) // 2 + 1)

    ans1 = sum([a * x for a, x in zip(A, X1)])

    ans2 = sum([a * x for a, x in zip(A, X2)])

    print((max(ans1, ans2)))

from collections import deque

N = int(eval(input()))
A = deque(sorted([int(eval(input())) for i in range(N)]))
X = deque([A.popleft()])
ans = 0
for i in range(N - 1):
    # Aのどちらから取り出してXのどちらに入れるか
    left_left = abs(X[0] - A[0])
    left_right = abs(X[-1] - A[0])
    right_left = abs(X[0] - A[-1])
    right_right = abs(X[-1] - A[-1])
    if left_left >= max(left_right, right_left, right_right):
        ans += left_left
        X.appendleft(A.popleft())
    elif left_right >= max(left_left, right_left, right_right):
        ans += left_right
        X.append(A.popleft())
    elif right_left >= max(left_left, left_right, right_right):
        ans += right_left
        X.appendleft(A.pop())
    else:
        ans += right_right
        X.append(A.pop())
print(ans)

N = int(eval(input()))
A = sorted([int(eval(input())) for i in range(N)])
if N % 2 == 0:
    X = [-2] * ((N - 2) // 2) + [-1, 1] + [2] * ((N - 2) // 2)
    ans = sum([a * x for a, x in zip(A, X)])
    print(ans)
else:
    X1 = [-2] * ((N - 2) // 2 + 1) + [1, 1] + [2] * ((N - 2) // 2)
    X2 = [-2] * ((N - 2) // 2) + [-1, -1] + [2] * ((N - 2) // 2 + 1)
    ans1 = sum([a * x for a, x in zip(A, X1)])
    ans2 = sum([a * x for a, x in zip(A, X2)])
    print((max(ans1, ans2)))

-from collections import deque - -A = deque(sorted([int(eval(input())) for i in range(N)])) -X = deque([A.popleft()]) -ans = 0 -for i in range(N - 1): -    # Aのどちらから取り出してXのどちらに入れるか -    left_left = abs(X[0] - A[0]) -    left_right = abs(X[-1] - A[0]) -    right_left = abs(X[0] - A[-1]) -    right_right = abs(X[-1] - A[-1]) -    if left_left >= max(left_right, right_left, right_right): -        ans += left_left -        X.appendleft(A.popleft()) -    elif left_right >= max(left_left, right_left, right_right): -        ans += left_right -        X.append(A.popleft()) -    elif right_left >= max(left_left, left_right, right_right): -        ans += right_left -        X.appendleft(A.pop()) -    else: -        ans += right_right -        X.append(A.pop()) -print(ans) +A = sorted([int(eval(input())) for i in range(N)]) +if N % 2 == 0: +    X = [-2] * ((N - 2) // 2) + [-1, 1] + [2] * ((N - 2) // 2) +    ans = sum([a * x for a, x in zip(A, X)]) +    print(ans) +else: +    X1 = [-2] * ((N - 2) // 2 + 1) + [1, 1] + [2] * ((N - 2) // 2) +    X2 = [-2] * ((N - 2) // 2) + [-1, -1] + [2] * ((N - 2) // 2 + 1) +    ans1 = sum([a * x for a, x in zip(A, X1)]) +    ans2 = sum([a * x for a, x in zip(A, X2)]) +    print((max(ans1, ans2)))