def tenka18beg_c():

    N = int(eval(input()))

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

    A_desc = sorted(A, reverse=True)



    if N % 2 == 1:

        tot1, tot2 = 0, 0

        for i, a in enumerate(A_desc):

            if i < N//2 - 1:

                tot1 += 2*a

                tot2 += 2*a

            elif i == N//2 - 1:

                tot1 += a

                tot2 += 2*a

            elif i == N//2:

                tot1 += a

                tot2 -= a

            elif i == N//2 + 1:

                tot1 -= 2*a

                tot2 -= a

            elif N//2 + 1 < i:

                tot1 -= 2*a

                tot2 -= 2*a

        ans = max(tot1, tot2)

    else:

        tot = 0

        for i, a in enumerate(A_desc):

            if i < N//2 - 1:

                tot += 2*a

            elif i == N//2 - 1:

                tot += a

            elif i == N//2:

                tot -= a

            elif N//2 < i:

                tot -= 2*a

        ans = tot

    print(ans)



tenka18beg_c()
# https://atcoder.jp/contests/tenka1-2018-beginner/submissions/6799465

def tenka18beg_c():

    N = int(eval(input()))

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

    A.sort()



    if N % 2 == 0:

        lower = A[:N//2]

        upper = A[N//2:]

        ans = (2 * sum(upper) - upper[0]) - (2 * sum(lower) - lower[-1])

    else:

        lower = A[:N//2]

        upper = A[N//2 + 1:]

        mid = A[N//2]

        x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1]  # 中央が +2* -1* -1* のパターン

        y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0]  # 中央が +1* +1* -2* のパターン

        ans = max(x, y)

    print(ans)



tenka18beg_c()
def tenka18beg_c():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    A_desc = sorted(A, reverse=True)
    if N % 2 == 1:
        tot1, tot2 = 0, 0
        for i, a in enumerate(A_desc):
            if i < N // 2 - 1:
                tot1 += 2 * a
                tot2 += 2 * a
            elif i == N // 2 - 1:
                tot1 += a
                tot2 += 2 * a
            elif i == N // 2:
                tot1 += a
                tot2 -= a
            elif i == N // 2 + 1:
                tot1 -= 2 * a
                tot2 -= a
            elif N // 2 + 1 < i:
                tot1 -= 2 * a
                tot2 -= 2 * a
        ans = max(tot1, tot2)
    else:
        tot = 0
        for i, a in enumerate(A_desc):
            if i < N // 2 - 1:
                tot += 2 * a
            elif i == N // 2 - 1:
                tot += a
            elif i == N // 2:
                tot -= a
            elif N // 2 < i:
                tot -= 2 * a
        ans = tot
    print(ans)


tenka18beg_c()

# https://atcoder.jp/contests/tenka1-2018-beginner/submissions/6799465
def tenka18beg_c():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    A.sort()
    if N % 2 == 0:
        lower = A[: N // 2]
        upper = A[N // 2 :]
        ans = (2 * sum(upper) - upper[0]) - (2 * sum(lower) - lower[-1])
    else:
        lower = A[: N // 2]
        upper = A[N // 2 + 1 :]
        mid = A[N // 2]
        x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1]  # 中央が +2* -1* -1* のパターン
        y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0]  # 中央が +1* +1* -2* のパターン
        ans = max(x, y)
    print(ans)


tenka18beg_c()

+# https://atcoder.jp/contests/tenka1-2018-beginner/submissions/6799465 -    A_desc = sorted(A, reverse=True) -    if N % 2 == 1: -        tot1, tot2 = 0, 0 -        for i, a in enumerate(A_desc): -            if i < N // 2 - 1: -                tot1 += 2 * a -                tot2 += 2 * a -            elif i == N // 2 - 1: -                tot1 += a -                tot2 += 2 * a -            elif i == N // 2: -                tot1 += a -                tot2 -= a -            elif i == N // 2 + 1: -                tot1 -= 2 * a -                tot2 -= a -            elif N // 2 + 1 < i: -                tot1 -= 2 * a -                tot2 -= 2 * a -        ans = max(tot1, tot2) +    A.sort() +    if N % 2 == 0: +        lower = A[: N // 2] +        upper = A[N // 2 :] +        ans = (2 * sum(upper) - upper[0]) - (2 * sum(lower) - lower[-1]) -        tot = 0 -        for i, a in enumerate(A_desc): -            if i < N // 2 - 1: -                tot += 2 * a -            elif i == N // 2 - 1: -                tot += a -            elif i == N // 2: -                tot -= a -            elif N // 2 < i: -                tot -= 2 * a -        ans = tot +        lower = A[: N // 2] +        upper = A[N // 2 + 1 :] +        mid = A[N // 2] +        x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1]  # 中央が +2* -1* -1* のパターン +        y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0]  # 中央が +1* +1* -2* のパターン +        ans = max(x, y)