#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int arr[MAXN];
int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int x = sum % n;
  sum /= n;
  int a1 = 0, a2 = 0, b1 = 0, b2 = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] > sum) {
      a1 += arr[i] - sum;
      if (x != 0) {
        x--;
        a1--;
      }
    } else
      a2 += sum - arr[i];
  }
  int ans = max(a1, a2);
  cout << ans << endl;
}
