import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int five_hundreds = n / 500;
    n -= five_hundreds * 500;
    System.out.println(five_hundreds * 1000 + n/5 * 5);
  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int five_hundreds = n / 500;
    n -= five_hundreds * 500;
    System.out.println(five_hundreds * 1000 + n/5 * 5);
  }
} Main public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int five_hundreds = n / 500;
    n -= five_hundreds * 500;
    System.out.println(five_hundreds * 1000 + n/5 * 5);
  } main {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int five_hundreds = n / 500;
    n -= five_hundreds * 500;
    System.out.println(five_hundreds * 1000 + n/5 * 5);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int five_hundreds = n / 500; five_hundreds n / 500 n 500 n -= five_hundreds * 500 n five_hundreds * 500 five_hundreds 500 System.out.println(five_hundreds * 1000 + n/5 * 5) System.out.println System.out System System.out five_hundreds * 1000 + n/5 * 5 five_hundreds * 1000 five_hundreds 1000 n/5 * 5 n/5 n 5 5 String[] args args
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int five_hundreds = n / 500;
    n -= five_hundreds * 500;
    System.out.println(five_hundreds * 1000 + n/5 * 5);
  }
}