
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();

		int happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		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 happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		scan.close();
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();

		int happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();

		int happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int X = scan.nextInt(); X scan.nextInt() scan.nextInt scan int happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5; happy (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5 (X / 500) * 1000 (X / 500) X 500 1000 ((X - 500 * (X / 500)) / 5) * 5 ((X - 500 * (X / 500)) / 5) (X - 500 * (X / 500)) X 500 * (X / 500) 500 (X / 500) X 500 5 5 System.out.println(happy) System.out.println System.out System System.out happy 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 happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		scan.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();

		int happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		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 happy = (X / 500) * 1000 + ((X - 500 * (X / 500)) / 5) * 5;
		System.out.println(happy);
		scan.close();
	}
}
