import java.util.*;
import java.io.*;
public class Main {
	static final int MOD=998244353;
	public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	}
}      import java.util.*; util.* java import java.io.*; io.* java public class Main {
	static final int MOD=998244353;
	public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	}
} Main static final int MOD=998244353; MOD 998244353 public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	} main {
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	} BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); out new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))) int x=Integer.parseInt(in.readLine()); x Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		} x==0 x 0 out.append(0+"\n") out.append out 0+"\n" 0 "\n" {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		} int happiness=(x/500)*1000; happiness (x/500)*1000 (x/500) x 500 1000 x=(x%500) x (x%500) x 500 happiness+=(x/5)*5 happiness (x/5)*5 (x/5) x 5 5 out.append(happiness+"\n") out.append out happiness+"\n" happiness "\n" out.flush() out.flush out in.close() in.close in out.close() out.close out String[] args args public class Main {
	static final int MOD=998244353;
	public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	}
} public class Main {
	static final int MOD=998244353;
	public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	}
} Main
import java.util.*;
import java.io.*;
public class Main {
	static final int MOD=998244353;
	public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int x=Integer.parseInt(in.readLine());
		
		if(x==0)
			out.append(0+"\n");
		else {
			int happiness=(x/500)*1000;
			x=(x%500);
			happiness+=(x/5)*5;
			out.append(happiness+"\n");
		}
		
		
		out.flush();
		in.close();
		out.close();
	}
}     
