#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
const long long M = 2111;
const long long INF = 1e18;
const long long inf = -1e18;
const long long MOD = 998244353;
const long long xesh = 31;
long long n, s, a[N], k, ans;
int main() {
  long long o = 1;
  while (o--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      s += a[i];
    }
    if (s % n != 0) {
      k = s % n;
    }
    sort(a + 1, a + n + 1);
    for (int i = n - k + 1; i <= n; i++) {
      if (a[i] < s / n + 1) {
        ans += s / n - a[i] + 1;
      }
    }
    for (int i = 1; i <= n - k; i++) {
      if (a[i] < s / n) {
        ans += s / n - a[i];
      }
    }
    cout << ans;
  }
}
