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