#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
typedef long long LL;
int pos[N];
int n, c;
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ ) scanf("%d", &pos[i]); //读入每个商店的坐标
sort(pos, pos + n);
int c = pos[n / 2]; //存中心点坐标
LL res = 0;
for (int i = 0; i < n; i ++ ) res += abs(c - pos[i]);
printf("%lld", res);
return 0;
}