/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	}
} Main public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int t=Integer.parseInt(br.readLine()); t Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int coin_big= t/500; coin_big t/500 t 500 int rem= t%500; rem t%500 t 500 int coin_small=rem/5; coin_small rem/5 rem 5 int ans= (coin_big*1000 + coin_small*5 ); ans (coin_big*1000 + coin_small*5 ) coin_big*1000 coin_big 1000 coin_small*5 coin_small 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	}
} public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	}
} Main
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String s=br.readLine().trim();
		//System.out.println(s);
		
		int t=Integer.parseInt(br.readLine());
		
		int coin_big= t/500;
		int rem= t%500;
		
		int coin_small=rem/5;
		
		int ans= (coin_big*1000 + coin_small*5 );
		
		System.out.println(ans);
		
		/*if((s.charAt(2)==s.charAt(3)) && (s.charAt(4)==s.charAt(5)))
		    System.out.println("Yes");
		else
		    System.out.println("No");*/
	}
}
