#include <bits/stdc++.h>
const int N = 200000;
using namespace std;
int n;
int ar[N];
int s;
int full, rem;
int need[N];
int ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    s += ar[i];
  }
  sort(ar, ar + n);
  full = s / n;
  rem = s % n;
  for (int i = 0; i < n; i++) {
    need[i] = full;
  }
  for (int i = n - 1; i >= 0; --i) {
    if (rem == 0) continue;
    need[i]++;
    rem--;
  }
  for (int i = 0; i < n; i++) {
    if (ar[i] > need[i]) ans += ar[i] - need[i];
  }
  cout << ans << endl;
  cin.get();
  return 0;
}
