import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   }
} 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 happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   } main {
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int happy = 0; happy 0 int cnt1 = 0; cnt1 0 int cnt2 = 0; cnt2 0 while(x>=500){
         cnt1++;
         x = x-500;
      } x>=500 x 500 {
         cnt1++;
         x = x-500;
      } cnt1++ cnt1 x = x-500 x x-500 x 500 happy += 1000*cnt1 happy 1000*cnt1 1000 cnt1 while(x>=5){
         cnt2++;
         x = x-5;
      } x>=5 x 5 {
         cnt2++;
         x = x-5;
      } cnt2++ cnt2 x = x-5 x x-5 x 5 happy += 5*cnt2 happy 5*cnt2 5 cnt2 System.out.println(happy) System.out.println System.out System System.out happy String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   }
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   }
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int happy = 0;
      int cnt1 = 0;
      int cnt2 = 0;
      while(x>=500){
         cnt1++;
         x = x-500;
      }
      happy += 1000*cnt1;
      while(x>=5){
         cnt2++;
         x = x-5;
      }
      happy += 5*cnt2;
      System.out.println(happy);     
   }
}