#include <bits/stdc++.h>
using namespace std;
int static fast = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
int main() {
  int n;
  cin >> n;
  vector<long long> arr(n, 0);
  for (auto& val : arr) cin >> val;
  long long acc = accumulate(arr.begin(), arr.end(), 0LL);
  if (acc % n == 0) {
    long long ans = 0, avg = acc / n;
    for (auto& val : arr)
      if (val >= avg) ans += (val - avg);
    cout << ans << "\n";
    return 0;
  }
  long long avg = acc / n;
  long long ans = 0, sm_cnt = 0;
  long long target_lg_cnt = acc % n;
  sort(arr.rbegin(), arr.rend());
  for (int i = 0; i < n; i++) {
    long long target = avg + (i < target_lg_cnt);
    ans += llabs(arr[i] - target);
  }
  cout << ans / 2 << "\n";
  return 0;
}
