import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = a / 500;
        int c = a % 500 / 5;
        System.out.println(b * 1000 + c * 5);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = a / 500;
        int c = a % 500 / 5;
        System.out.println(b * 1000 + c * 5);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = a / 500;
        int c = a % 500 / 5;
        System.out.println(b * 1000 + c * 5);
    } main {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = a / 500;
        int c = a % 500 / 5;
        System.out.println(b * 1000 + c * 5);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = Integer.parseInt(sc.next()); a Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int b = a / 500; b a / 500 a 500 int c = a % 500 / 5; c a % 500 / 5 a % 500 a 500 5 System.out.println(b * 1000 + c * 5) System.out.println System.out System System.out b * 1000 + c * 5 b * 1000 b 1000 c * 5 c 5 String[] args args
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = a / 500;
        int c = a % 500 / 5;
        System.out.println(b * 1000 + c * 5);
    }
}