#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
LL res;
int a[N];
int main(){
scanf("%d",&n);
for(int i = 0;i < n;++i) scanf("%d",&a[i]);
sort(a,a + n);
for(int i = 0;i < n;++i){
res += abs(a[i] - a[i >> 1]);
}
printf("%lld\n",res);
return 0;
}