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