fun main(args :Array<String>){
  var input : String? = readLine()
  var value = input!!.toLong()
  var view :Long = 0
  var num1 = value / 500
  var num2 = (value - num1*500)/5
  view = num1*1000 + num2 * 5
  println(view)
}