object Main extends App {
  for(line <- io.Source.stdin.getLines()) {
    val numAry = line.split(' ').map { _.toInt }
    val _money = numAry(0).toInt
    val money = if ((0 <= _money) && (_money <= 1000000000)) _money else 0

    val coinNum500: Int = money/500
    val coinNum5: Int = (money - coinNum500*500)/5
    val hpns500: Int = coinNum500*1000
    val hpns5: Int = coinNum5*5
    val hapiness = hpns500 + hpns5
    println(hapiness)
  }
}
