import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    }

} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    }

} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner if (n < 5){
            System.out.println("0");
            return;
        } n < 5 n 5 {
            System.out.println("0");
            return;
        } System.out.println("0") System.out.println System.out System System.out "0" return; int sum = 0; sum 0 while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        } n > 4 n 4 {
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        } if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            } n / 500 > 0 n / 500 n 500 0 {
                sum += n / 500 * 1000;
                n %= 500;
            } sum += n / 500 * 1000 sum n / 500 * 1000 n / 500 n 500 1000 n %= 500 n 500 if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            } n > 4 n 4 {
                sum += n / 5 * 5;
                n %= 5;
            } sum += n / 5 * 5 sum n / 5 * 5 n / 5 n 5 5 n %= 5 n 5 System.out.print(sum) System.out.print System.out System System.out sum String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    }

} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    }

} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n < 5){
            System.out.println("0");
            return;
        }
        int sum = 0;
        while (n > 4){
            if (n / 500 > 0){
                sum += n / 500 * 1000;
                n %= 500;
            }
            if(n > 4){
                sum += n / 5 * 5;
                n %= 5;
            }
        }
        System.out.print(sum);
    }

}
