program decrease
  implicit none
  integer :: n, i
  integer(8) :: a(50), m, t
  a = 0_8
  read(*,*) n
  read(*,*) a(1:n)
  t = 0_8
  do
    m = maxval(a(1:n))
    if (m.lt.int(n,8)) exit
    m = 0_8
    do i = 1, n
      m = m + a(i)/int(n,8)
    end do
    do i = 1, n
      a(i) = a(i) + m - (a(i)/int(n,8))*int(n+1,8)
    end do
    t = t + m
  end do
  write(*,'(i0)') t
  stop
end program decrease