#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long p = sum % n;
  long long d = sum / n;
  long long q = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > d) {
      q = q + a[i] - d;
      if (p > 0) {
        q--;
        p--;
      }
    }
  }
  cout << q << endl;
}
