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