#include #include #include int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int b; std::cin >> b; int n; std::cin >> n; long long sum = 0; std::vector c; int a; for (int i = 0; i < n; ++i) { std::cin >> a; c.push_back(a); sum += a; } std::sort(c.begin(), c.end()); if (n == 1) { std::cout << "0" << std::endl; return 0; } long long count = 0, t = 20000000000; int lv, i; for (i = 0; i < n; ++i, t = count, count = 0) { for (int j = 0; j < n; ++j) { count += abs(c[i] - c[j]); } if (count >= t) { lv = c[i-1]; break; } } if (i > n) { lv = c[n - 1]; } int sa; if ((sa = lv * n - (sum + b)) > 0) { lv -= sa / n; lv -= ((sa % n) ? 1 : 0); } t = 0; for (int i = 0; i < n; ++i) { t += abs(lv - c[i]); } std::cout << t << std::endl; }