贪心
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1E5 + 10;
typedef long long ll;
int ads[N];
int main(){
int n; cin >> n;
for(int i = 0; i < n; i ++ ) cin >> ads[i];
sort(ads, ads + n);
ll res = 0;
for(int i = 0; i < n; i ++ ) res += abs(ads[n / 2] - ads[i]);
cout << res << endl;
return 0;
}