#include <bits/stdc++.h>
using namespace std;
const long long int infi = 1e9;
const long long infl = 1e18;
const long long int MOD = 1e9 + 7;
template <typename Map>
bool map_compare(Map const& lhs, Map const& rhs) {
  return lhs.size() == rhs.size() &&
         std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 mt(seed);
long long int randint(long long int p = MOD) { return mt() % p; }
long long randlong(long long p = infl) { return mt() % p; }
long long int modpow(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n % 2) res = (res * x) % MOD;
    x = (x * x) % MOD;
    n /= 2;
  }
  return res;
}
long long int inv(long long int x) { return modpow(x, MOD - 2); }
long long log_2(long long n) { return (n > 1ll) ? 1ll + log_2(n / 2) : 0ll; }
long long log_10(long long n) { return (n > 1ll) ? 1ll + log_10(n / 10) : 0ll; }
inline long long int add(long long int a, long long int b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}
inline long long int sub(long long int a, long long int b) {
  return ((a % MOD) - (b % MOD) + MOD) % MOD;
}
inline long long int mul(long long int a, long long int b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}
template <class T>
struct cmp {
  bool operator()(const T& x, const T& y) const { return x > y; }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int m[n];
  for (long long int i = 0; i < n; i++) cin >> m[i];
  sort(m, m + n);
  long long int s = 0;
  for (long long int i = 0; i < n; i++) s += m[i];
  long long int p = s / n;
  long long int q = s % n;
  long long int ans = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    if (q != 0) {
      ans += abs((p + 1) - m[i]);
      q--;
    } else {
      ans += abs(p - m[i]);
    }
  }
  cout << ans / 2 << "\n";
  return 0;
}
