import java.util.Scanner;
class Main{
public static void main(String[]args){

Scanner sc= new Scanner(System.in);
int X =sc.nextInt();

int tho = X/500;
int A =X-500*tho;
int five = A/5;
  
int ans=tho*1000+five*5;

System.out.println(ans);
}
} import java.util.Scanner; Scanner java.util class Main{
public static void main(String[]args){

Scanner sc= new Scanner(System.in);
int X =sc.nextInt();

int tho = X/500;
int A =X-500*tho;
int five = A/5;
  
int ans=tho*1000+five*5;

System.out.println(ans);
}
} Main public static void main(String[]args){

Scanner sc= new Scanner(System.in);
int X =sc.nextInt();

int tho = X/500;
int A =X-500*tho;
int five = A/5;
  
int ans=tho*1000+five*5;

System.out.println(ans);
} main {

Scanner sc= new Scanner(System.in);
int X =sc.nextInt();

int tho = X/500;
int A =X-500*tho;
int five = A/5;
  
int ans=tho*1000+five*5;

System.out.println(ans);
} Scanner sc= new Scanner(System.in); sc new Scanner(System.in) int X =sc.nextInt(); X sc.nextInt() sc.nextInt sc int tho = X/500; tho X/500 X 500 int A =X-500*tho; A X-500*tho X 500*tho 500 tho int five = A/5; five A/5 A 5 int ans=tho*1000+five*5; ans tho*1000+five*5 tho*1000 tho 1000 five*5 five 5 System.out.println(ans) System.out.println System.out System System.out ans String[]args args
import java.util.Scanner;
class Main{
public static void main(String[]args){

Scanner sc= new Scanner(System.in);
int X =sc.nextInt();

int tho = X/500;
int A =X-500*tho;
int five = A/5;
  
int ans=tho*1000+five*5;

System.out.println(ans);
}
}