/* package whatever; // 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
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	}
} 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
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	}
} Main public static void main (String[] args) throws java.lang.Exception
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	} main {try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	} try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){} catch (Exception e){} Exception e {} {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) long x; x x=Long.parseLong(br.readLine()) x Long.parseLong(br.readLine()) Long.parseLong Long br.readLine() br.readLine br long sum =( (x/500)*1000)+((x%500)/5)*5; sum ( (x/500)*1000)+((x%500)/5)*5 ( (x/500)*1000) (x/500) x 500 1000 ((x%500)/5)*5 ((x%500)/5) (x%500) x 500 5 5 System.out.print(sum) System.out.print System.out System System.out sum String[] args args public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	}
} public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	}
} Main
/* package whatever; // 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
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	}
}