
import java.util.*;
public class Main {
	public static void main ( String [] args) {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	}

} import java.util.*; util.* java public class Main {
	public static void main ( String [] args) {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	}

} Main public static void main ( String [] args) {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	} main {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	} Scanner input = new Scanner (System.in); input new Scanner (System.in) int x = input.nextInt(); x input.nextInt() input.nextInt input int h = (x/500)*1000; h (x/500)*1000 (x/500) x 500 1000 int f = ((x%500)/5)*5; f ((x%500)/5)*5 ((x%500)/5) (x%500) x 500 5 5 System.out.println(h+f) System.out.println System.out System System.out h+f h f String [] args args public class Main {
	public static void main ( String [] args) {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	}

} public class Main {
	public static void main ( String [] args) {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	}

} Main

import java.util.*;
public class Main {
	public static void main ( String [] args) {
		Scanner input = new Scanner (System.in);
		int x = input.nextInt();
		int h = (x/500)*1000;
		int f = ((x%500)/5)*5;
		System.out.println(h+f);
		
	}

}