import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 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);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 500) / 5;
            System.out.println(a*1000 + b * 5);
          }
} Main public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 500) / 5;
            System.out.println(a*1000 + b * 5);
          } main {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 500) / 5;
            System.out.println(a*1000 + b * 5);
          } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int a = N / 500; a N / 500 N 500 int b = (N % 500) / 5; b (N % 500) / 5 (N % 500) N 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);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 500) / 5;
            System.out.println(a*1000 + b * 5);
          }
} public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 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);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 500) / 5;
            System.out.println(a*1000 + b * 5);
          }
}