#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int i;
  vector<int> a;
  long long s = 0;
  for (i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
    s += t;
  }
  long long k = 0;
  if (s % n == 0)
    s /= n;
  else {
    k = s / n;
    s = s / n + 1;
  }
  long long ans = 0, ans2 = 0;
  if (k != 0) {
    for (i = 0; i < n; i++)
      if (k > a[i]) ans2 += (k - a[i]);
  }
  for (i = 0; i < n; i++)
    if (a[i] > s) ans += (a[i] - s);
  if (ans2 != 0) {
    cout << max(ans, ans2);
    return 0;
  }
  cout << ans;
  return 0;
}
