#include #include #include int main(){ int N; std::cin >> N; std::vector v(N); for(int i = 0; i < N; i++){ std::cin >> v[i]; } int high = 1e9; int low = -1e9; while(high - low > 1){ long long mid = (high + low) / 2; long long cnt = 0; for(int i = 0; i < N; i++){ cnt += mid - v[i]; } if(cnt >= 0)high = mid; else low = mid; } std::cerr << low << " " << high << std::endl; long long ans = 0; for(int i = 0; i < N; i++){ ans += std::abs(high - v[i]); } std::cout << ans << std::endl; }