fun main (args:Array<String>) {
    val money = readLine()!!.toInt()
    var happy = 0
    val numOf500yen = money / 500
    val numOf5yen = (money - (numOf500yen * 500)) / 5

    if(numOf500yen >= 1) {
        happy += numOf500yen * 1000
    }
    if(numOf5yen >= 1){
        happy += 5 * numOf5yen
    }
    print(happy)
}