program pr4
  implicit none
  integer(16) :: n
  integer,allocatable(16) :: a(:)
  integer(16) :: i, money, stock
  
  read(*,*) n
  allocate(a(n))
  read(*,*) a
  
  money = 1000_16
  stock = 0_16
  
  do i = 1, n-1
     if ( a(i) < a(i+1) ) then
        call  buystock(a(i), money, stock)
     else if ( a(i) > a(i+1) ) then
        call sellstock(a(i), money, stock)
     else
        cycle
     end if
  end do
  

  call sellstock(a(n),money,stock)
    
  write(*,'(i0)') money
  
  stop
contains

  subroutine buystock(price,money,stock)
    integer(16) :: price, money, stock
    do while ( money >= price )
       money = money - price
       stock = stock + 1_16
    end do
    return
  end subroutine buystock

  subroutine sellstock(price,money,stock)
    integer(16) :: price, money, stock
    do while ( stock > 0_16 )
       money = money + price
       stock = stock - 1_16
    end do
    return
  end subroutine sellstock
end program pr4
