import java.util.*;
public class BOJ_10819 {
static int[] arr;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
int max = 0;
while (nextPermutation()) {
int answer = 0;
for (int i = 0; i < n - 1; i++) {
answer += Math.abs(arr[i] - arr[i + 1]);
}
max = Math.max(answer, max);
}
System.out.println(max);
}
private static boolean nextPermutation() {
int idx = arr.length - 1;
while (true) {
if (idx == 0) {
return false;
}
if (arr[idx - 1] >= arr[idx]) {
idx -= 1;
continue;
}
int i = idx;
int j = -1;
for (int k = idx - 1; k < arr.length; k++) {
if (arr[idx - 1] < arr[k])
j = k;
}
if (j != -1) {
swap(i - 1, j);
reverse(i);
break;
}
}
return true;
}
private static void reverse(int lh) {
int temp = 0;
int rh = arr.length - 1;
while (lh < rh) {
temp = arr[lh];
arr[lh] = arr[rh];
arr[rh] = temp;
lh += 1;
rh -= 1;
}
}
private static void swap(int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}