#include <bits/stdc++.h>
using namespace std;
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
int bin(int l, int h, int key, vector<int> arr) {
  while (l <= h) {
    int mid = (l + h) / 2;
    if (arr[mid] == key)
      return mid;
    else if (key > arr[mid])
      l = mid + 1;
    else
      h = mid - 1;
  }
  return -1;
}
int modulo(int value, int m) {
  int mod = value % (int)m;
  if (value < 0) {
    mod += m;
  }
  return mod;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, sum = 0;
  cin >> n;
  vector<int> arr(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int x = sum / n;
  for (int i = 0; i < n; i++) v[i] = x;
  for (int i = 0; i < sum % n; i++) v[i] += 1;
  sort((v).begin(), (v).end());
  sort((arr).begin(), (arr).end());
  int a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] - arr[i] < 0)
      a += abs(v[i] - arr[i]);
    else
      b += (v[i] - arr[i]);
  }
  cout << min(a, b);
  return 0;
}
