import java.util.Scanner;

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  }
  
} import java.util.Scanner; Scanner java.util public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  }
  
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  } main {
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int S = sc.nextInt(); S sc.nextInt() sc.nextInt sc int totalHappy = 0; totalHappy 0 totalHappy  = totalHappy + ((S/500) * 1000) totalHappy totalHappy + ((S/500) * 1000) totalHappy ((S/500) * 1000) (S/500) S 500 1000 S = S%500 S S%500 S 500 totalHappy = totalHappy + ((S/5) *5) totalHappy totalHappy + ((S/5) *5) totalHappy ((S/5) *5) (S/5) S 5 5 S = S%5 S S%5 S 5 System.out.println(totalHappy) System.out.println System.out System System.out totalHappy String[] args args public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  }
  
} public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  }
  
} Main
import java.util.Scanner;

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int totalHappy = 0;
    totalHappy  = totalHappy + ((S/500) * 1000);
    S = S%500;
    totalHappy = totalHappy + ((S/5) *5);
    S = S%5;
    System.out.println(totalHappy);
  }
  
}
