fun main (args : Array<String>) {
    val x = readLine()!!.toInt()

    var calc : Int = x
    var cnt1 : Int = 0
    var cnt2 : Int = 0
    var result : Int

    while (calc >= 500) {
        calc = calc - 500
        cnt1 += 1
    }

    while (calc >= 5) {
        calc = calc - 5
        cnt2 += 1
    }

    result = (1000 * cnt1) + (5 * cnt2)
    return println("${result}")

}
