function main(input){
  let protoMoney = input[0] + input[1] + input[2] + input[3] + input[4] + input[5] + input[6] + input[7] + input[8];
  let money = parseInt(protoMoney,10);
  let happy = 0;
  let amari = money % 500
  
  
  while (money >= 500) {
      happy = money / 500;
  }

  happy = happy * 1000;
  
  while(amari >= 5){
    happy2 = amari / 5;
  } 

  happy2 = happy2 * 5;

  console.log(happy + happy2);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));