from collections import deque



n=int(eval(input()))

a = []



for i in range(n):

    a.append(int(eval(input())))



a.sort()



a=deque(a)



mid = a[(n-1)//2]

midi = abs(a[(n-1)//2-1] - mid)

mida = abs(a[(n-1)//2+1] - mid)



rev = False

omi = a[0]

oma = a[-1]



ans = abs(oma - omi)

for i in range(len(a)//2):

    mi = a.popleft()

    ma = a.pop()



    if rev:

        q = mi

        mi = ma

        ma = q



    ans+=abs(mi - omi)+abs(ma - oma)



    omi = mi

    oma = ma

    rev = not rev



if len(a)==1:

    ans+=max(midi,mida)



print(ans)
n=int(eval(input()))

a=[]

for i in range(n):

    aa=int(eval(input()))

    a.append(aa)

from collections import deque

a.sort()

a=deque(a)



omi=a.popleft()

oma=a.pop()

ans=abs(oma-omi)

ret=True



while len(a)>1:

    mi=a.popleft()

    ma=a.pop()



    if ret:

        mi,ma=ma,mi



    ans+=abs(omi-mi)+abs(oma-ma)

    omi,oma=mi,ma

    ret = not ret



if len(a)==1:

    aa=a.pop()

    ans+=max(abs(omi-aa),abs(oma-aa))



print(ans)
from collections import deque

n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
a.sort()
a = deque(a)
mid = a[(n - 1) // 2]
midi = abs(a[(n - 1) // 2 - 1] - mid)
mida = abs(a[(n - 1) // 2 + 1] - mid)
rev = False
omi = a[0]
oma = a[-1]
ans = abs(oma - omi)
for i in range(len(a) // 2):
    mi = a.popleft()
    ma = a.pop()
    if rev:
        q = mi
        mi = ma
        ma = q
    ans += abs(mi - omi) + abs(ma - oma)
    omi = mi
    oma = ma
    rev = not rev
if len(a) == 1:
    ans += max(midi, mida)
print(ans)

n = int(eval(input()))
a = []
for i in range(n):
    aa = int(eval(input()))
    a.append(aa)
from collections import deque

a.sort()
a = deque(a)
omi = a.popleft()
oma = a.pop()
ans = abs(oma - omi)
ret = True
while len(a) > 1:
    mi = a.popleft()
    ma = a.pop()
    if ret:
        mi, ma = ma, mi
    ans += abs(omi - mi) + abs(oma - ma)
    omi, oma = mi, ma
    ret = not ret
if len(a) == 1:
    aa = a.pop()
    ans += max(abs(omi - aa), abs(oma - aa))
print(ans)

-from collections import deque - -    a.append(int(eval(input()))) +    aa = int(eval(input())) +    a.append(aa) +from collections import deque + -mid = a[(n - 1) // 2] -midi = abs(a[(n - 1) // 2 - 1] - mid) -mida = abs(a[(n - 1) // 2 + 1] - mid) -rev = False -omi = a[0] -oma = a[-1] +omi = a.popleft() +oma = a.pop() -for i in range(len(a) // 2): +ret = True +while len(a) > 1: -    if rev: -        q = mi -        mi = ma -        ma = q -    ans += abs(mi - omi) + abs(ma - oma) -    omi = mi -    oma = ma -    rev = not rev +    if ret: +        mi, ma = ma, mi +    ans += abs(omi - mi) + abs(oma - ma) +    omi, oma = mi, ma +    ret = not ret -    ans += max(midi, mida) +    aa = a.pop() +    ans += max(abs(omi - aa), abs(oma - aa))