#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 20;
long long n, a[N], sum, ans, p1, p2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  sort(a, a + n);
  long long t1 = sum / n, t2 = (sum + n - 1) / n, ex = n - sum % n;
  p1 = 0, p2 = n - 1;
  while (p1 < p2) {
    long long &x = a[p1], &y = a[p2];
    long long te1 = (p1 < ex) ? t1 : t2, te2 = (p2 < ex) ? t1 : t2;
    if (x < te1 || y > te2) {
      int t = min(te1 - x, y - te2);
      ans += t;
      x += t;
      y -= t;
    }
    if (x == te1) p1++;
    if (y == te2) p2--;
  }
  return cout << ans, 0;
}
