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