#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) cin >> v[i], sum += v[i];
    long long q = sum / n;
    long long seconds = 0;
    long long r = sum % n;
    long long x = 0;
    int i = 0;
    for (i = 0; i < n; i++) {
      if (v[i] <= q) seconds += abs(q - v[i]), x++;
    }
    seconds += max(0ll, r - n + x);
    cout << seconds;
  }
}
