//package algorthims.LeetCode;

import java.util.*;


public class Main{
    
    public static int points( int num ){
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    }
    public static void main(String[] args) {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    }
} import java.util.*; util.* java public class Main{
    
    public static int points( int num ){
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    }
    public static void main(String[] args) {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    }
} Main public static int points( int num ){
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    } points {
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    } int points = 0; points 0 int mul = num / 500; mul num / 500 num 500 num %= 500 num 500 points = points + mul*1000 points points + mul*1000 points mul*1000 mul 1000 if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	} num > 0 num 0 {
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	} mul = num/5 mul num/5 num 5 num %= 5 num 5 points = points + mul*5 points points + mul*5 points mul*5 mul 5 return points; points int num num public static void main(String[] args) {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    } main {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    } Scanner sc = new Scanner( System.in ); sc new Scanner( System.in ) System.out.print( points( sc.nextInt() )) System.out.print System.out System System.out points( sc.nextInt() ) points sc.nextInt() sc.nextInt sc String[] args args public class Main{
    
    public static int points( int num ){
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    }
    public static void main(String[] args) {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    }
} public class Main{
    
    public static int points( int num ){
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    }
    public static void main(String[] args) {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    }
} Main
//package algorthims.LeetCode;

import java.util.*;


public class Main{
    
    public static int points( int num ){
	
	int points = 0;
	
	int mul = num / 500;
	num %= 500;
	points = points + mul*1000;
	    
	if( num > 0){
	    mul = num/5;
	    num %= 5;
	    points = points + mul*5;
	}
	    
	return points;
	
    }
    public static void main(String[] args) {
	
	Scanner sc = new Scanner( System.in );
	System.out.print( points( sc.nextInt() ));
    }
}
