from collections import deque

N=int(eval(input()))

A=[]

for i in range(N):

    s=int(eval(input()))

    A.append(s)

A.sort()

H=deque()

H.append(A[0])

s=1

t=N-1

i=0

while t-s!=-1:

    x=A[s]

    y=A[t]

    a=abs(H[0]-x)

    b=abs(H[-1]-x)

    c=abs(H[0]-y)

    d=abs(H[-1]-y)

    e=max(a,b,c,d)

    if a==e:

        H.appendleft(x)

        s+=1

    elif b==e:

        H.append(x)

        s+=1

    elif c==e:

        H.appendleft(y)

        t-=1

    else:

        H.append(y)

        t-=1

ans=0

for i in range(N-1):

    ans+=abs(H[i+1]-H[i])

print(ans)
import sys

N=int(eval(input()))

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

B=sorted(A)

if N%2==0:

    C=B[:(N//2)]

    D=B[(N//2):]

    print((2*sum(D)-2*sum(C)+C[-1]-D[0]))

    sys.exit()

C=B[:(N//2)]

D=B[((N//2)+1):]

s=B[(N//2)]

print((max(2*sum(D)-2*sum(C)+C[-1]-s,2*sum(D)-2*sum(C)+s-D[0])))
from collections import deque

N = int(eval(input()))
A = []
for i in range(N):
    s = int(eval(input()))
    A.append(s)
A.sort()
H = deque()
H.append(A[0])
s = 1
t = N - 1
i = 0
while t - s != -1:
    x = A[s]
    y = A[t]
    a = abs(H[0] - x)
    b = abs(H[-1] - x)
    c = abs(H[0] - y)
    d = abs(H[-1] - y)
    e = max(a, b, c, d)
    if a == e:
        H.appendleft(x)
        s += 1
    elif b == e:
        H.append(x)
        s += 1
    elif c == e:
        H.appendleft(y)
        t -= 1
    else:
        H.append(y)
        t -= 1
ans = 0
for i in range(N - 1):
    ans += abs(H[i + 1] - H[i])
print(ans)

import sys

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A)
if N % 2 == 0:
    C = B[: (N // 2)]
    D = B[(N // 2) :]
    print((2 * sum(D) - 2 * sum(C) + C[-1] - D[0]))
    sys.exit()
C = B[: (N // 2)]
D = B[((N // 2) + 1) :]
s = B[(N // 2)]
print((max(2 * sum(D) - 2 * sum(C) + C[-1] - s, 2 * sum(D) - 2 * sum(C) + s - D[0])))

-from collections import deque +import sys -A = [] -for i in range(N): -    s = int(eval(input())) -    A.append(s) -A.sort() -H = deque() -H.append(A[0]) -s = 1 -t = N - 1 -i = 0 -while t - s != -1: -    x = A[s] -    y = A[t] -    a = abs(H[0] - x) -    b = abs(H[-1] - x) -    c = abs(H[0] - y) -    d = abs(H[-1] - y) -    e = max(a, b, c, d) -    if a == e: -        H.appendleft(x) -        s += 1 -    elif b == e: -        H.append(x) -        s += 1 -    elif c == e: -        H.appendleft(y) -        t -= 1 -    else: -        H.append(y) -        t -= 1 -ans = 0 -for i in range(N - 1): -    ans += abs(H[i + 1] - H[i]) -print(ans) +A = [int(eval(input())) for i in range(N)] +B = sorted(A) +if N % 2 == 0: +    C = B[: (N // 2)] +    D = B[(N // 2) :] +    print((2 * sum(D) - 2 * sum(C) + C[-1] - D[0])) +    sys.exit() +C = B[: (N // 2)] +D = B[((N // 2) + 1) :] +s = B[(N // 2)] +print((max(2 * sum(D) - 2 * sum(C) + C[-1] - s, 2 * sum(D) - 2 * sum(C) + s - D[0])))