import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	} main {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int result = 0; result 0 if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        } x % 500 == 0 x % 500 x 500 0 {
        	result = 1000 * (x / 500);
        } result = 1000 * (x / 500) result 1000 * (x / 500) 1000 (x / 500) x 500 {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        } result = 1000 * (x / 500) + (x % 500) / 5 * 5 result 1000 * (x / 500) + (x % 500) / 5 * 5 1000 * (x / 500) 1000 (x / 500) x 500 (x % 500) / 5 * 5 (x % 500) / 5 (x % 500) x 500 5 5 System.out.print(result) System.out.print System.out System System.out result String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int result = 0;
        if(x % 500 == 0) {
        	result = 1000 * (x / 500);
        }else {
        	result = 1000 * (x / 500) + (x % 500) / 5 * 5;
        }
        System.out.print(result);
        
	}
}