def solve():

    n = int(eval(input()))

    a = sorted(int(eval(input())) for _ in range(n))

    c0 = n // 2 - 1

    c1 = n // 2

    c2 = n // 2 + 1

    ans = 0

    if n & 1:

        for i in range(c0):

            ans -= a[i] * 2

        for i in range(c2 + 1, n):

            ans += a[i] * 2

        ans += -a[c0] + a[c2] + max(-a[c0] + a[c1], - a[c1] + a[c2])

    else:

        for i in range(c0):

            ans -= a[i] * 2

        for i in range(c1 + 1, n):

            ans += a[i] * 2

        ans += -a[c0] + a[c1]

    return ans

print((solve()))

import sys

readline = sys.stdin.readline

def solve():

    n = int(eval(input()))

    a = sorted(int(readline()) for _ in range(n))

    c0 = n // 2 - 1

    c1 = n // 2

    c2 = n // 2 + 1

    ans = 0

    if n & 1:

        ans = sum(a[c2 + 1:]) * 2 - sum(a[:c0]) * 2 - a[c0] + a[c2] + max(-a[c0] + a[c1], - a[c1] + a[c2])

    else:

        ans = sum(a[c1 + 1:]) * 2 - sum(a[:c0]) * 2 - a[c0] + a[c1]

    return ans

print((solve()))

def solve():
    n = int(eval(input()))
    a = sorted(int(eval(input())) for _ in range(n))
    c0 = n // 2 - 1
    c1 = n // 2
    c2 = n // 2 + 1
    ans = 0
    if n & 1:
        for i in range(c0):
            ans -= a[i] * 2
        for i in range(c2 + 1, n):
            ans += a[i] * 2
        ans += -a[c0] + a[c2] + max(-a[c0] + a[c1], -a[c1] + a[c2])
    else:
        for i in range(c0):
            ans -= a[i] * 2
        for i in range(c1 + 1, n):
            ans += a[i] * 2
        ans += -a[c0] + a[c1]
    return ans


print((solve()))

import sys

readline = sys.stdin.readline


def solve():
    n = int(eval(input()))
    a = sorted(int(readline()) for _ in range(n))
    c0 = n // 2 - 1
    c1 = n // 2
    c2 = n // 2 + 1
    ans = 0
    if n & 1:
        ans = (
            sum(a[c2 + 1 :]) * 2
            - sum(a[:c0]) * 2
            - a[c0]
            + a[c2]
            + max(-a[c0] + a[c1], -a[c1] + a[c2])
        )
    else:
        ans = sum(a[c1 + 1 :]) * 2 - sum(a[:c0]) * 2 - a[c0] + a[c1]
    return ans


print((solve()))

+import sys + +readline = sys.stdin.readline + + -    a = sorted(int(eval(input())) for _ in range(n)) +    a = sorted(int(readline()) for _ in range(n)) -        for i in range(c0): -            ans -= a[i] * 2 -        for i in range(c2 + 1, n): -            ans += a[i] * 2 -        ans += -a[c0] + a[c2] + max(-a[c0] + a[c1], -a[c1] + a[c2]) +        ans = ( +            sum(a[c2 + 1 :]) * 2 +            - sum(a[:c0]) * 2 +            - a[c0] +            + a[c2] +            + max(-a[c0] + a[c1], -a[c1] + a[c2]) +        ) -        for i in range(c0): -            ans -= a[i] * 2 -        for i in range(c1 + 1, n): -            ans += a[i] * 2 -        ans += -a[c0] + a[c1] +        ans = sum(a[c1 + 1 :]) * 2 - sum(a[:c0]) * 2 - a[c0] + a[c1]