#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n], sum = 0;
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  sort(a, a + n);
  long long re = 0, av = sum / n, jabe = 0;
  int mod = sum % n;
  for (int i = n - 1; i >= 0; i--) {
    if (av < a[i]) {
      if (mod)
        re += a[i] - 1 - av, mod--;
      else
        re += a[i] - av;
    } else {
      cout << re << endl;
      break;
    }
  }
  return 0;
}
