#include using namespace std; #define int long long int a[100010]; int rui[100010] = {}; signed main(){ int n; cin >> n; for(int i = 0;i < n;i++){ cin >> a[i]; } sort(a, a+n); if(a[0] == a[n-1]){ cout << 1 << endl; return 0; } for(int i = 0;i < n;i++){ rui[i+1] = rui[i] + a[i]; } int ans = LLONG_MAX; for(int i = 1;i < n;i++){ int tmp = 0; int idx = (i/2); tmp += (a[idx] * (idx) - rui[idx]) + (rui[i] - rui[idx+1]) - (a[idx] * (i-idx-1)); int idx2 = (i+n)/2; tmp += (a[idx2] * (idx2-i) - (rui[idx2]-rui[i])) + (rui[n] - rui[idx2+1]) - (a[idx2] * (n-idx2-1)); ans = min(ans, tmp); } cout << ans << endl; return 0; }