import java.util.Scanner;

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

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int X = sc.nextInt();
            long sum = 0;
            sum += (X / 500) * 1000;
            sum += ((X % 500) / 5) * 5;
            System.out.println(sum);
        }
    }
}
