import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	}

} import java.math.BigDecimal; BigDecimal java.math import java.math.RoundingMode; RoundingMode java.math import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	} main {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int X=sc.nextInt(); X sc.nextInt() sc.nextInt sc int intgoukei; intgoukei int happy1000; happy1000 int happy5; happy5 BigDecimal bigX=BigDecimal.valueOf(X); bigX BigDecimal.valueOf(X) BigDecimal.valueOf BigDecimal X BigDecimal gohyaku=BigDecimal.valueOf(500); gohyaku BigDecimal.valueOf(500) BigDecimal.valueOf BigDecimal 500 BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN); bigresult bigX.divide(gohyaku,0,RoundingMode.DOWN) bigX.divide bigX gohyaku 0 RoundingMode.DOWN RoundingMode RoundingMode.DOWN int bigresult1=bigresult.intValue(); bigresult1 bigresult.intValue() bigresult.intValue bigresult int senresult=bigresult1*500; senresult bigresult1*500 bigresult1 500 intgoukei=X-senresult intgoukei X-senresult X senresult BigDecimal goukei=BigDecimal.valueOf(intgoukei); goukei BigDecimal.valueOf(intgoukei) BigDecimal.valueOf BigDecimal intgoukei BigDecimal goen=BigDecimal.valueOf(5); goen BigDecimal.valueOf(5) BigDecimal.valueOf BigDecimal 5 BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN); goenresult goukei.divide(goen,0,RoundingMode.DOWN) goukei.divide goukei goen 0 RoundingMode.DOWN RoundingMode RoundingMode.DOWN int goenresult1=goenresult.intValue(); goenresult1 goenresult.intValue() goenresult.intValue goenresult int goenresult2=goenresult1*5; goenresult2 goenresult1*5 goenresult1 5 int amari=X-(senresult+goenresult2); amari X-(senresult+goenresult2) X (senresult+goenresult2) senresult goenresult2 happy1000=bigresult1*1000 happy1000 bigresult1*1000 bigresult1 1000 happy5=goenresult1*5 happy5 goenresult1*5 goenresult1 5 int happyX=happy1000+happy5; happyX happy1000+happy5 happy1000 happy5 System.out.println(happyX) System.out.println System.out System System.out happyX String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	}

} Main
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	}

}
