import java.util.Scanner;
import java.util.LinkedList;
import java.lang.Math;

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

        long c500 = x/500;
        long c5 = (x-c500*500)/5;
        long iei = 1000*c500 + 5*c5;

        System.out.print(iei);

    }
} import java.util.Scanner; Scanner java.util import java.util.LinkedList; LinkedList java.util import java.lang.Math; Math java.lang class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Long x = sc.nextLong();

        long c500 = x/500;
        long c5 = (x-c500*500)/5;
        long iei = 1000*c500 + 5*c5;

        System.out.print(iei);

    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Long x = sc.nextLong();

        long c500 = x/500;
        long c5 = (x-c500*500)/5;
        long iei = 1000*c500 + 5*c5;

        System.out.print(iei);

    } main {
        Scanner sc = new Scanner(System.in);
        Long x = sc.nextLong();

        long c500 = x/500;
        long c5 = (x-c500*500)/5;
        long iei = 1000*c500 + 5*c5;

        System.out.print(iei);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Long x = sc.nextLong(); x sc.nextLong() sc.nextLong sc long c500 = x/500; c500 x/500 x 500 long c5 = (x-c500*500)/5; c5 (x-c500*500)/5 (x-c500*500) x c500*500 c500 500 5 long iei = 1000*c500 + 5*c5; iei 1000*c500 + 5*c5 1000*c500 1000 c500 5*c5 5 c5 System.out.print(iei) System.out.print System.out System System.out iei String[] args args
import java.util.Scanner;
import java.util.LinkedList;
import java.lang.Math;

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

        long c500 = x/500;
        long c5 = (x-c500*500)/5;
        long iei = 1000*c500 + 5*c5;

        System.out.print(iei);

    }
}