import java.util.*;

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

class Main {
  public static void main(String[] args) {
         Scanner scanner = new Scanner(System.in);
         int X = scanner.nextInt();
         int happiness = 0;
         happiness = (X/500)*1000;
         X = X%500;
         happiness += (X/5)*5;
         System.out.println(happiness);
         scanner.close();
  }
}