
	


import java.util.*;


	public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			}} import java.util.*; util.* java public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			}} Main public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			} main {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			} Scanner in = new Scanner(System.in); in new Scanner(System.in) long a = in.nextLong(); a in.nextLong() in.nextLong in long b = a%500; b a%500 a 500 long c = a/500; c a/500 a 500 long h = b%5; h b%5 b 5 long g = b/5; g b/5 b 5 System.out.println(c*1000+ g*5) System.out.println System.out System System.out c*1000+ g*5 c*1000 c 1000 g*5 g 5 String[] args args public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			}} public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			}} Main

	


import java.util.*;


	public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			}}