#include <bits/stdc++.h>
using namespace std;
int d[10];
int main() {
  int n, s = 0;
  cin >> n;
  vector<int> m(n);
  for (int j = 0; j < n; j++) {
    cin >> m[j];
    s += m[j];
  }
  int a = s / n, b = s % n;
  s = 0;
  for (int j = 0; j < n; j++) {
    if (a < m[j]) {
      if (b) {
        m[j]--;
        b--;
      }
      s += m[j] - a;
    }
  }
  cout << s;
}
