import java.io.IOException;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    }
} import java.io.IOException; IOException java.io import java.util.*; util.* java public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    }
} Main public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    } main {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int a = in.nextInt(); a in.nextInt() in.nextInt in int b = a / 500; b a / 500 a 500 int c = (a % 500) / 5; c (a % 500) / 5 (a % 500) a 500 5 System.out.println(1000 * b + 5 * c) System.out.println System.out System System.out 1000 * b + 5 * c 1000 * b 1000 b 5 * c 5 c String[] args args public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    }
} Main
import java.io.IOException;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = a / 500;
        int c = (a % 500) / 5;
        System.out.println(1000 * b + 5 * c);
    }
}