# https://www.acmicpc.net/problem/10819

from sys import stdin
from itertools import permutations


N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))

ans = 0
for case in permutations(A):
    tmp = sum(abs(case[i] - case[i+1]) for i in range(N-1))
    ans = max(ans, tmp)

print(ans)
8b70e96bed093d134c1328a8c38c075cf5e444ea
<mask token>

<mask token>
for case in permutations(A):
    tmp = sum(abs(case[i] - case[i + 1]) for i in range(N - 1))
    ans = max(ans, tmp)
print(ans)

<mask token>
N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))
ans = 0
for case in permutations(A):
    tmp = sum(abs(case[i] - case[i + 1]) for i in range(N - 1))
    ans = max(ans, tmp)
print(ans)

from sys import stdin
from itertools import permutations
N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))
ans = 0
for case in permutations(A):
    tmp = sum(abs(case[i] - case[i + 1]) for i in range(N - 1))
    ans = max(ans, tmp)
print(ans)

# https://www.acmicpc.net/problem/10819

from sys import stdin
from itertools import permutations


N = int(stdin.readline())
A = list(map(int, stdin.readline().split()))

ans = 0
for case in permutations(A):
    tmp = sum(abs(case[i] - case[i+1]) for i in range(N-1))
    ans = max(ans, tmp)

print(ans)