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