import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X=sc.nextInt();

        int gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*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 gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*5));
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X=sc.nextInt();

        int gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*5));
    } main {
        Scanner sc = new Scanner(System.in);

        int X=sc.nextInt();

        int gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*5));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X=sc.nextInt(); X sc.nextInt() sc.nextInt sc int gohyaku=0; gohyaku 0 int go=0; go 0 gohyaku=X/500 gohyaku X/500 X 500 go=(X%500)/5 go (X%500)/5 (X%500) X 500 5 System.out.println((gohyaku*1000+go*5)) System.out.println System.out System System.out (gohyaku*1000+go*5) gohyaku*1000 gohyaku 1000 go*5 go 5 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X=sc.nextInt();

        int gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*5));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X=sc.nextInt();

        int gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*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 gohyaku=0;
        int go=0;

        gohyaku=X/500;
        go=(X%500)/5;

        System.out.println((gohyaku*1000+go*5));
    }
}