import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  } main {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int rem1 = X/500; rem1 X/500 X 500 int rem2 = (X-(rem1*500))/5; rem2 (X-(rem1*500))/5 (X-(rem1*500)) X (rem1*500) rem1 500 5 System.out.println(1000*rem1+5*rem2) System.out.println System.out System System.out 1000*rem1+5*rem2 1000*rem1 1000 rem1 5*rem2 5 rem2 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  }
} Main
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  }
}