import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    }
 } import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    }
 } Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    } main {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int num500 = x / 500; num500 x / 500 x 500 int num50 = x % 500 / 5; num50 x % 500 / 5 x % 500 x 500 5 System.out.println(num500 * 1000 + num50 * 5) System.out.println System.out System System.out num500 * 1000 + num50 * 5 num500 * 1000 num500 1000 num50 * 5 num50 5 String[] args args public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    }
 } public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    }
 } Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int num500 = x / 500;
      	int num50 = x % 500 / 5;
      	System.out.println(num500 * 1000 + num50 * 5);
    }
 }