import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        long price  = sc.nextLong();

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    }

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

    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        long price  = sc.nextLong();

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    }

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

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    } main {
        Scanner sc  = new Scanner(System.in);
        long price  = sc.nextLong();

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    } Scanner sc  = new Scanner(System.in); sc new Scanner(System.in) long price  = sc.nextLong(); price sc.nextLong() sc.nextLong sc long happypoint = 0; happypoint 0 happypoint = happypoint + (price/500) * 1000 happypoint happypoint + (price/500) * 1000 happypoint (price/500) * 1000 (price/500) price 500 1000 price = price % 500 price price % 500 price 500 happypoint = happypoint + (price/5) * 5 happypoint happypoint + (price/5) * 5 happypoint (price/5) * 5 (price/5) price 5 5 System.out.println(happypoint) System.out.println System.out System System.out happypoint sc.close() sc.close sc String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        long price  = sc.nextLong();

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        long price  = sc.nextLong();

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        long price  = sc.nextLong();

        long happypoint = 0;

        // 500円玉のhappypoint
        happypoint = happypoint + (price/500) * 1000;

        price = price % 500;

        // 5円玉のhappypoint
        happypoint = happypoint + (price/5) * 5;

        // 出力
        System.out.println(happypoint);

        sc.close();
    }

}