import java.util.*;

public class Main {
    public static void main(String[] args){
 
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
   
	int gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

    }
} 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 gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

    }
} Main public static void main(String[] args){
 
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
   
	int gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

    } main {
 
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
   
	int gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

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

      System.out.println(1000*gohyaku + 5*goen);

    }
} public class Main {
    public static void main(String[] args){
 
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
   
	int gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
 
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
   
	int gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

    }
}