import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
}

} import java.util.*; util.* java public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
}

} Main public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
} main {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long n=sc.nextLong(); n sc.nextLong() sc.nextLong sc long s=0; s 0 long q=n/500; q n/500 n 500 s=q*1000 s q*1000 q 1000 long z=n%500; z n%500 n 500 long f=(z/5); f (z/5) z 5 s=s+(f*5) s s+(f*5) s (f*5) f 5 System.out.println(s) System.out.println System.out System System.out s String[] args args public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
}

} public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
}

} Main
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long n=sc.nextLong();
long s=0;
long q=n/500;
s=q*1000;
long z=n%500;
long f=(z/5);
s=s+(f*5);
System.out.println(s);
}

}