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