#include #include #include using namespace std; int main(void){ int n; cin >> n; long y[n]; for(int i = 0; i < n; i++) cin >> y[i]; sort(y, y + n); long long ans = 0; for(int i = 0; i < n; i++){ ans += abs(y[i] - y[n / 2]); } cout << ans << endl; return 0; }