import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int bigPoint, smallPoint;

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

        System.out.println(bigPoint + smallPoint);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int bigPoint, smallPoint;

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

        System.out.println(bigPoint + smallPoint);
    }
} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int bigPoint, smallPoint;

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

        System.out.println(bigPoint + smallPoint);
    } main {
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int bigPoint, smallPoint;

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

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

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

        System.out.println(bigPoint + smallPoint);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int bigPoint, smallPoint;

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

        System.out.println(bigPoint + smallPoint);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int bigPoint, smallPoint;

        bigPoint = (int) (X / 500) * 1000;
        smallPoint = (int)((X % 500) / 5) * 5;

        System.out.println(bigPoint + smallPoint);
    }
}