import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = Integer.parseInt(sc.next()); x Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int five_hundred_yen = x / 500; five_hundred_yen x / 500 x 500 x = x % 500 x x % 500 x 500 int five_yen = x / 5; five_yen x / 5 x 5 System.out.println((five_hundred_yen * 1000) + (five_yen * 5)) System.out.println System.out System System.out (five_hundred_yen * 1000) + (five_yen * 5) (five_hundred_yen * 1000) five_hundred_yen 1000 (five_yen * 5) five_yen 5 sc.close() sc.close sc String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int five_hundred_yen = x / 500;
        x = x % 500;
        int five_yen = x / 5;
        System.out.println((five_hundred_yen * 1000) + (five_yen * 5));
        sc.close();
    }
}
