#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int serv[100005] = {0};
  int64_t nig = 0;
  for (int i = 0; i < n; ++i) {
    cin >> serv[i];
    nig += serv[i];
  }
  nig = nig / n;
  int64_t res1 = 0;
  int64_t res2 = 0;
  for (int i = 0; i < n; ++i) {
    if (serv[i] < nig) res1 += nig - serv[i];
  }
  for (int i = 0; i < n; ++i)
    if (serv[i] > nig + 1) res2 += serv[i] - nig - 1;
  cout << max(res1, res2);
  return 0;
}
