#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int n = 0; cin >> n; set st; long long nums[n]; long long num_min = 10000000000; long long num_max = -10000000000; long long tmp = 0; for (int i = 0; i < n; i++) { cin >> tmp; nums[i] = tmp; num_min = min(num_min, tmp); num_max = max(num_max, tmp); st.insert(tmp); } set::iterator itr; /* for (itr = st.begin(); itr != st.end(); ++itr) { std::cout << *itr << "\n"; }*/ long long ans = 10000000000; tmp = 0; for (itr = st.begin(); itr != st.end(); ++itr) { for (int k = 0; k < n; k++) { tmp += abs(nums[k] - *itr); if (tmp > ans) { break; } } ans = min(ans, tmp); tmp = 0; } cout << ans << endl; return 0; }