#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int a[maxn];
int tot;
int n, m, m2, ans, ans2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tot += a[i];
  m = tot / n;
  m2 = m + (tot % n == 0 ? 0 : 1);
  for (int i = 1; i <= n; i++)
    if (a[i] < m)
      ans += m - a[i];
    else if (a[i] > m2)
      ans2 += a[i] - m2;
  printf("%d", max(ans, ans2));
  return 0;
}
