import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    } main {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long x= sc.nextLong(); x sc.nextLong() sc.nextLong sc long happinessCount = 0; happinessCount 0 while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        } x>4 x 4 {
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        } if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            } x>=500 x 500 {
                happinessCount += 1000;
                x -= 500;
            } happinessCount += 1000 happinessCount 1000 x -= 500 x 500 {
                happinessCount += 5;
                x -= 5;
            } happinessCount += 5 happinessCount 5 x -= 5 x 5 System.out.println(happinessCount) System.out.println System.out System System.out happinessCount String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x= sc.nextLong();
        long happinessCount = 0;
        while (x>4){
            if(x>=500){
                happinessCount += 1000;
                x -= 500;
            }else {
                happinessCount += 5;
                x -= 5;
            }
        }
        System.out.println(happinessCount);
    }
}