import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long x;
    long y500;
    long y5;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long x;
    long y500;
    long y5;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    }
} Main // 変数一覧
    long x; x long y500; y500 long y5; y5 public static void main(String[] args) {
        Main main = new Main();
        main.run();
    } main {
        Main main = new Main();
        main.run();
    } Main main = new Main(); main new Main() main.run() main.run main String[] args args public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    } run {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) x = sc.nextLong() x sc.nextLong() sc.nextLong sc sc.close() sc.close sc solve() solve private void solve() {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    } solve {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    } y500 = x / 500 y500 x / 500 x 500 x = x % 500 x x % 500 x 500 y5 = x / 5 y5 x / 5 x 5 long res = y500 * 1000 + y5 * 5; res y500 * 1000 + y5 * 5 y500 * 1000 y500 1000 y5 * 5 y5 5 System.out.println(res) System.out.println System.out System System.out res public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long x;
    long y500;
    long y5;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    }
} public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long x;
    long y500;
    long y5;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    long x;
    long y500;
    long y5;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        y500 = x / 500;
        x = x % 500;
        y5 = x / 5;
        long res = y500 * 1000 + y5 * 5;
        System.out.println(res);
    }
}