#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int a;
int arr[100002];
int main() {
  long long all = 0;
  scanf("%d", &a);
  for (int i = 0; i < a; ++i) {
    scanf("%d", arr + i);
    all += arr[i];
  }
  long long ans = 0;
  long long ans1 = 0;
  int each;
  each = all / a;
  for (int i = 0; i < a; i++) {
    if (arr[i] < each) ans1 += each - arr[i];
  }
  if (all % a != 0) each++;
  for (int i = 0; i < a; i++) {
    if (arr[i] > each) ans += arr[i] - each;
  }
  cout << max(ans, ans1);
  return 0;
}
