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

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

        int x = sc.nextInt();

        int a = x%500;

        System.out.println((1000*(x/500))+((a/5)*5));
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        int a = x%500;

        System.out.println((1000*(x/500))+((a/5)*5));
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        int a = x%500;

        System.out.println((1000*(x/500))+((a/5)*5));
    } main {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        int a = x%500;

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

        int x = sc.nextInt();

        int a = x%500;

        System.out.println((1000*(x/500))+((a/5)*5));
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        int a = x%500;

        System.out.println((1000*(x/500))+((a/5)*5));
    }
} Main
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int x = sc.nextInt();

        int a = x%500;

        System.out.println((1000*(x/500))+((a/5)*5));
    }
}