#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long Array[n];
  long long sum = 0LL, diff, required, ans = 0LL, mod = 0LL;
  for (int i = 0; i < n; i++) {
    cin >> Array[i];
    sum += Array[i];
  }
  required = sum / n;
  mod = sum % n;
  for (int i = 0; i < n; i++) {
    if (Array[i] > required)
      mod--;
    else
      ans += required - Array[i];
  }
  cout << ans + max(mod, 0LL) << "\n";
}
