import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	} main {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x = sc.nextLong(); x sc.nextLong() sc.nextLong sc long happy = (x / 500) * 1000; happy (x / 500) * 1000 (x / 500) x 500 1000 x %= 500 x 500 happy += (x / 5) * 5 happy (x / 5) * 5 (x / 5) x 5 5 System.out.println(happy) System.out.println System.out System System.out happy String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	}
} Main
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long happy = (x / 500) * 1000;
		x %= 500;
		happy += (x / 5) * 5;
		System.out.println(happy);
	}
}
