require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
}).on('line', function(line) {
  var x = +line;
  var happiness = Math.floor(x / 500) * 1000;
  happiness += Math.floor((x % 500) / 5) * 5;
  console.log(happiness);
});