#include <bits/stdc++.h>
using namespace std;
int abs(int a, int b) {
  int c = max(a, b) - min(a, b);
  return c;
}
signed main() {
  long long a, b = 0;
  long long c[10000];
  long long d, e = 1000000;
  cin >> a;
  for (long long i = 0; i < a; i++) {
    cin >> c[i];
    b += c[i];
  }
  b /= a;
  for (long long i = 0; i < a; i++) {
    if (abs(c[i], b) < e) e = i;
  }
  cout << d << "\n";
}
