import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    }
} import java.util.Scanner; Scanner java.util public class Main
{
    public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    }
} Main public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    } main {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    } Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) int num = keyboard.nextInt(); num keyboard.nextInt() keyboard.nextInt keyboard int points_500 = 0; points_500 0 int points_5 = 0; points_5 0 while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        } num > 5 num 5 {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

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

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    }
} public class Main
{
    public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    }
} Main
import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    }
}