import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	}
} 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 num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	} main {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) long X = stdIn.nextLong(); X stdIn.nextLong() stdIn.nextLong stdIn long num500 = X / 500; num500 X / 500 X 500 long num5 = (X % 500) / 5; num5 (X % 500) / 5 (X % 500) X 500 5 System.out.println(num500 * 1000 + num5 * 5) System.out.println System.out System System.out num500 * 1000 + num5 * 5 num500 * 1000 num500 1000 num5 * 5 num5 5 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	}
} 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 num500 = X / 500;
		long num5 = (X % 500) / 5;
		System.out.println(num500 * 1000 + num5 * 5);
	}
}