
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int X = sc.nextInt();

    int count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  }
} 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 count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int X = sc.nextInt();

    int count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  } main {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int X = sc.nextInt();

    int count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int count = 0; count 0 count += (X / 500) * 1000 count (X / 500) * 1000 (X / 500) X 500 1000 X = X % 500 X X % 500 X 500 count += (X / 5) * 5 count (X / 5) * 5 (X / 5) X 5 5 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int X = sc.nextInt();

    int count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  }
} public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int X = sc.nextInt();

    int count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  }
} 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 count = 0;
    count += (X / 500) * 1000;
    X = X % 500;
    count += (X / 5) * 5;

    // 出力
    System.out.println(count);
  }
}
