import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        long x = sc.nextInt();
        
        long power1000 = 0;
        long power5 = 0;
        
        power1000 = x/500;
        power5 = (x%500)/5;
        
        System.out.println(1000*power1000+5*power5);
    }
} import java.util.*; util.* java class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        long x = sc.nextInt();
        
        long power1000 = 0;
        long power5 = 0;
        
        power1000 = x/500;
        power5 = (x%500)/5;
        
        System.out.println(1000*power1000+5*power5);
    }
} Main public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        long x = sc.nextInt();
        
        long power1000 = 0;
        long power5 = 0;
        
        power1000 = x/500;
        power5 = (x%500)/5;
        
        System.out.println(1000*power1000+5*power5);
    } main {
        Scanner sc = new Scanner(System.in);
        
        long x = sc.nextInt();
        
        long power1000 = 0;
        long power5 = 0;
        
        power1000 = x/500;
        power5 = (x%500)/5;
        
        System.out.println(1000*power1000+5*power5);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x = sc.nextInt(); x sc.nextInt() sc.nextInt sc long power1000 = 0; power1000 0 long power5 = 0; power5 0 power1000 = x/500 power1000 x/500 x 500 power5 = (x%500)/5 power5 (x%500)/5 (x%500) x 500 5 System.out.println(1000*power1000+5*power5) System.out.println System.out System System.out 1000*power1000+5*power5 1000*power1000 1000 power1000 5*power5 5 power5 String[] args args
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        long x = sc.nextInt();
        
        long power1000 = 0;
        long power5 = 0;
        
        power1000 = x/500;
        power5 = (x%500)/5;
        
        System.out.println(1000*power1000+5*power5);
    }
}