You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
import sys
iN = int(input())

aA = sorted([int(_) for _ in sys.stdin.readlines()])
aInvA = list(reversed(aA))

iDiff = aInvA[0] - aA[0]
for i in range(1,iN//2 + 1 ):
    D1 = aInvA[i] - aA[i-1]
    D2 = aInvA[i-1] - aA[i]
    if D1 :
        iDiff += D1
    if D2:
        iDiff += D2

print(iDiff)

import sys
iN = int(input())

aA = sorted([int(_) for _ in sys.stdin.readlines()])



if iN % 2 == 0:
    iH = iN // 2
    print( -2 * sum(aA[0:iH-1]) - aA[iH-1] + aA[iH] + 2* sum(aA[iH+1:]))
else:
    iH = (iN -1) //2
    iBigStart = -2 * sum(aA[0:iH]) + aA[iH] + aA[iH+1] + 2 * sum(aA[iH+2:])
    iSmallStart = -2 * sum(aA[0:iH-1]) - aA[iH-1] -aA[iH] + 2* sum(aA[iH+1:])
    print(max(iBigStart,iSmallStart))

exit()
