#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
int m = a[n/2];
int res = 0;
for (int i: a) {
res += abs(i-m);
}
cout << res << endl;
return 0;
}