import java.util.*;

class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int num=sc.nextInt();
		int sum=0;
		num-=num%5;
		do{
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		}while(num>0);
		
		System.out.println(sum);
	}
} import java.util.*; util.* java class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int num=sc.nextInt();
		int sum=0;
		num-=num%5;
		do{
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		}while(num>0);
		
		System.out.println(sum);
	}
} Main static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int num=sc.nextInt();
		int sum=0;
		num-=num%5;
		do{
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		}while(num>0);
		
		System.out.println(sum);
	} main {
		Scanner sc=new Scanner(System.in);
		
		int num=sc.nextInt();
		int sum=0;
		num-=num%5;
		do{
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		}while(num>0);
		
		System.out.println(sum);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int num=sc.nextInt(); num sc.nextInt() sc.nextInt sc int sum=0; sum 0 num-=num%5 num num%5 num 5 do{
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		}while(num>0); num>0 num 0 {
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		} if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break; num/500>0 num/500 num 500 0 {
				sum+=(num/500)*1000;
				num%=500;
			} sum+=(num/500)*1000 sum (num/500)*1000 (num/500) num 500 1000 num%=500 num 500 if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break; num/5>0 num/5 num 5 0 {
				sum+=(num/5)*5;
				num%=5;
			} sum+=(num/5)*5 sum (num/5)*5 (num/5) num 5 5 num%=5 num 5 break; System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.util.*;

class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int num=sc.nextInt();
		int sum=0;
		num-=num%5;
		do{
			if(num/500>0){
				sum+=(num/500)*1000;
				num%=500;
			}
			else if(num/5>0){
				sum+=(num/5)*5;
				num%=5;
			}
			else break;
		}while(num>0);
		
		System.out.println(sum);
	}
}