#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector Y(N); for (auto &&e : Y) { cin >> e; } sort(Y.begin(), Y.end()); int64_t res = 0; if (N % 2 == 0) { int64_t a = 0, b = 0; for (auto &&e : Y) { a += abs(e - Y[N / 2]); b += abs(e - Y[N / 2 - 1]); } res = min(a, b); } else { for (auto &&e : Y) { res += abs(e - Y[N / 2]); } } cout << res << '\n'; return 0; }