
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    } main {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long X = scanner.nextLong(); X scanner.nextLong() scanner.nextLong scanner long a = X / 500; a X / 500 X 500 X = X % 500 X X % 500 X 500 long b = X / 5; b X / 5 X 5 System.out.println(a * 1000 + b * 5) System.out.println System.out System System.out a * 1000 + b * 5 a * 1000 a 1000 b * 5 b 5 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    }
} Main

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    }
}
