import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    }
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    } main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long price = sc.nextLong(); price sc.nextLong() sc.nextLong sc long happy = 0; happy 0 happy += price / 500 * 1000 happy price / 500 * 1000 price / 500 price 500 1000 price = price % 500 price price % 500 price 500 happy += price / 5 * 5 happy price / 5 * 5 price / 5 price 5 5 System.out.println(happy) System.out.println System.out System System.out happy String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    }
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long price = sc.nextLong();
        long happy = 0;
        
        happy += price / 500 * 1000;
        price = price % 500;
        happy += price / 5 * 5;
        System.out.println(happy);
    }
}