import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    } main {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = Integer.parseInt(sc.next()); num Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int five_hund = num / 500; five_hund num / 500 num 500 int five = (num - five_hund * 500) / 5; five (num - five_hund * 500) / 5 (num - five_hund * 500) num five_hund * 500 five_hund 500 5 System.out.println(1000 * five_hund + 5 * five) System.out.println System.out System System.out 1000 * five_hund + 5 * five 1000 * five_hund 1000 five_hund 5 * five 5 five String args[] args public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int num = Integer.parseInt(sc.next());
        
        int five_hund = num / 500;
        int five = (num - five_hund * 500) / 5;
        
        System.out.println(1000 * five_hund + 5 * five);
    }
}