import sys

def input():

    return sys.stdin.readline()[:-1]

n=int(eval(input()))

a=[int(eval(input())) for i in range(n)]

a.sort()

if n==2:

    print((a[1]-a[0]))

    quit()



ans=0

for i in range((n-1)//2):

    ans-=a[i]

for i in range((n-2)//2):

    ans+=a[n-1-i]

ans*=2

if n%2!=0:

    ans+=a[n//2]+a[n//2+1]

else:

    ans+=a[n//2]-a[n//2-1]



ans2=0

for i in range((n-1)//2):

    ans2+=a[n-1-i]

for i in range((n-2)//2):

    ans2-=a[i]

ans2*=2

if n%2!=0:

    ans2-=a[n//2]+a[n//2-1]

else:

    ans2+=a[n//2]-a[n//2+1]



# print(ans)

# print(ans2)



print((max(ans,ans2)))
import bisect

import copy

import heapq

import math

import sys

from collections import *

from functools import lru_cache

from itertools import accumulate, combinations, permutations, product

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

sys.setrecursionlimit(500000)

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



n=int(eval(input()))

a=[int(eval(input())) for i in range(n)]



a.sort()



ans1=0

if n%2==0:

    for i in range(n):

        if i<n//2:

            ans1-=a[i]*2

        else:

            ans1+=a[i]*2

    ans1-=a[n//2]

    ans1+=a[n//2-1]

    print(ans1)

else:

    for i in range(n):

        if i<n//2:

            ans1-=a[i]*2

        elif i>n//2:

            ans1+=a[i]*2

    print((max(ans1+a[n//2]-a[n//2+1],ans1-a[n//2]+a[n//2-1])))
import sys


def input():
    return sys.stdin.readline()[:-1]


n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a.sort()
if n == 2:
    print((a[1] - a[0]))
    quit()
ans = 0
for i in range((n - 1) // 2):
    ans -= a[i]
for i in range((n - 2) // 2):
    ans += a[n - 1 - i]
ans *= 2
if n % 2 != 0:
    ans += a[n // 2] + a[n // 2 + 1]
else:
    ans += a[n // 2] - a[n // 2 - 1]
ans2 = 0
for i in range((n - 1) // 2):
    ans2 += a[n - 1 - i]
for i in range((n - 2) // 2):
    ans2 -= a[i]
ans2 *= 2
if n % 2 != 0:
    ans2 -= a[n // 2] + a[n // 2 - 1]
else:
    ans2 += a[n // 2] - a[n // 2 + 1]
# print(ans)
# print(ans2)
print((max(ans, ans2)))

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


sys.setrecursionlimit(500000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a.sort()
ans1 = 0
if n % 2 == 0:
    for i in range(n):
        if i < n // 2:
            ans1 -= a[i] * 2
        else:
            ans1 += a[i] * 2
    ans1 -= a[n // 2]
    ans1 += a[n // 2 - 1]
    print(ans1)
else:
    for i in range(n):
        if i < n // 2:
            ans1 -= a[i] * 2
        elif i > n // 2:
            ans1 += a[i] * 2
    print((max(ans1 + a[n // 2] - a[n // 2 + 1], ans1 - a[n // 2] + a[n // 2 - 1])))

+import bisect +import copy +import heapq +import math +from collections import * +from functools import lru_cache +from itertools import accumulate, combinations, permutations, product +def ruiseki(lst): +    return [0] + list(accumulate(lst)) + + +sys.setrecursionlimit(500000) +mod = pow(10, 9) + 7 +al = [chr(ord("a") + i) for i in range(26)] +direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] -if n == 2: -    print((a[1] - a[0])) -    quit() -ans = 0 -for i in range((n - 1) // 2): -    ans -= a[i] -for i in range((n - 2) // 2): -    ans += a[n - 1 - i] -ans *= 2 -if n % 2 != 0: -    ans += a[n // 2] + a[n // 2 + 1] +ans1 = 0 +if n % 2 == 0: +    for i in range(n): +        if i < n // 2: +            ans1 -= a[i] * 2 +        else: +            ans1 += a[i] * 2 +    ans1 -= a[n // 2] +    ans1 += a[n // 2 - 1] +    print(ans1) -    ans += a[n // 2] - a[n // 2 - 1] -ans2 = 0 -for i in range((n - 1) // 2): -    ans2 += a[n - 1 - i] -for i in range((n - 2) // 2): -    ans2 -= a[i] -ans2 *= 2 -if n % 2 != 0: -    ans2 -= a[n // 2] + a[n // 2 - 1] -else: -    ans2 += a[n // 2] - a[n // 2 + 1] -# print(ans) -# print(ans2) -print((max(ans, ans2))) +    for i in range(n): +        if i < n // 2: +            ans1 -= a[i] * 2 +        elif i > n // 2: +            ans1 += a[i] * 2 +    print((max(ans1 + a[n // 2] - a[n // 2 + 1], ans1 - a[n // 2] + a[n // 2 - 1])))