local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end
table.sort(a,function(a,b)
    return a>b
end)

if n%2==0 then
    local total=0
    for i=1,n//2-1 do
        total=total+a[i]*2
    end
    total=total+a[n//2]
    total=total-a[n//2+1]
    for i=n//2+2,n do
        total=total-a[i]*2
    end
    print(total)
else
    local total1=0
    for i=1,n//2-1 do
        total1=total1+a[i]*2
    end
    total1=total1+a[n//2]+a[n//2+1]
    for i=n//2+2,n do
        total1=total1-a[i]*2
    end

    local total2=0
    for i=1,n//2 do
        total2=total2+a[i]*2
    end
    total2=total2-(a[n//2+1]+a[n//2+2])
    for i=n//2+3,n do
        total2=total2-a[i]*2
    end
    print(math.max(total1,total2))
end