#include <bits/stdc++.h>
using namespace std;
int n;
long long int sum;
vector<long long int> v;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long int a;
    scanf("%I64d", &a);
    sum += a;
    v.push_back(a);
  }
  long long int f = sum / (long long int)(n);
  long long int k = sum % (long long int)(n);
  long long int mint = f;
  long long int mint_cnt = n - k;
  long long int maxt = f + 1;
  long long int maxt_cnt = k;
  sort(v.begin(), v.end());
  long long int need = 0;
  for (int i = 0; i < mint_cnt; i++) {
    need += abs(v[i] - mint);
  }
  for (int i = mint_cnt; i < v.size(); i++) {
    need += abs(v[i] - maxt);
  }
  need /= 2LL;
  printf("%lld\n", need);
  return 0;
}
