import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    } main {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x = sc.nextLong(); x sc.nextLong() sc.nextLong sc if(x ==0) {
            System.out.println(0);
            return;
        } x ==0 x 0 {
            System.out.println(0);
            return;
        } System.out.println(0) System.out.println System.out System System.out 0 return; long a500 = x / 500; a500 x / 500 x 500 if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        } a500 == 0 a500 0 {
            System.out.println(x / 5 * 5);
            return;
        } System.out.println(x / 5 * 5) System.out.println System.out System System.out x / 5 * 5 x / 5 x 5 5 return; long b = x % (a500 * 500); b x % (a500 * 500) x (a500 * 500) a500 500 long b5 = b / 5; b5 b / 5 b 5 System.out.println(a500 * 1000 + b5 * 5) System.out.println System.out System System.out a500 * 1000 + b5 * 5 a500 * 1000 a500 1000 b5 * 5 b5 5 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x ==0) {
            System.out.println(0);
            return;
        }
        long a500 = x / 500;
        if(a500 == 0) {
            System.out.println(x / 5 * 5);
            return;
        }
        long b = x % (a500 * 500);
        long b5 = b / 5;
        System.out.println(a500 * 1000 + b5 * 5);
    }
}