#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int arr[N];
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long int sum = accumulate(arr, arr + n, 0);
  long long int mini = sum / n, maxi = n - (sum % n), cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (arr[i] < mini) cnt += mini - arr[i];
    maxi--;
    if (maxi == 0) mini++;
  }
  cout << cnt << endl;
}
