typedef long long ll; #include using namespace std; int main() { ll n; std::cin >> n; vector y(n); for (int i = 0; i < n; i++) { std::cin >> y[i]; } sort(y.begin(),y.end()); if(y[0] == y[n-1]){ std::cout << 1 << std::endl; return 0; } vector sum(n+1); for (int i = 0; i < n; i++) { sum[i+1] = sum[i]+y[i]; } ll result = 1e15; for (int i = 0; i < n-1; i++) { ll dv,uv; ll m = i/2; if(i%2==0){ dv = sum[i+1] -sum[m+1] - sum[m]; }else{ dv = sum[i+1] -sum[m+1] -sum[m+1]; } m = (n-i)/2+i; if( (n-i)%2==0 ){ uv = sum[n] - sum[m+1] - (sum[m]-sum[i+1]); }else{ uv = sum[n] - sum[m+1] - (sum[m+1]-sum[i+1]); } result = min(uv+dv,result); } std::cout << result << std::endl; }