import java.util.*;

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

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
        
        int A = X/500;
        int B = (X%500)/5;
        
        System.out.println(1000*A+5*B);
    }
}
