import java.util.Scanner;
    public class Main{
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        }
    } import java.util.Scanner; Scanner java.util public class Main{
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        }
    } Main public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        } main {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        } Scanner in=new Scanner(System.in); in new Scanner(System.in) long num=in.nextLong(); num in.nextLong() in.nextLong in long tk=0; tk 0 long pchso=num/500; pchso num/500 num 500 tk=pchso*1000 tk pchso*1000 pchso 1000 int baki=(int) (num%500); baki (int) (num%500) num 500 long pach=baki/5; pach baki/5 baki 5 tk=tk+(pach*5) tk tk+(pach*5) tk (pach*5) pach 5 System.out.println(tk) System.out.println System.out System System.out tk String[] args args public class Main{
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        }
    } public class Main{
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        }
    } Main
import java.util.Scanner;
    public class Main{
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        }
    }