import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	}

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

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	} main {

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long x = scan.nextLong(); x scan.nextLong() scan.nextLong scan int uresi500 = 1000; uresi500 1000 int uresi5 = 5; uresi5 5 int count500 = 0; count500 0 int count5 = 0; count5 0 while(x >= 500) {
			x -= 500;
			count500++;
		} x >= 500 x 500 {
			x -= 500;
			count500++;
		} x -= 500 x 500 count500++ count500 while(x >= 5){
			x -= 5;
			count5++;
		} x >= 5 x 5 {
			x -= 5;
			count5++;
		} x -= 5 x 5 count5++ count5 int re = count500*uresi500 + count5*uresi5; re count500*uresi500 + count5*uresi5 count500*uresi500 count500 uresi500 count5*uresi5 count5 uresi5 System.out.println(re) System.out.println System.out System System.out re scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	}

} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long x = scan.nextLong();
		int uresi500 = 1000;
		int uresi5 = 5;
		int count500 = 0;
		int count5 = 0;


		while(x >= 500) {
			x -= 500;
			count500++;
		}

		while(x >= 5){
			x -= 5;
			count5++;
		}

		int re = count500*uresi500 + count5*uresi5;

		System.out.println(re);

		scan.close();

	}

}
