#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector v(n); REP (i, n) cin >> v[i]; sort(v.begin(), v.end()); long long sum = 0; REP (i, n) sum += abs(v[i] - v[n/2]); cout << sum << endl; return 0; }