from itertools import permutations
n = int(input())
num_list = list(map(int, input().split()))
res_list = list(set(permutations(num_list, n)))
res = -1e9
for i in res_list:
tmp = 0
tmp_list = list(i)
for j in range(len(tmp_list)-1):
tmp += abs(tmp_list[j]-tmp_list[j+1])
res = max(res, tmp)
print(res)