    import java.util.Scanner;
     
     
    public class Main {
        

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } 
        }
     import java.util.Scanner; Scanner java.util public class Main {
        

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } 
        } Main public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } main {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int sum500=0; sum500 0 int sum5=0; sum5 0 sum500=x/500 sum500 x/500 x 500 sum5=(x-sum500*500)/5 sum5 (x-sum500*500)/5 (x-sum500*500) x sum500*500 sum500 500 5 System.out.println(sum500*1000+sum5*5) System.out.println System.out System System.out sum500*1000+sum5*5 sum500*1000 sum500 1000 sum5*5 sum5 5 String[] args args public class Main {
        

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } 
        } public class Main {
        

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } 
        } Main
    import java.util.Scanner;
     
     
    public class Main {
        

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int sum500=0;
            int sum5=0;
            
            sum500=x/500;
            sum5=(x-sum500*500)/5;


            System.out.println(sum500*1000+sum5*5);



           } 
        }
    
