import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	}
} Main public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	} main {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int X = input.nextInt(); X input.nextInt() input.nextInt input int ure500=0; ure500 0 int ure5=0; ure5 0 int j=0; j 0 int k=0; k 0 j=X/500 j X/500 X 500 X-=500*j X 500*j 500 j k=X/5 k X/5 X 5 ure500=j*1000 ure500 j*1000 j 1000 ure5=k*5 ure5 k*5 k 5 System.out.println(ure500+ure5) System.out.println System.out System System.out ure500+ure5 ure500 ure5 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	}
} public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int X = input.nextInt();
		int ure500=0;
		int ure5=0;
		int j=0;
		int k=0;
		
		j=X/500;
		X-=500*j;
		
		k=X/5;
		
		ure500=j*1000;
		ure5=k*5;
		
		System.out.println(ure500+ure5);
		
	}
}
