import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  }
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
  public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  }
} Main public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  } main {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int div = n / 500; div n / 500 n 500 int sub = n - div * 500 ; sub n - div * 500 n div * 500 div 500 int res = sub / 5; res sub / 5 sub 5 System.out.println(div * 1000 + res * 5) System.out.println System.out System System.out div * 1000 + res * 5 div * 1000 div 1000 res * 5 res 5 String[] args args public class Main{
  public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  }
} public class Main{
  public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  }
} Main
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args) {
     Scanner in = new Scanner(System.in);
     int n = in.nextInt();
     int div = n / 500;
     int sub = n - div * 500 ;
     int res = sub / 5;
     System.out.println(div * 1000 + res * 5);
  }
}
