import java.util.Scanner;

public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
}
 import java.util.Scanner; Scanner java.util public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
} Main public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		} main {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int gohyakuEn = 0; gohyakuEn 0 int goEn = 0; goEn 0 if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			} num/500 >= 1 num/500 num 500 1 {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			} gohyakuEn = num/500 gohyakuEn num/500 num 500 if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				} num%500 >=1 && num/5 >= 1 num%500 >=1 num%500 num 500 1 num/5 >= 1 num/5 num 5 1 {
					int tmp = num%500;
					goEn = tmp/5;
				} int tmp = num%500; tmp num%500 num 500 goEn = tmp/5 goEn tmp/5 tmp 5 if(num/5 >= 1) {
				goEn = num/5;

			} num/5 >= 1 num/5 num 5 1 {
				goEn = num/5;

			} goEn = num/5 goEn num/5 num 5 System.out.println( (1000 * gohyakuEn) + (5 * goEn) ) System.out.println System.out System System.out (1000 * gohyakuEn) + (5 * goEn) (1000 * gohyakuEn) 1000 gohyakuEn (5 * goEn) 5 goEn String[] args args public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
} public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
} Main
import java.util.Scanner;

public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int num = sc.nextInt();

			//500で割れる、5で割れる ex 1050
			//500で割れる、5で割れない ex 1000

			//500で割れない、5で割れる ex 300
			//500で割れない、5で割れない ex 0
			int gohyakuEn = 0;
			int goEn = 0;

			if(num/500 >= 1) {
				gohyakuEn = num/500;

				if( num%500 >=1 && num/5 >= 1) {
					int tmp = num%500;
					goEn = tmp/5;
				}
			}else if(num/5 >= 1) {
				goEn = num/5;

			}


				System.out.println( (1000 * gohyakuEn) + (5 * goEn) );


		}
}

