import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  } main {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x = sc.nextLong(); x sc.nextLong() sc.nextLong sc long t = x / 500; t x / 500 x 500 x -= (500 * t) x (500 * t) 500 t long s = x / 5; s x / 5 x 5 System.out.println((1000 * t) + (5 * s)) System.out.println System.out System System.out (1000 * t) + (5 * s) (1000 * t) 1000 t (5 * s) 5 s String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long t = x / 500;
    x -= (500 * t);
    long s = x / 5;
    System.out.println((1000 * t) + (5 * s));
  }
}