
import java.util.Collections;
import java.util.ArrayList;
import java.util.*;
import java.util.regex.Pattern;  
import java.util.Scanner;  
import java.util.regex.Matcher; 
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		{
			int x=sc.nextInt();
			int sum=0;
			if(x/500>=1)
			{
				sum=sum+(x/500)*1000+((x%500)/5)*5;
			}
			else
			{
				sum=sum+(x/5)*5;
				
			}
			System.out.println(sum);
				
			
					
		     
		     }		
			
		
	}

	
	
	
}
		 import java.util.Collections; Collections java.util import java.util.ArrayList; ArrayList java.util import java.util.*; util.* java import java.util.regex.Pattern; Pattern java.util.regex import java.util.Scanner; Scanner java.util import java.util.regex.Matcher; Matcher java.util.regex public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		{
			int x=sc.nextInt();
			int sum=0;
			if(x/500>=1)
			{
				sum=sum+(x/500)*1000+((x%500)/5)*5;
			}
			else
			{
				sum=sum+(x/5)*5;
				
			}
			System.out.println(sum);
				
			
					
		     
		     }		
			
		
	}

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

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

	
	
	
} Main

import java.util.Collections;
import java.util.ArrayList;
import java.util.*;
import java.util.regex.Pattern;  
import java.util.Scanner;  
import java.util.regex.Matcher; 
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		{
			int x=sc.nextInt();
			int sum=0;
			if(x/500>=1)
			{
				sum=sum+(x/500)*1000+((x%500)/5)*5;
			}
			else
			{
				sum=sum+(x/5)*5;
				
			}
			System.out.println(sum);
				
			
					
		     
		     }		
			
		
	}

	
	
	
}
		
