import java.io.*;
import java.util.*;


public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    }
} Main public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    } main {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long x = scanner.nextLong(); x scanner.nextLong() scanner.nextLong scanner long answer=0; answer 0 long bigYen=(x-(x%500))/500; bigYen (x-(x%500))/500 (x-(x%500)) x (x%500) x 500 500 answer+=bigYen*1000 answer bigYen*1000 bigYen 1000 long extra=x%500; extra x%500 x 500 extra-=extra%5 extra extra%5 extra 5 answer+=extra answer extra System.out.println(answer) System.out.println System.out System System.out answer String[]args args public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    }
} public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    }
} Main
import java.io.*;
import java.util.*;


public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long answer=0;
        long bigYen=(x-(x%500))/500;
        answer+=bigYen*1000;
        long extra=x%500;
        extra-=extra%5;
        answer+=extra;
        System.out.println(answer);
    }
}
