program thumbnail
  implicit none
  integer              :: n, i, idx
  integer, allocatable :: a(:)
  real(8)              :: ave, rsd
  read(*,*) n
  allocate(a(n))
  read(*,*) a(:)
  if (n .eq. 1) then
     write(*,'(i0)') 0
     stop
  end if
  
  ave = sum(a)/real(n,8)
  rsd = abs(a(1)-ave)
  idx = 1
  
  do i = 2, n
     if (abs(a(i)-ave) .lt. rsd) then
        rsd = abs(a(i)-ave)
        idx = i
     end if
  end do
  deallocate(a)
  write(*,'(i0)') idx-1
  stop
end program thumbnail