#include #include #include #include #include #include #include #include #include #include #include #include #include #define CK(N, A, B) (A <= N && N < B) #define REP(i, a, b) for (int i = a; i < b; i++) #define RREP(i, a, b) for (int i = (b - 1); a <= i; i--) #define F first #define S second #define ll long long const int INF = 1e9; const long long LLINF = 1e18; using namespace std; int dy[] = {0,1,0,-1}; int dx[] = {1,0,-1,0}; int dy8[] = {0,1,1,1,0,-1,-1,-1}; int dx8[] = {1,1,0,-1,-1,-1,0,1}; /*==================================================*/ /*variable*/ int N; double Y[100010]; map m; /*==================================================*/ /*function*/ /*==================================================*/ int main() { cin>>N; double sum = 0; REP(i,0,N){ cin>>Y[i]; sum += Y[i]; m[Y[i]]++; } double ave = sum / (double)N; auto itr = m.begin(); double n = -1, mx = (double)LLINF; while(itr != m.end()){ if(mx > (*itr).S * fabs((*itr).F - ave)){ n = (*itr).F; mx = (*itr).S * fabs((*itr).F - ave); } itr++; } double ans = 0; REP(i,0,N){ ans += fabs(Y[i] - ave); } cout<<(ll)ans<