#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N;
  cin >> N;
  long long count = 0;
  long long A = 1000;
  long long ans = 0;
  vector<long long> a(N - 1);
  vector<long long> b(N - 1);
  for (long long i = 0; i < N - 1; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < N - 1; i++) {
    count += a[i];
  }
  count = count / N;
  for (long long i = 0; i < N - 1; i++) {
    b[i] = abs(a[i] - count);
  }
  for (long long i = 0; i < N - 1; i++) {
    A = min(A, b[i]);
  }
  for (long long i = 0; i < N - 1; i++) {
    if (A == b[i]) {
      ans = b[i];
      break;
    }
  }
  cout << ans << endl;
}
