#include <bits/stdc++.h>
int main() {
  int n;
  int64_t res1 = 0, res2 = 0, sum = 0;
  bool is;
  std::cin >> n;
  std::vector<int> m(n);
  for (int i = 0; i < n; i++) {
    std::cin >> m[i];
    sum += m[i];
  }
  is = sum % n != 0;
  sum /= n;
  for (int i = 0; i < n; i++) {
    if (m[i] < sum) {
      res1 += sum - m[i];
    } else if (is) {
      if (m[i] > sum + 1) {
        res2 += m[i] - sum - 1;
      }
    } else {
      if (m[i] > sum) {
        res2 += m[i] - sum;
      }
    }
  }
  std::cout << std::max(res1, res2);
}
