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

