import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	}
} import java.util.*; util.* java public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	} main {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int Five_Count = 0; Five_Count 0 int Thousand_Count = 0; Thousand_Count 0 int num = 0; num 0 for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		} int i = 0; int i = 0; i 0 i < X i X i++ i++ i {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		} {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		} num = X % 500 num X % 500 X 500 Thousand_Count = X / 500 Thousand_Count X / 500 X 500 Five_Count = num / 5 Five_Count num / 5 num 5 System.out.println(Thousand_Count * 1000 + Five_Count * 5) System.out.println System.out System System.out Thousand_Count * 1000 + Five_Count * 5 Thousand_Count * 1000 Thousand_Count 1000 Five_Count * 5 Five_Count 5 String[] args args public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	}
} public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	}
} Main
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Five_Count = 0;
		int Thousand_Count = 0;
		int num = 0;
		for(int i = 0;i < X;i++) {
			num = X % 500;
			Thousand_Count = X / 500;
			Five_Count = num / 5;
		}
		System.out.println(Thousand_Count * 1000 + Five_Count * 5);
	}
}