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