import java.util.Scanner;

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

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