#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int ans = 0, temp = sum / n, cc = sum % n;
  for (int i = 0; i < n; i++) {
    if (!cc && arr[i] > temp) {
      ans += arr[i] - temp;
    } else if (cc && arr[i] > temp) {
      ans += arr[i] - 1 - temp;
      cc--;
    }
  }
  cout << ans;
  return 0;
}
