program main
  
  implicit none
  integer :: i,n
  real(8) :: x,tmp500,tmp5
  
  read(*,*) x
  tmp500 = 500
  tmp5   = 5
  
  print*, int(x/tmp500)*1000+int((x-int(x/tmp500)*tmp500)/tmp5)*5  
end program main
