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