import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	}
} import java.util.*; util.* java public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	}
} Main public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	} Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) int X = keyboard.nextInt(); X keyboard.nextInt() keyboard.nextInt keyboard System.out.println((X/500)*1000 + ((X%500)/5)*5) System.out.println System.out System System.out (X/500)*1000 + ((X%500)/5)*5 (X/500)*1000 (X/500) X 500 1000 ((X%500)/5)*5 ((X%500)/5) (X%500) X 500 5 5 keyboard.close() keyboard.close keyboard String[] args args public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	}
} public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	}
} Main
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		
		System.out.println((X/500)*1000 + ((X%500)/5)*5);
		keyboard.close();	
	}
}