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