import java.util.Scanner;

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

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