#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main() {
  int i, num, sum = 0, ans = 0, counter = 0;
  cin >> num;
  for (i = 0; i < num; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  int temp = sum / num;
  for (i = 0; i < num; i++) {
    if (a[i] < temp)
      ans += temp - a[i];
    else if (a[i] > temp)
      counter++;
  }
  temp = sum % num;
  if (counter < temp) ans += temp - counter;
  cout << ans << endl;
  return 0;
}
