import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

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

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    }
} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    }
}
