#include <bits/stdc++.h>
using namespace std;
int N, M;
int a[200005];
int sum = 0;
int vis0, vis1;
int cnt0, cnt1;
int n0, n1;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  n0 = sum / N;
  if (sum % N) {
    n1 = n0 + 1;
    cnt1 = sum % N;
    cnt0 = N - cnt1;
  } else
    cnt0 = N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (a[i] <= n0) {
      if (cnt0) {
        ans += (n0 - a[i]);
        cnt0--;
      } else {
        ans += (n1 - a[i]);
        cnt1--;
      }
    } else {
      if (cnt1) {
        ans += abs(n1 - a[i]);
        cnt1--;
      } else {
        ans += abs(n0 - a[i]);
        cnt0--;
      }
    }
  }
  cout << ans / 2;
  return 0;
}
