import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long f=n/500,f2=(n%500)/5;
		System.out.println(f*1000+f2*5);
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long f=n/500,f2=(n%500)/5;
		System.out.println(f*1000+f2*5);
	}
} Main public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long f=n/500,f2=(n%500)/5;
		System.out.println(f*1000+f2*5);
	} main {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long f=n/500,f2=(n%500)/5;
		System.out.println(f*1000+f2*5);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n=sc.nextLong(); n sc.nextLong() sc.nextLong sc long f=n/500 f n/500 n 500 f2=(n%500)/5; f2 (n%500)/5 (n%500) n 500 5 System.out.println(f*1000+f2*5) System.out.println System.out System System.out f*1000+f2*5 f*1000 f 1000 f2*5 f2 5 String[] $ $
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long f=n/500,f2=(n%500)/5;
		System.out.println(f*1000+f2*5);
	}
}
