#include <bits/stdc++.h>
using namespace std;
long long int mint(long long int x, long long int y) { return (x < y) ? x : y; }
int main() {
  long long int n, i;
  cin >> n;
  long long int sum = 0, arr[n];
  for (i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
  }
  sum = sum / n;
  long long int ans = 0, ans1 = 0;
  for (i = 0; i < n; ++i) {
    if (arr[i] < sum) {
      ans += sum - arr[i];
    } else if (arr[i] > sum)
      ans1 += arr[i] - sum - 1;
  }
  cout << max(ans, ans1);
  return 0;
}
