#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int s = 0, a[n];
  long long int i;
  for (i = 0; i <= n - 1; i++) {
    cin >> a[i];
    s += a[i];
  }
  s = s / n;
  long long int t = 0;
  long long int ll = 0;
  for (i = 0; i <= n - 1; i++) {
    if (a[i] < s) t += s - a[i];
    if (a[i] >= s + 1) ll += a[i] - s - 1;
  }
  cout << max(t, ll);
}
