CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
for i in range(N):
    x = a.count(i+1)
    print(x)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
s = [0] *N
for u in range(N-1):
    s[a[u]-1] += 1
for i in range(N):
    print((s[i]))
# Original solution
N = int(eval(input()))
boss = {i+1: 0 for i in range(N)}
A = list(map(int, input().split()))

for i in A:
    boss[i] += 1

for i in range(N):
    print((boss[i+1]))

# Optimized solution
N = int(input())
boss = [0] * N
A = map(lambda x:int(x) - 1, input().split())

for i in A:
    boss[i] += 1

print(*boss, sep='\n')
# Original solution
import os

def main():
        n = int(eval(input()))
        a_list = list(map(int, input().split()))
        result = [a_list.count(i) for i in range(1,n+1)]
        for i in result:
                print(i)
        
if __name__ == "__main__":
        main()       

# Optimized solution
import os

def main():
	n = int(eval(input()))
	a_list = list(map(int, input().split()))
	result = [0]*n
	for i in a_list:
		result[i-1] += 1
	for i in result:
		print(i)

if __name__ == "__main__":
	main()
# Original solution
N = int(input())
l = []
k = []
s = 0
l = list(map(int, input().split(" ")))
for i in range(1, len(l)+2):
    k.append(l.count(i))
for i in range(len(k)):
    print(k[i], end = "\n")


# Optimized solution
N = int(eval(input()))
P = [0] * (N+1)
L = list(map(int, input().split(" ")))
for i in L:
    P[i] += 1
for i in range(1, len(P)):
    print((P[i]))
# Original solution
n=int(eval(input()))
lista=list(map(int,input().split()))
for x in range(1,n+1):
  print((lista.count(x)))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=[0]*n
for aa in a:
  ans[aa-1]+=1
for an in ans:
  print(an)
# Original solution
n = int(eval(input()))

a = list(map(int, input().split()))

for i in range(1, n+1):
    print((a.count(i)))

# Optimized solution
n = int(eval(input()))

a = list(map(int, input().split()))

men = {}

for i in range(1, n+1):
    men[i] = 0

for i in a:
    men[i] += 1

for i in range(1, n+1):
    print((men[i]))
# Original solution
n=int(eval(input()))
a=[0]*n
a[:]=list(map(int,input().split()))
for ii in range(n):
    print((a.count(ii+1)))

# Optimized solution
n=int(eval(input()))
a=[0]*(n-1)
a[:]=list(map(int,input().split()))
b=[0]*(n)
"""print(a)
print(b)"""
for ii in range(n-1):
    b[a[ii]-1]+=1
for ii in range(n):
    print((b[ii]))
# Original solution
n=int(eval(input()))
c=list(map(int,input().split()))
k=n
u=n
for i in range(1,n):
    p=(c.count(i))
    print(p)
    k=k-p
    u=u-1
    if k<2:
        break
while u>0:
    print((0))
    u=u-1

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
d = dict()
for i in range(n):
    d[i] = 0
for e in a:
    d[e-1] += 1
for i in range(n):
    print((d[i]))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n):
  print((a.count(i+1)))

# Optimized solution
n=int(eval(input()))
result=[0]*n
a=list(map(int,input().split()))
for i in range(n-1):
  result[a[i]-1]+=1
for j in range (n):
  print((result[j]))
# Original solution
s=int(eval(input()))
e_list=list(map(int,input().split()))
e_lst=list(e_list)
e_dic={}
for i in range(1,s+1):
  e_dic[i]=e_lst.count(i)

for i in list(e_dic.keys()):
  print((e_dic[i]))

# Optimized solution
n=int(eval(input()))
l=list(map(int,input().split()))

ans=[0]*n

for i in l:
    ans[i-1]+=1

for j in ans:
    print(j)
# Original solution
num = int(eval(input()))
num2 = list(input().split())
for i in range(num):
  print((num2.count(str(i + 1))))

# Optimized solution
num = int(eval(input()))
li = list(int(x) for x in input().split())
li2 = [0] * num
num = len(li)
for i in li:
  li2[i - 1] = li2[i - 1] + 1
for j in range(num + 1):
  print((li2[j]))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
 
for i in range(1,n+1):
	print((a.count(i)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

ans = [0] * n

for i in a:
    ans[i - 1] += 1

for i in ans:
    print(i)
# Original solution
#整数の入力
N = int(eval(input()))
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

ans = 0
for i in range(N):
  ans = A_list.count(i+1)
  print(ans)


# Optimized solution
#整数の入力
N = int(eval(input()))
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

ans = 0
  
  
ans_list = [0]*N
  
for i in range(len(A_list)):
  #ans = A_list.count(i+1)
  ans_list[A_list[i]-1]+=1


for i in range(len(ans_list)):
  print((ans_list[i]))
# Original solution
import collections

n = int(eval(input()))
A = list(map(int, input().split()))

C = collections.Counter(A)
for i in range(1, n+1):
  print((C[i]))


# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))

ans = [0] * n

for a in A:
    ans[a-1] += 1

for i in ans:
    print(i)
# Original solution
n = int(eval(input()))
A = input().split()
a = [int(i) for i in A]
b = [0]*n

for i in range(len(a)):
    for j in range(n):
        if j == a[i]:
            b[j-1] += 1

for i in range(n):
    print((b[i]))

# Optimized solution
n = int(eval(input()))
A = input().split()
a = [int(i) for i in A]
b = [0]*n

for i in range(len(a)):
    s = a[i]
    b[s-1] += 1

for i in range(n):
    print((b[i]))
# Original solution
def main():
        N = int(eval(input()))
        A = list(map(int, input().split()))

        l = []

        for i in range(N-1):
                if i+1 in A:
                        l.append(A.count(i+1))
                else:
                        l.append(0)
        l.append(0)


        ans = "\n".join([str(x) for x in l])
        print(ans)

if __name__=="__main__":
        main()

# Optimized solution
def main():
        N = int(eval(input()))
        A = list(map(int, input().split()))

        l = [0]*N

        for a in A:
                l[a-1] += 1

        ans = "\n".join([str(x) for x in l])
        print(ans)

if __name__=="__main__":
        main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

memo = {}
for i in range(N-1):
    Si = A[i]
    try:
        memo[Si] += 1
    except:
        memo[Si] = 1

for i in range(1, N+1):
    try:
        print((memo[i]))
    except:
        print((0))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
memo = {key:0 for key in range(1, N+1)}

for a in A:
    memo[a] += 1

for key in list(memo.keys()):
    print((memo[key]))
# Original solution
N = int(eval(input()))
As = list(map(int, input().split()))

for i in range(N):
    print((As.count(i+1)))

# Optimized solution
N = int(eval(input()))
As = list(map(int, input().split()))
ans = [0] * N

for i in As:
    ans[i-1]+=1

for j in ans:
    print(j)
# Original solution
#H,W = map(int,input().split())
N=int(eval(input()))
A = list(map(int,input().split()))
#S=str(input())
c=[]
for i in range(1,N+1):
    C=A.count(i)
    c.append(C)

for k in c:

    print(k)


# Optimized solution
#H,W = map(int,input().split())
N=int(eval(input()))
A = list(map(int,input().split()))
#S=str(input())
c=[0]*N
for i in A:
    c[i-1]+=1
for k in c:
    print(k)
# Original solution
n = int(eval(input()))
*a, = list(map(int, input().split()))
for i in range(n):
    print((a.count(i+1)))

# Optimized solution
n = int(eval(input()))
*a, = list(map(int, input().split()))
d = {}
for i in range(1, -~n): d[i] = 0
for i in a:
    if i not in d: d[i] = 1
    else: d[i] += 1
for i in list(d.values()):
    print(i)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n):
    if i+1 in a:
        print((a[i:].count(i+1)))
    else:
        print('0')


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1):
    ans[a[i]-1] += 1
for i in range(n):
    print((ans[i]))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

for i in range(N):
    print((A.count(i+1)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

count = 0
buka = [0 for _ in range(N)]

for i in range(N-1):
    buka[A[i]-1] += 1

for k in range(N):
    print((buka[k]))
# Original solution
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(eval(input()))
    S = [input().strip() for _ in range(N)]
    res = 0
    for a in range(N):
        f = True
        for i in range(N):
            for j in range(N):
                if S[(i - a) % N][j] != S[(j - a) % N][i]:
                    f = False
        if f:
            res += N
    print(res)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return list(map(int, input().split()))
def read_index(): return [int(x) - 1 for x in input().split()]
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(eval(input()))
    S = [input().strip() for _ in range(N)]
    print((sum(N if all(S[(i - a) % N][j] == S[(j - a) % N][i] for i in range(N) for j in range(N)) else 0 for a in range(N))))


if __name__ == "__main__":
    main()
# Original solution
def s():
	n,*o=open(0)
	n=int(n)
	r=list(range(n))
	print((sum((n-a-b)*all(o[(i+b)%n][(a+j)%n]==o[(j+b)%n][(a+i)%n]for i in r for j in r)for a,b in zip(r+[0]*n,[0]*~-n+r))))
s()

# Optimized solution
n,*o=open(0)
n=int(n)
r=list(range(n))
print((sum((n-a-b)*all(o[(i+b)%n][(a+j)%n]==o[(j+b)%n][(a+i)%n]for i in r for j in r[i:])for a,b in zip(r+[0]*n,[0]*~-n+r))))
# Original solution
from collections import*
n,*s=open(0)
n=int(n)
s=deque([tuple(t.rstrip())for t in s])
c=0
for _ in range(n):
  if all(x==y for x,y in zip(s,list(zip(*s)))):c+=n
  s.rotate(1)
print(c)

# Optimized solution
n,*s=open(0)
n=int(n)
c=0
for _ in range(n):
  for i in range(n*n):
    i,j=i//n,i%n
    if s[i][j]!=s[j][i]:
      break
  else:
    c+=n    
  s=s[1:]+s[:1]
print(c)
# Original solution
N = int(input())
S = [list(input()) for t in range(N)]
ans = 0
for n in range(N):
  isSym = True
  for i in range(N):
    for j in range(i,N):
      if S[i][j] != S[j][i]:
        isSym = False
        break
    if not isSym:
      break
  ans += 1 if isSym else 0
  s = S.pop()
  S.insert(0, s)
print(ans*N)


# Optimized solution
N = int(input())
S = [list(input()) for t in range(N)]
ans = 0
for n in range(N):
  t = S[n:]+S[:n]
  t_t = list(map(list, list(zip(*t))))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print(ans*N)
# Original solution
n = int(eval(input()))
A = []
for i in range(n):
    A.append(int(eval(input())))
    
A.sort()
B = []
for i in range(n):
    if(i==0):
        B.append(A.pop(0))
    elif(i==n-1):
        if(abs(B[0]-A[0])>abs(B[-1]-A[0])):
            B.insert(0, A.pop())
        else:
            B.append(A.pop())
    elif(not(i%4==0 or (i+1)%4==0)):
        if(i%2==0):
            B.insert(0, A.pop())
        else:
            B.append(A.pop())
    else:
        if(i%2==0):
            B.insert(0, A.pop(0))
        else:
            B.append(A.pop(0))

res = 0
for i in range(n-1):
    res += abs(B[i]-B[i+1])

print(res)
    

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

A.sort(reverse=True)

def p1(l):
    if N%2 == 1:
        ans = 0
        ans += sum(l[:(N-3)//2])*2
        ans += sum(l[(N-3)//2:(N-3)//2+2])
        ans += sum(l[(N-3)//2+2:])*(-2)
        return ans
    else:
        ans = 0
        ans += sum(l[:(N-2)//2])*2
        ans += sum(l[(N-2)//2:(N-2)//2+1])
        ans += sum(l[(N-2)//2+1:(N-2)//2+2])*(-1)
        ans += sum(l[(N-2)//2+2:])*(-2)
        return ans

def p2(l):
    if N%2 == 1:
        ans = 0
        ans += sum(l[:(N-1)//2])*2
        ans += sum(l[(N-1)//2:(N-1)//2+2])*(-1)
        ans += sum(l[(N-1)//2+2:])*(-2)
        return ans
    else:
        ans = 0
        ans += sum(l[:(N-2)//2])*2
        ans += sum(l[(N-2)//2:(N-2)//2+1])
        ans += sum(l[(N-2)//2+1:(N-2)//2+2])*(-1)
        ans += sum(l[(N-2)//2+2:])*(-2)
        return ans
print((max(p1(A),p2(A))))
# Original solution
def calc(A):
    res = 0
    
    for i in range(N-1):
        res += abs(A[i+1]-A[i])
    
    return res

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

if N%2==0:
    l1 = A[:N//2]
    l2 = A[N//2:]
    l1.reverse()
    l2.reverse()
    B = [-1]*N
    
    for i in range(N):
        if i%2==0:
            B[i] = l1[i//2]
        else:
            B[i] = l2[i//2]
            
    ans = calc(B)
    print(ans)
else:
    l1 = A[:N//2]
    l2 = A[N//2:]
    B = [-1]*N
    B[0] = l2[0]
    B[-1] = l2[1]
    
    for i in range(1, N-1):
        if i%2==0:
            B[i] = l2[i//2+1]
        else:
            B[i] = l1[i//2]
    
    l1 = A[:N//2+1]
    l2 = A[N//2+1:]
    C = [-1]*N
    C[0] = l1[-1]
    C[-1] = l1[-2]
    
    for i in range(1, N-1):
        if i%2==0:
            C[i] = l1[i//2-1]
        else:
            C[i] = l2[i//2]
   
    ans = max(calc(B), calc(C))
    print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

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

for i in range(N):
    p = 1 if i in [0, N-1] else 2
    coef1.append(p*(1 if i%2==0 else -1))
    coef2.append(p*(-1 if i%2==0 else 1))

A.sort()
coef1.sort()
coef2.sort()
ans = max(sum(Ai*p for Ai, p in zip(A, coef1)), sum(Ai*p for Ai, p in zip(A, coef2)))
print(ans)
# Original solution
# tenka1-2018-beginnerC - Align
from collections import deque


def main():
    N, *A = list(map(int, open(0).read().split()))
    A.sort()
    if N & 1:
        low, high, mid = A[: N // 2], A[N // 2 + 1 :], A[N // 2]
        x = (sum(high) - sum(low)) * 2 - mid + low[-1]
        y = (sum(high) - sum(low)) * 2 + mid - high[0]
        ans = max(x, y)
    else:
        low, high = A[: N // 2], A[N // 2 :]
        ans = (sum(high) - sum(low)) * 2 - high[0] + low[-1]
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# tenka1-2018-beginnerC - Align
def main():
    N, *A = list(map(int, open(0).read().split()))
    A.sort()
    if N & 1:
        low, high, mid = A[: N // 2], A[N // 2 + 1 :], A[N // 2]
        x = (sum(high) - sum(low)) * 2 - mid + low[-1]
        y = (sum(high) - sum(low)) * 2 + mid - high[0]
        ans = max(x, y)
    else:
        low, high = A[: N // 2], A[N // 2 :]
        ans = (sum(high) - sum(low)) * 2 - high[0] + low[-1]
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))

A = [0 for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for k in range(i):
        if a <= A[k]:
            # print(A[k + 1: i + 1], A[k:i])
            A[k + 1: i + 1] = A[k: i]
            A[k] = a
            break
    else:
        A[i] = a
    # print(A)
# A.sort()
# print(A)

ans = 0
end = [A[0], A[-1]]
ans += abs(A[-1] - A[0])
A = A[1:-1]
while len(A) != 0:
    # print(ans, A, end)
    sl = [A[0], A[-1]]

    tmp_l = []
    tmp_l.append(abs(end[0] - sl[0]))
    tmp_l.append(abs(end[1] - sl[0]))
    tmp_l.append(abs(end[0] - sl[1]))
    tmp_l.append(abs(end[1] - sl[1]))

    tmp = max(tmp_l)
    index = tmp_l.index(tmp)
    ans += tmp

    # print(index, tmp_l[index])
    if index % 2 == 0:
        end[0] = sl[index == 2]

    else:
        end[1] = sl[index == 3]

    if index < 2:
        A = A[1:]
    else:
        A = A[:-1]

print(ans)

# Optimized solution
n = int(eval(input()))

A = []
for i in range(n):
    A.append(int(eval(input())))
A.sort()
# print(A)

ans = 0
end = [A[0], A[-1]]
ans += abs(A[-1] - A[0])
A = A[1:-1]
s = 0
L = -1
for _ in range(n - 2):
    # print(ans, A, end)
    sl = [A[s], A[L]]
    # print(sl)

    tmp_l = []
    tmp_l.append(abs(end[0] - sl[0]))
    tmp_l.append(abs(end[1] - sl[0]))
    tmp_l.append(abs(end[0] - sl[1]))
    tmp_l.append(abs(end[1] - sl[1]))

    tmp = max(tmp_l)
    index = tmp_l.index(tmp)
    ans += tmp

    # print(index, tmp_l[index])
    if index % 2 == 0:
        end[0] = sl[index == 2]

    else:
        end[1] = sl[index == 3]

    if index < 2:
        s += 1
    else:
        L -= 1

print(ans)
# Original solution
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    if N == 2:
        print((abs(A[0] - A[1])))
        return

    A.sort()

    q = collections.deque(A)

    ans = 0
    i = 0
    c = [q.popleft(), q.pop()]
    ans += abs(c[0] - c[1])
    while q:
        if len(q) >= 2:
            a = q.popleft()
            b = q.pop()
            al = abs(a - c[0])
            ar = abs(a - c[1])
            bl = abs(b - c[0])
            br = abs(b - c[1])
            ma = max([al, ar, bl, br])
            ans += ma
            if ma == al:
                c[0] = a
                q.append(b)
            elif ma == ar:
                c[1] = a
                q.append(b)
            elif ma == bl:
                c[0] = b
                q.appendleft(a)
            else:
                c[1] = b
                q.appendleft(a)
        else:
            a = q.pop()
            ans += max(abs(c[0] - a), abs(c[1] - a))

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    A.sort()

    if N % 2 == 0:
        ans = sum(A[N // 2:]) * 2 - A[N // 2] - sum(A[:N // 2]) * 2 + A[N // 2 - 1]
    else:
        ans = sum(A[N // 2:]) * 2 - A[N // 2] - A[N // 2 + 1] - sum(A[:N // 2]) * 2
        ans = max(ans, sum(A[N // 2 + 1:]) * 2 - sum(A[:N // 2 + 1]) * 2 + A[N // 2] + A[N // 2 - 1])
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = []
b = []
c = 0
for i in range(n):
 ak = int(eval(input()))
 a.append(ak)
a.sort()
for i in range(n-1):
 bk = a[i+1] -  a[i]
 b.append(bk)
if len(b) % 2 == 1:
 for i in range(len(b) // 2):
  c += sum(b[i:len(b)-i])*2
 c += b[len(b)//2]
else:
 for i in range(len(b) // 2):
  c += sum(b[i:len(b)-i])*2
 c -= min(b[len(b)//2-1],b[len(b)//2])
print(c)

# Optimized solution
n = int(eval(input()))
a = []
b = []
d = []
c = 0
for i in range(n):
 ak = int(eval(input()))
 a.append(ak)
a.sort()
for i in range((len(a)-1)//2):
 d.append(a[-i-1]-a[i])
for i in range(n-1):
 bk = a[i+1] -  a[i]
 b.append(bk)
e = len(b)
c = sum(d) * 2
if e % 2 == 1:
 c += b[e//2]
else:
 c -= min(b[e//2-1],b[e//2])
print(c)
# Original solution
n = int(eval(input()))
a = sorted([int(eval(input())) for i in range(n)])

if n % 2 == 0:
    small = a[:(n//2)]
    big = a[(n//2):]
    ans = sum(big) * 2 - sum(small) * 2  - big[0] + small[-1]
    print(ans)

else:
    small = a[:(n//2)]
    big = a[(n//2):]
    ans = sum(big) * 2 - sum(small) * 2  - big[0] -big[1]

    small = a[:(n//2)+1]
    big = a[(n//2)+1:]
    ans = max(ans, sum(big) * 2 - sum(small) * 2 + small[-1] + small[-2])
    print(ans)


# Optimized solution
n = int(eval(input()))
a = sorted([int(eval(input())) for i in range(n)])
l = n//2

if n % 2 == 0:
    small = a[:l]
    big = a[l:]
    ans = sum(big) * 2 - sum(small) * 2  - big[0] + small[-1]
    print(ans)

else:
    small = a[:l]
    big = a[l+1:]
    ans = sum(big) * 2 - sum(small) * 2 - min(a[l] - small[-1], big[0] - a[l])
    print(ans)
# Original solution
def main():
  N, *A = list(map(int, open(0).read().split()))
  A.sort()

  if N % 2:
    array1 = [-2] * (N // 2) + [1] * 2 + [2] * (N // 2 - 1)
    array2 = [-2] * (N // 2 - 1) + [-1] * 2 + [2] * (N // 2)
  
    ret1 = 0
    ret2 = 0
    for i in range(N):
      ret1 += A[i]*array1[i] 
      ret2 += A[i]*array2[i]
    ret = max(ret1, ret2)

  else:
    array1 = [-2] * (N // 2 - 1) + [-1] + [1] + [2] * (N // 2 - 1)
  
    ret = 0
    for i in range(N):
      ret += A[i]*array1[i] 
  
  print(ret)

  
if __name__=="__main__":
  main()

# Optimized solution
def main():
  N, *A = list(map(int, open(0).read().split()))
  A.sort()

  if N % 2:
    array1 = [-2] * (N // 2) + [1] * 2 + [2] * (N // 2 - 1)
    array2 = [-2] * (N // 2 - 1) + [-1] * 2 + [2] * (N // 2)
  
    ret1 = 0
    ret2 = 0
    for i, j, k in zip(A, array1, array2):
      ret1 += i * j
      ret2 += i * k
    ret = max(ret1, ret2)

  else:
    array1 = [-2] * (N // 2 - 1) + [-1] + [1] + [2] * (N // 2 - 1)
  
    ret = 0
    for i, j in zip(A, array1):
      ret += i * j
  
  print(ret)

  
if __name__=="__main__":
  main()
# Original solution
from collections import *
a = sorted(int(eval(input())) for _ in range(int(eval(input()))))
q = deque(a)
rq = deque([q.popleft()])
while q:
    rq.appendleft(q.pop())
    if q: 
        rq.append(q.pop())
    if q:
        rq.appendleft(q.popleft())
    if q: 
        rq.append(q.popleft())
r1 = sum(abs(i-j) for i, j in zip(rq, list(rq)[1:]))

q = deque(a[::-1])
rq = deque([q.popleft()])
while q:
    rq.appendleft(q.pop())
    if q: 
        rq.append(q.pop())
    if q:
        rq.appendleft(q.popleft())
    if q: 
        rq.append(q.popleft())
r2 = sum(abs(i-j) for i, j in zip(rq, list(rq)[1:]))
print((max(r1, r2)))

# Optimized solution
n = int(eval(input()))
a = sorted(int(eval(input())) for _ in range(n))
if n == 2:
    print((abs(a[0] - a[1])))
elif n%2 == 1:
    r1 = a[n//2] + a[n//2+1] + sum(a[n//2+2:])*2 - sum(a[:n//2])*2
    r2 = sum(a[n//2+1:])*2 - sum(a[:n//2-1])*2 - a[n//2-1] - a[n//2]
    print((max(r1, r2)))
else:
    r1 = sum(a[n//2+1:])*2 + a[n//2] - sum(a[:n//2-1])*2 - a[n//2-1]
    print(r1)
# Original solution
from collections import deque
N = int(eval(input()))
H = []
Q = deque()
for i in range(N):
  A = int(eval(input()))
  H.append(A)
H.sort()
#H = deque(H)

if N%2 == 0:
  groupA = H[:N//2]
  groupB = H[N//2:]
  ans = 2*sum(groupB)-2*sum(groupA)-groupB[0]+groupA[-1]
else:
  groupA1 = H[:N//2]
  groupB1 = H[N//2:]
  groupA2 = H[:N//2+1]
  groupB2 = H[N//2+1:]
  ans1 = 2*sum(groupB1)-2*sum(groupA1)-groupB1[0]-groupB1[1]
  ans2 = 2*sum(groupB2)-2*sum(groupA2)+groupA2[-1]+groupA2[-2]
  ans = max(ans1,ans2)
print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A.sort()

if N%2 == 0:
  S = A[:N//2]
  L = A[N//2:]
  ans = 2*sum(L)-L[0]-2*sum(S)+S[-1]
else:
  S1 = A[:N//2]
  L1 = A[N//2:]
  S2 = A[:N//2+1]
  L2 = A[N//2+1:]
  ans1 = 2*sum(L1)-L1[0]-L1[1]-2*sum(S1)
  ans2 = 2*sum(L2)-2*sum(S2)+S2[-1]+S2[-2]
  ans = max(ans1,ans2)
print(ans)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

A_ = sorted(A)
A_r = list(reversed(A_))

l = []
for i, (x, y) in enumerate(zip(A_[:N//2], A_r[:N//2])):
    if i % 2 == 0:
        l.append(x)
        l.insert(0, y)
    else:
        l.append(y)
        l.insert(0, x)

if N % 2 != 0:
    m = A_[N//2]
    if abs(l[0] - m) > abs(l[-1] - m):
        l.insert(0, m)
    else:
        l.append(m)

def g(L):
    for i, j in zip(L[:-1], L[1:]):
        yield abs(i - j)

print((sum(g(l))))


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

A_ = sorted(A)
A_r = list(reversed(A_))

n = (A_[0], A_r[0])
sum = abs(n[0] - n[1])
for i, (x, y) in enumerate(zip(A_[1:N//2], A_r[1:N//2])):
    sum += abs(n[0] - y) + abs(n[1] - x)
    n = (x, y)

if N%2 != 0:
    m = A_[N//2]
    sum += max(abs(n[0] - m), abs(n[1] - m))

print(sum)