#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
int n;
int a[MaxN + 5], b[MaxN + 5];
int st[MaxN + 5];
int main() {
  while (scanf("%d", &n) != EOF) {
    int sum = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      sum += a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) b[i] = sum / n;
    for (int i = 1; i <= sum % n; i++) b[n - i + 1]++;
    for (int i = 1; i <= n; i++) st[i] = a[i] - b[i];
    for (int i = 1; i <= n; i++)
      if (st[i] > 0) ans += st[i];
    printf("%d\n", ans);
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(st, 0, sizeof(st));
  }
  return 0;
}
