#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b v){ int n=(int)v.size(); vector sum(n+1,0); rep(i,n) sum[i+1]=sum[i]+v[i]; ll ret=LINF; rep(i,n){ ll res=-sum[i]+i*v[i]+(sum[n]-sum[i+1])-(n-1-i)*v[i]; chmin(ret,res); } return ret; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n;cin>>n; vector v(n); rep(i,n) cin>>v[i]; sort(ALL(v)); if(v[0]==v[n-1]){ cout<<1< l,r; l.push_back(v[0]); for(int i=1;i0){ chmin(ans,solve(l)+solve(r)); l.push_back(r.front()); r.pop_front(); } cout<