#include <bits/stdc++.h>
using namespace std;
const int maxn = 10e5;
long long int a[maxn];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << setprecision(30);
  long long int n, rem = 0;
  long long int jam = 0, mian = 0, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    jam += a[i];
  }
  sort(a, a + n);
  mian = jam / n;
  cerr << "jam"
       << "=" << jam << "\n";
  cerr << "mian"
       << "=" << mian << "\n";
  rem = jam % n;
  cerr << "rem"
       << "=" << rem << "\n";
  for (int i = n - 1; i >= 0; i--) {
    if (rem) {
      rem--;
      ans += abs(a[i] - mian - 1);
    } else {
      ans += abs(a[i] - mian);
    }
  }
  cout << ans / 2;
  return 0;
}
