#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} _;
int const N = 1e5 + 16;
int a[N];
int b[N];
int main() {
  int n;
  scanf("%d", &n);
  long long count = 0;
  for (int i = n - 1; i >= 0; --i) {
    scanf("%d", &a[i]);
    count += a[i];
  }
  sort(a, a + n);
  long long best = count / n;
  long long left = count % n;
  for (int i = n - 1; i >= 0; --i) b[i] += (best + (--left >= 0 ? 1 : 0));
  long long diff = 0;
  for (int i = n - 1; i >= 0; --i) diff += abs(a[i] - b[i]);
  printf("%d", int(diff >> 1));
}
