#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
int n;
cin >> n;
int nums[n];
for (int i = 0;i < n;i++) {
cin >> nums[i];
}
sort(nums,nums + n);
int pos = nums[n / 2],ans = 0;
for (int i = 0;i < n;i++) {
ans += abs(nums[i] - pos);
}
cout << ans << endl;
}