#include #include #include #include #include using ll = long long; using namespace std; const int MOD = 1e9+7; int main() { int N; ll ave = 0, ans = (1LL << 62); cin >> N; vector Y(N); for(int i = 0; i < N; i++) { cin >> Y[i]; ave += Y[i]; } ave /= N; ll sum; do { sum = 0; for(int i = 0; i < N; i++) { sum += abs(Y[i] - ave); } ans = min(ans, sum); ave++; } while (sum == ans); cout << ans << endl; return 0; }