import java.util.*;

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

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