#include <bits/stdc++.h>
using namespace std;
long long n, sum, ans, a[100005];
inline long long read() {
  long long q = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    q = (q << 3) + (q << 1) + (ch ^ 48);
    ch = getchar();
  }
  return f ? q : -q;
}
inline void print(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
signed main() {
  n = read();
  for (register long long i = 1; i <= n; ++i) a[i] = read(), sum += a[i];
  sort(a + 1, a + n + 1, greater<long long>());
  for (register long long i = 1; i <= (sum % n); ++i)
    ans += abs(a[i] - sum / n - 1);
  for (register long long i = (sum % n) + 1; i <= n; ++i)
    ans += abs(a[i] - sum / n);
  print(ans >> 1);
  return 0;
}
