#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[123456];
  int avg[123456];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long count = 0;
  for (int i = 0; i < n; i++) count += a[i];
  int Max = count / n;
  int rem = count % n;
  long long c = 0;
  for (int i = 0; i < n; i++) avg[i] = Max;
  sort(a, a + n);
  for (int i = n - 1; i >= 0; i--) {
    if (!rem) continue;
    avg[i]++;
    rem--;
  }
  for (int i = 0; i < n; i++)
    if (a[i] > avg[i]) c += a[i] - avg[i];
  cout << c << endl;
  return 0;
}
