// yukicoder: No.609 Noelちゃんと星々 // 2019.5.5 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() // 整数の入力(負数対応) { int n = 0, c = gc(); if (c == '-') { c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return -n; } do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } #define ABS(x) ((x)>=0?(x):-(x)) int y[100005]; int main() { int i, N, t; long long s, min; N = in(); s = 0; for (i = 0; i < N; i++) { y[i] = in(); s += y[i]; } t = (int)(s / N); min = 0; for (i = 0; i < N; i++) min += ABS(y[i]-t); if (s % N) { t++; s = 0; for (i = 0; i < N; i++) s += ABS(y[i]-t); if (s < min) min = s; } printf("%lld\n", min); return 0; }