import java.io.*;
class Main{
  public static void main(String []args)throws IOException{
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int num = Integer.parseInt(br.readLine());
    
    int happiness;
    
    happiness = (num / 500) * 1000;
    num = num % 500;
    happiness = happiness + (num / 5) * 5;
    
    System.out.println(happiness);
  }
} import java.io.*; io.* java class Main{
  public static void main(String []args)throws IOException{
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int num = Integer.parseInt(br.readLine());
    
    int happiness;
    
    happiness = (num / 500) * 1000;
    num = num % 500;
    happiness = happiness + (num / 5) * 5;
    
    System.out.println(happiness);
  }
} Main public static void main(String []args)throws IOException{
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int num = Integer.parseInt(br.readLine());
    
    int happiness;
    
    happiness = (num / 500) * 1000;
    num = num % 500;
    happiness = happiness + (num / 5) * 5;
    
    System.out.println(happiness);
  } main {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int num = Integer.parseInt(br.readLine());
    
    int happiness;
    
    happiness = (num / 500) * 1000;
    num = num % 500;
    happiness = happiness + (num / 5) * 5;
    
    System.out.println(happiness);
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int num = Integer.parseInt(br.readLine()); num Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int happiness; happiness happiness = (num / 500) * 1000 happiness (num / 500) * 1000 (num / 500) num 500 1000 num = num % 500 num num % 500 num 500 happiness = happiness + (num / 5) * 5 happiness happiness + (num / 5) * 5 happiness (num / 5) * 5 (num / 5) num 5 5 System.out.println(happiness) System.out.println System.out System System.out happiness String []args args
import java.io.*;
class Main{
  public static void main(String []args)throws IOException{
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int num = Integer.parseInt(br.readLine());
    
    int happiness;
    
    happiness = (num / 500) * 1000;
    num = num % 500;
    happiness = happiness + (num / 5) * 5;
    
    System.out.println(happiness);
  }
}