   program abc160b
      implicit none
      integer(8)::X,a1,a2,b1

         read *,X
         a1=X/500
         a2=X-a1*500
         b1=a2/5

         print *,(a1*1000)+(b1*5)
         stop

   end program abc160b