import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

        happy += 1000*a + 5*b;
        
        System.out.println(happy);
        // System.out.println(a);
        // System.out.println(b);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

        happy += 1000*a + 5*b;
        
        System.out.println(happy);
        // System.out.println(a);
        // System.out.println(b);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

        happy += 1000*a + 5*b;
        
        System.out.println(happy);
        // System.out.println(a);
        // System.out.println(b);
    } main {
        Scanner scan = new Scanner(System.in);

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

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

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

        happy += 1000*a + 5*b;
        
        System.out.println(happy);
        // System.out.println(a);
        // System.out.println(b);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

        happy += 1000*a + 5*b;
        
        System.out.println(happy);
        // System.out.println(a);
        // System.out.println(b);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int X = Integer.parseInt(scan.next());
        scan.close();
        
        int happy = 0;

        int a = X/500;
        int b = (X%500)/5;

        happy += 1000*a + 5*b;
        
        System.out.println(happy);
        // System.out.println(a);
        // System.out.println(b);
    }
}