#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
unsigned long long int m[MAXN];
int main() {
  unsigned long long int n;
  unsigned long long int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    sum += m[i];
  }
  unsigned long long int avg1 = sum / n;
  unsigned long long int avg2 = sum / n + (sum % n > 0 ? 1 : 0);
  unsigned long long int ret1 = 0, ret2 = 0;
  for (int i = 0; i < n; i++)
    if (m[i] < avg1) ret1 += avg1 - m[i];
  for (int i = 0; i < n; i++)
    if (m[i] > avg2) ret2 += m[i] - avg2;
  cout << max(ret1, ret2) << endl;
  return 0;
}
