
import java.util.Scanner;

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

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


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

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


	} main {

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Long n 	   = Long.parseLong(scanner.nextLine()); n Long.parseLong(scanner.nextLine()) Long.parseLong Long scanner.nextLine() scanner.nextLine scanner Long count  = (long)Math.floor(n / 500.0); count (long)Math.floor(n / 500.0) Math.floor Math n / 500.0 n 500.0 Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0); tcoun (long)Math.floor((n - 500 * count) / 5.0) Math.floor Math (n - 500 * count) / 5.0 (n - 500 * count) n 500 * count 500 count 5.0 System.out.println(count * 1000 + tcoun * 5) System.out.println System.out System System.out count * 1000 + tcoun * 5 count * 1000 count 1000 tcoun * 5 tcoun 5 String[] args args public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


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

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


	}
} Main

import java.util.Scanner;

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

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


	}
}