#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  cin >> n;
  long prom = 0, cont1 = 0, cont2 = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    prom += v[i];
  }
  if (prom % n == 0) {
    a = b = prom / n;
  } else {
    a = prom / n;
    b = a + 1;
  }
  for (int i = 0; i < n; i++) {
    if (v[i] <= a) {
      cont1 += a - v[i];
    } else {
      cont2 += v[i] - b;
    }
  }
  cout << max(cont1, cont2);
  return 0;
}
