#include <bits/stdc++.h>
using namespace std;
int a[123456], n;
long long LessThanMin = 0, GreaterThanMax = 0, mn, mx, sum = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  mx = mn = sum / n;
  if (sum > (mx * n)) mx++;
  for (int i = 0; i < n; i++) {
    if (a[i] < mn)
      LessThanMin += (mn - a[i]);
    else if (a[i] > mx)
      GreaterThanMax += (a[i] - mx);
  }
  cout << max(LessThanMin, GreaterThanMax) << endl;
  return 0;
}
