#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, temp, sum = 0, ans = 0, x, y, mx = 0, mn = 0;
  vector<long long int> a;
  cin >> n;
  long long int t = n;
  while (t--) {
    cin >> temp;
    a.push_back(temp);
    sum += temp;
  }
  if (sum % n == 0) {
    x = sum / n;
    for (int i = 0; i < n; i++) {
      if (a[i] < x)
        mn += x - a[i];
      else
        mx += a[i] - x;
    }
    cout << min(mx, mn) << endl;
  } else {
    x = sum / n;
    y = x + 1;
    for (int i = 0; i < n; i++) {
      if (a[i] <= x)
        mn += x - a[i];
      else
        mx += a[i] - y;
    }
    cout << max(mx, mn) << endl;
  }
}
