  import java.util.Scanner;

  public class Main {

    public static void main(String[] args) {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    }
  } import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    }
  } Main public static void main(String[] args) {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    } main {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    } int x = Integer.parseInt(new Scanner(System.in).nextLine()); x Integer.parseInt(new Scanner(System.in).nextLine()) Integer.parseInt Integer new Scanner(System.in).nextLine() new Scanner(System.in).nextLine new Scanner(System.in) int c500 = x/500; c500 x/500 x 500 int r500 = x%500; r500 x%500 x 500 int c5 = r500/5; c5 r500/5 r500 5 System.out.printf("%d\n",c500*1000+c5*5) System.out.printf System.out System System.out "%d\n" c500*1000+c5*5 c500*1000 c500 1000 c5*5 c5 5 String[] args args public class Main {

    public static void main(String[] args) {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    }
  } public class Main {

    public static void main(String[] args) {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    }
  } Main
  import java.util.Scanner;

  public class Main {

    public static void main(String[] args) {
      int x = Integer.parseInt(new Scanner(System.in).nextLine());
      int c500 = x/500;
      int r500 = x%500;
      int c5 = r500/5;
      System.out.printf("%d\n",c500*1000+c5*5);
    }
  }