import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int k=x/500;
		int l=(x%500)/5;
		
		
		System.out.println(1000*k+5*l);
	}

} 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 k=x/500;
		int l=(x%500)/5;
		
		
		System.out.println(1000*k+5*l);
	}

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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int k=x/500;
		int l=(x%500)/5;
		
		
		System.out.println(1000*k+5*l);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int k=x/500;
		int l=(x%500)/5;
		
		
		System.out.println(1000*k+5*l);
	}

} 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 k=x/500;
		int l=(x%500)/5;
		
		
		System.out.println(1000*k+5*l);
	}

}
