import java.util.Scanner;
 
public class Main {
 
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
}
} import java.util.Scanner; Scanner java.util public class Main {
 
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
}
} Main public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int happynesspoint happynesspoint k k j; j if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	} n>=0 n 0 {
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	} k = n/500 k n/500 n 500 j= n%500 j n%500 n 500 happynesspoint = 1000*k+5*(j/5) happynesspoint 1000*k+5*(j/5) 1000*k 1000 k 5*(j/5) 5 (j/5) j 5 System.out.println(happynesspoint) System.out.println System.out System System.out happynesspoint String[]args args public class Main {
 
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
}
} public class Main {
 
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
}
} Main
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int happynesspoint,k,j;
		if(n>=0){
			k = n/500;
			j= n%500;
			happynesspoint = 1000*k+5*(j/5);
		System.out.println(happynesspoint);
	}
}
}