#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lb = long double;
using db = double;
const long double pi = 2 * asin(1.0);
const int maxn = 100001;
int a[maxn];
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  sort(a, a + n);
  ll ave = sum / n;
  ll re1 = 0;
  for (int i = 0; i < n - sum % n; i++) {
    re1 += abs(a[i] - ave);
  }
  for (int i = n - sum % n; i < n; i++) re1 += abs(a[i] - ave - 1);
  cout << re1 / 2 << endl;
  return 0;
}
