      PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: x,ans
      integer(16) :: num500,num5
      
      read*,x
      
      num500 = x / 500
      x = x - num500 * 500
      
      num5 = x / 5
      
      ans = num500 * 1000 + num5 * 5
      
      print*,ans
      
      
      
      
      
      
      END PROGRAM