import java.util.Scanner;

public class Main {
  private int happiness500 = 1000;
  private int happiness5 = 5;
  
  public int numOf500(int amount) {
    return amount / 500;
  }
  
  public int numOf5(int amount) {
    return (amount % 500) / 5;
  }
  
  public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  }
  
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  }
} import java.util.Scanner; Scanner java.util public class Main {
  private int happiness500 = 1000;
  private int happiness5 = 5;
  
  public int numOf500(int amount) {
    return amount / 500;
  }
  
  public int numOf5(int amount) {
    return (amount % 500) / 5;
  }
  
  public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  }
  
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  }
} Main private int happiness500 = 1000; happiness500 1000 private int happiness5 = 5; happiness5 5 public int numOf500(int amount) {
    return amount / 500;
  } numOf500 {
    return amount / 500;
  } return amount / 500; amount / 500 amount 500 int amount amount public int numOf5(int amount) {
    return (amount % 500) / 5;
  } numOf5 {
    return (amount % 500) / 5;
  } return (amount % 500) / 5; (amount % 500) / 5 (amount % 500) amount 500 5 int amount amount public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  } calcHappiness {
    return largeMedal * happiness500 + smallMedal * happiness5;
  } return largeMedal * happiness500 + smallMedal * happiness5; largeMedal * happiness500 + smallMedal * happiness5 largeMedal * happiness500 largeMedal happiness500 smallMedal * happiness5 smallMedal happiness5 int largeMedal largeMedal int smallMedal smallMedal public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  } main {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  } Scanner scnr = new Scanner(System.in); scnr new Scanner(System.in) Main obj = new Main(); obj new Main() int amount = Integer.parseInt(scnr.nextLine()); amount Integer.parseInt(scnr.nextLine()) Integer.parseInt Integer scnr.nextLine() scnr.nextLine scnr System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount))) System.out.println System.out System System.out obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)) obj.calcHappiness obj obj.numOf500(amount) obj.numOf500 obj amount obj.numOf5(amount) obj.numOf5 obj amount String[] args args public class Main {
  private int happiness500 = 1000;
  private int happiness5 = 5;
  
  public int numOf500(int amount) {
    return amount / 500;
  }
  
  public int numOf5(int amount) {
    return (amount % 500) / 5;
  }
  
  public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  }
  
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  }
} public class Main {
  private int happiness500 = 1000;
  private int happiness5 = 5;
  
  public int numOf500(int amount) {
    return amount / 500;
  }
  
  public int numOf5(int amount) {
    return (amount % 500) / 5;
  }
  
  public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  }
  
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  }
} Main
import java.util.Scanner;

public class Main {
  private int happiness500 = 1000;
  private int happiness5 = 5;
  
  public int numOf500(int amount) {
    return amount / 500;
  }
  
  public int numOf5(int amount) {
    return (amount % 500) / 5;
  }
  
  public int calcHappiness(int largeMedal, int smallMedal) {
    return largeMedal * happiness500 + smallMedal * happiness5;
  }
  
  public static void main(String[] args) {
    Scanner scnr = new Scanner(System.in);
    Main obj = new Main();
    
    int amount = Integer.parseInt(scnr.nextLine());
    
    System.out.println(obj.calcHappiness(obj.numOf500(amount), 
                                         obj.numOf5(amount)));
  }
}