import java.util.*; 
public class Main{
public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  }
} import java.util.*; util.* java public class Main{
public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  }
} Main public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  } main {
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int c500 = n/500; c500 n/500 n 500 int r500 = n%500; r500 n%500 n 500 int c5 = r500/5; c5 r500/5 r500 5 System.out.println(c500*1000+c5*5) System.out.println System.out System System.out c500*1000+c5*5 c500*1000 c500 1000 c5*5 c5 5 String ... string string public class Main{
public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  }
} public class Main{
public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  }
} Main
import java.util.*; 
public class Main{
public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  }
}
