import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    }
} Main public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    } main {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    } Scanner tan = new Scanner(System.in); tan new Scanner(System.in) int x x a a b; b x=tan.nextInt() x tan.nextInt() tan.nextInt tan a=x/500 a x/500 x 500 b=(x%500)/5 b (x%500)/5 (x%500) x 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) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    }
}
