import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    }
} import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int x = Integer.parseInt(br.readLine()); x Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br long ret = x/500*1000L + x%500/5*5; ret x/500*1000L + x%500/5*5 x/500*1000L x/500 x 500 1000L x%500/5*5 x%500/5 x%500 x 500 5 5 System.out.println(ret) System.out.println System.out System System.out ret String[] args args public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    }
} Main
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        long ret = x/500*1000L + x%500/5*5;
        System.out.println(ret);
    }
}
