#include #define rep(i, a, n) for(int i = a; i < n; i++) #define int long long using namespace std; typedef pair P; const int mod = 1000000007; const int INF = 1e18; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); rep(i, 1, n){ if(a[i] != a[0]) break; if(i == n - 1){ cout << 1 << endl; return 0; } } int l = n / 4; int r = n - 1 - n / 4; int ans = 0; rep(i, 0, n){ ans += min(abs(a[i] - a[l]), abs(a[i] - a[r])); } cout << ans << endl; }