#include "bits/stdc++.h" // Custom Header <<< #define ALL(x) x.begin(), x.end() #define rep(i, s, n) for(int i(s); i < int(n); ++i) #ifndef YDK #define eprintf(...) #endif using namespace std; using i64 = long long; using pii = pair; templateinline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;} templateinline bool chmin(A &a, const B &b){return b>> i64 slv(const int *a, const int *end) { const int N = end - a; i64 sum = 0; if (N & 1) { const int med = a[N / 2]; rep(i, 0, N) { sum += abs(med - a[i]); } } else { sum = LINF; for (int med : {a[N/2], a[N/2-1]}) { i64 tmp = 0; rep(i, 0, N) { tmp += abs(med - a[i]); } chmin(sum, tmp); } } return sum; } signed main() { int N; int a[100010]; cin >> N >> a[0]; rep(i, 1, N) cin >> a[i]; sort(a, a+N); if (a[0] == a[N-1]) { cout << 1 << endl; return 0; } const int mid = N / 2; i64 ans = LINF; rep(i, max(0, mid - 2), min(N, mid + 3)) { // rep(i, 0, mid) { cout << a[i] << ' '; } cout << endl; // rep(i, mid, N) { cout << a[i] << ' '; } cout << endl; chmin(ans, slv(a, a+i) + slv(a+i, a+N)); } cout << ans << endl; return 0; } /* vim:set foldmethod=marker foldmarker=<<<,>>> : */