#include <bits/stdc++.h>
using namespace std;
int n, lis[100010];
int main() {
  int i, sum = 0, ans1 = 0, ans2 = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &lis[i]);
    sum += lis[i];
  }
  sum /= n;
  sort(lis, lis + n);
  for (i = 0; i < n; i++)
    if (lis[i] > sum) ans1 += lis[i] - sum - 1;
  for (i = 0; i < n; i++)
    if (lis[i] < sum) ans2 += sum - lis[i];
  if (ans2 > ans1) ans1 = ans2;
  printf("%d\n", ans1);
  return 0;
}
