#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int difference(int n, vector<int>& array) {
int max = 0;
sort(array.begin(), array.end());
do {
int now = 0;
for (int i = 0; i < n - 1; ++i) {
now += abs(array[i] - array[i + 1]);
}
if (now > max) {
max = now;
}
} while (next_permutation(array.begin(), array.end()));
return max;
}
int main() {
int a;
cin >> a;
vector<int> array(a);
for (int i = 0; i < a; ++i) {
cin >> array[i];
}
cout << difference(a, array) << endl;
return 0;
}