#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)(1e9 + 1e6);
const long long LINF = (long long)(4e18);
const double EPS = 1e-9;
const long long mod = 1e9 + 7;
mt19937 ggen;
void solve();
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  ggen = mt19937(1337);
  solve();
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  int ft = sum / n;
  int fft = 0;
  int lt = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] > ft) {
      fft++;
      lt += a[i] - ft;
    } else if (a[i] < ft) {
      lt -= ft - a[i];
      ans += ft - a[i];
    }
  }
  if (lt > 0) {
    ans += max(0, lt - fft);
  }
  cout << ans;
}
