#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
const long long mod = 1e9 + 7;
void unify(vector<int>& v) {
  auto ip = unique(v.begin(), v.end());
  v.resize(distance(v.begin(), ip));
}
long long gcd(long long int x, long long int y) {
  return y == 0 ? x : gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
bool isPower2(long long x) { return x && (!(x & (x - 1))); }
const int N = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<int> t(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    sum += t[i];
  }
  long long cnt = sum / n, rem = sum % n, ans = 0;
  for (int i = 0; i < n && rem; i++) {
    if (t[i] > cnt) {
      ans += (t[i] - cnt - 1);
      t[i] = -1;
      rem--;
    }
  }
  for (int i = 0; i < n; i++) {
    if (t[i] == -1 || t[i] < cnt) continue;
    ans += (t[i] - cnt);
    t[i] = -1;
  }
  cout << ans << endl;
}
int main() {
  int t = 1;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
  return 0;
}
