function Main(input) {
    const _500 = Math.floor(input / 500)
    if (_500 > 1) {
        const _5 = Math.floor((input - (500 * _500)) / 5)
        console.log(1000 * _500 + 5 * _5)
    } else {
        console.log(1000 * _500)
    }
}
// Main()
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
