#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, sum = 0, pos = 0, ans1 = 0, ans2 = 0;
  cin >> n;
  vector<unsigned long long int> vect;
  vect.resize(n);
  for (unsigned long long int i = 0; i < n; i++) {
    cin >> vect[i];
    sum += vect[i];
  }
  if (sum % n == 0) {
    pos = sum / n;
    for (unsigned long long int i = 0; i < n; i++) {
      if (vect[i] > pos) {
        ans1 += vect[i] - pos;
      }
    }
    cout << ans1 << endl;
  } else {
    pos = (sum / n) + 1;
    for (unsigned long long int i = 0; i < n; i++) {
      if (vect[i] > pos) {
        ans1 += vect[i] - pos;
      } else if (vect[i] < pos - 1) {
        ans2 += pos - 1 - vect[i];
      }
    }
    cout << max(ans1, ans2) << endl;
  }
  return 0;
}
