#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
  int n, sum = 0, i;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  if (sum % n == 0) {
    sum /= n;
    int ans = 0;
    for (i = 0; i < n; ++i) ans += max(0, sum - a[i]);
    cout << ans << endl;
  } else {
    int tmp = sum / n;
    for (i = 0; i < sum % n; ++i) b[i] = tmp + 1;
    for (; i < n; ++i) b[i] = tmp;
    sort(a, a + n);
    sort(b, b + n);
    int ans = 0;
    for (i = 0; i < n; ++i) ans += abs(a[i] - b[i]);
    cout << ans / 2 << endl;
  }
  return 0;
}
