#include <bits/stdc++.h>
using namespace std;
int n, m, ave1, ave2, ans1, ans2;
int a[567890], sum;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
  sort(a + 1, a + n + 1);
  int ave1 = sum / n;
  if (ave1 * n == sum)
    ave2 = ave1;
  else
    ave2 = ave1 + 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] < ave1) ans1 += (ave1 - a[i]);
    if (a[i] > ave2) ans2 += (a[i] - ave2);
  }
  printf("%d", ans1 > ans2 ? ans1 : ans2);
  return 0;
}
