import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        long X = sc.nextLong();
        long n500 = X/500;
        long n5 = (X%500)/5;
        System.out.println(n500*1000+n5*5);
    }
} import java.util.*; util.* java class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        long X = sc.nextLong();
        long n500 = X/500;
        long n5 = (X%500)/5;
        System.out.println(n500*1000+n5*5);
    }
} Main static Scanner sc=new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args){
        long X = sc.nextLong();
        long n500 = X/500;
        long n5 = (X%500)/5;
        System.out.println(n500*1000+n5*5);
    } main {
        long X = sc.nextLong();
        long n500 = X/500;
        long n5 = (X%500)/5;
        System.out.println(n500*1000+n5*5);
    } long X = sc.nextLong(); X sc.nextLong() sc.nextLong sc long n500 = X/500; n500 X/500 X 500 long n5 = (X%500)/5; n5 (X%500)/5 (X%500) X 500 5 System.out.println(n500*1000+n5*5) System.out.println System.out System System.out n500*1000+n5*5 n500*1000 n500 1000 n5*5 n5 5 String[] args args
import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        long X = sc.nextLong();
        long n500 = X/500;
        long n5 = (X%500)/5;
        System.out.println(n500*1000+n5*5);
    }
}