#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int a[N], b[N];
int main() {
  srand(time(NULL));
  int n;
  cin >> n;
  long long sum = 0LL;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int g = sum / n;
  int kald = sum % n;
  for (int i = 1; i <= n; i++) {
    if (kald > 0) {
      b[i]++;
      kald--;
    }
    b[i] += g;
  }
  sort(b + 1, b + 1 + n);
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += abs(a[i] - b[i]);
  }
  cout << ans / 2;
  return 0;
}
