import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	}

} 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();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	} main {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan int happiness = 0; happiness 0 if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		} 0 < (x / 500) 0 (x / 500) x 500 {
			happiness += 1000 * (x / 500);
			x = x % 500;
		} happiness += 1000 * (x / 500) happiness 1000 * (x / 500) 1000 (x / 500) x 500 x = x % 500 x x % 500 x 500 if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		} 0 < (x / 5) 0 (x / 5) x 5 {
			happiness += 5 * (x / 5);
			x = x % 5;
		} happiness += 5 * (x / 5) happiness 5 * (x / 5) 5 (x / 5) x 5 x = x % 5 x x % 5 x 5 System.out.println(happiness) System.out.println System.out System System.out happiness scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int happiness = 0;

		if (0 < (x / 500) ) {
			happiness += 1000 * (x / 500);
			x = x % 500;
		}
		if (0 < (x / 5)) {
			happiness += 5 * (x / 5);
			x = x % 5;
		}

		System.out.println(happiness);

		scan.close();
	}

}
