#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
void solve() {
  long long n;
  cin >> n;
  ;
  long long sum = 0;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end(), greater<long long>());
  long long avg = sum / n;
  long long extra = sum - (avg * n);
  long long diff = 0;
  for (long long i = 0; i < n; i++) {
    long long d = avg;
    if (i < extra) d++;
    diff += abs(d - a[i]);
  }
  cout << diff / 2 << endl;
}
signed main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  solve();
}
