#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 12;
int n, sum, a[maxn];
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &(a[i])), sum += a[i];
  sort(a, a + n);
  int ans = 0;
  int l = sum / n, r;
  r = l + 1;
  int y = n - sum + l * n;
  for (int i = 0; i < n; i++) {
    while (i < y) {
      ans += abs(a[i] - l);
      i++;
    }
    while (i < n) {
      ans += abs(r - a[i]);
      i++;
    }
  }
  cout << ans / 2 << endl;
}
