#define rep(i, n) for(int i = 0; i < (int)(n); i++) 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]; y[i]+=1e9; } 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 d,u,ijou; d = round(sum[i+1]*1.0/(i+1)); u = round((sum[n]-sum[i+1])*1.0/(n-i-1)); ijou = distance(y.begin(),lower_bound(y.begin(),y.end(),d)); ll dv = d*ijou-sum[ijou]+(sum[i+1]-sum[ijou])-d*(i+1-ijou); ijou = distance(y.begin(),lower_bound(y.begin(),y.end(),u)); ll uv = u*(ijou-i-1)-(sum[ijou]-sum[i+1])+(sum[n]-sum[ijou])-u*(n-ijou); result = min(dv+uv,result); } std::cout << result << std::endl; }