// No.609 Noelちゃんと星々 // https://yukicoder.me/problems/no/609 // #include #include #include #include using namespace std; long long int solve(vector &stars, int N); long long calc_score(int n, vector& stars); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); unsigned int N; cin >> N; vector stars(N); for (int i = 0; i < N; ++i) cin >> stars[i]; long long ans = solve(stars, N); cout << ans << endl; } long long int solve(vector &stars, int N) { sort(stars.begin(), stars.end()); int median; if (N % 2 == 1) median = stars[N/2]; else median = (stars[(N-1)/2] + stars[N/2]) / 2; long long ans = calc_score(median, stars); return ans; } long long calc_score(int n, vector& stars) { long long ans = 0; for (auto s: stars) { ans += abs(s - n); } return ans; }