import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	}
} Main public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	} main {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) long X = stdIn.nextLong(); X stdIn.nextLong() stdIn.nextLong stdIn long ans1 = 0; ans1 0 long ans2 = 0; ans2 0 long ans = 0; ans 0 ans1 = X / 500 ans1 X / 500 X 500 ans2 = (X % 500) / 5 ans2 (X % 500) / 5 (X % 500) X 500 5 ans = (ans1 * 1000) + (ans2 * 5) ans (ans1 * 1000) + (ans2 * 5) (ans1 * 1000) ans1 1000 (ans2 * 5) ans2 5 System.out.println(ans) System.out.println System.out System System.out ans stdIn.close() stdIn.close stdIn String[] args args public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	}
} public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	}
}