#include <bits/stdc++.h>
int main() {
  int i;
  int N, b, a[N];
  scanf("%d", &N);
  for (i = 0; i > N; i++) {
    scanf("%d", &a[N]);
  }
  b = a[N] / N - N;
  if (b <= 1) {
    printf("%d\n", a[N]);
  } else if (b - a[N] == b - a[N]) {
    printf("0\n");
  }
  return 0;
}
