#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; int main() { int N; cin >> N; vector V(N); for ( int i = 0; i < N; i++ ) { cin >> V[i]; } sort( V.begin(), V.end() ); long long mid = V[N/2]; // cout << mid << endl; long long ans = 0; for ( int i = 0; i < N; i++ ) { ans += abs( mid - V[i] ); } cout << ans << endl; return 0; }