import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    }

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

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    }

} Main public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    } main {
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int input = scanner.nextInt(); input scanner.nextInt() scanner.nextInt scanner int a = input/500; a input/500 input 500 int b = (input%500)/5; b (input%500)/5 (input%500) input 500 5 System.out.println(a*1000 + b*5) System.out.println System.out System System.out a*1000 + b*5 a*1000 a 1000 b*5 b 5 scanner.close() scanner.close scanner String args[] args public class Main {

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    }

} public class Main {

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        int a = input/500;
        int b = (input%500)/5;


        System.out.println(a*1000 + b*5);
        scanner.close();
    }

}
