#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  int q = sum / n;
  int r = sum % n;
  int b[n];
  for (int i = n - 1; i >= 0; i--) {
    if (r > 0) {
      b[i] = q + 1;
      r--;
    } else {
      b[i] = q;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] > a[i]) {
      ans += (b[i] - a[i]);
    }
  }
  cout << ans << "\n";
  return 0;
}
