#include <bits/stdc++.h>
using namespace std;
const int MM = 100000 + 5;
int main() {
  int n;
  int M[MM];
  int i;
  int sum, count, average, remainder;
  while (cin >> n) {
    for (i = 0, sum = 0; i < n; i++) {
      cin >> M[i];
      sum += M[i];
    }
    average = sum / n;
    remainder = sum % n;
    for (i = 0, sum = count = 0; i < n; i++) {
      if (M[i] > average) {
        count++;
        sum += M[i] - average;
      }
    }
    count = count < remainder ? count : remainder;
    cout << sum - count << endl;
  }
  return 0;
}
