import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	}

} Main public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	} main {
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	} try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		} {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int fhCount = x / 500; fhCount x / 500 x 500 int rest = x - fhCount * 500; rest x - fhCount * 500 x fhCount * 500 fhCount 500 int fCount = rest / 5; fCount rest / 5 rest 5 System.out.println(fhCount * 1000 + fCount * 5) System.out.println System.out System System.out fhCount * 1000 + fCount * 5 fhCount * 1000 fhCount 1000 fCount * 5 fCount 5 String[] args args public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	}

} public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int x = sc.nextInt();
			
			int fhCount = x / 500;
			
			int rest = x - fhCount * 500;
			int fCount = rest / 5;
			
			System.out.println(fhCount * 1000 + fCount * 5);
			
		}
	}

}