import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  } main {
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long s=sc.nextLong(); s sc.nextLong() sc.nextLong sc long a a b b c; c a=s/500 a s/500 s 500 b=(s%500)/5 b (s%500)/5 (s%500) s 500 5 c=a*1000+b*5 c a*1000+b*5 a*1000 a 1000 b*5 b 5 System.out.print(c) System.out.print System.out System System.out c String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long s=sc.nextLong();
    long a,b,c;
    a=s/500;
    b=(s%500)/5;
    c=a*1000+b*5;
    System.out.print(c);
  }
}