import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a = n / 500; a n / 500 n 500 int b = (n - a * 500) / 5; b (n - a * 500) / 5 (n - a * 500) n a * 500 a 500 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) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 500;
        int b = (n - a * 500) / 5;
        System.out.println(a*1000+b*5);
    }
}
