    import java.util.*;
    public class Main {
        static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        }

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        }
    } import java.util.*; util.* java public class Main {
        static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        }

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        }
    } Main static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        } find {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        } Stack<Character> ch = new Stack<>(); ch new Stack<>() for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            } int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            } {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            } char ch1 = s.charAt(i); ch1 s.charAt(i) s.charAt s i if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                } ch1 == '(' ch1 '(' ch.push(ch1) ch.push ch ch1 if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                } ch1 == ')' ch1 ')' {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                } if (ch.isEmpty() || ch.peek() != '(') return false; ch.isEmpty() || ch.peek() != '(' ch.isEmpty() ch.isEmpty ch ch.peek() != '(' ch.peek() ch.peek ch '(' return false; false ch.pop() ch.pop ch return ch.isEmpty(); ch.isEmpty() ch.isEmpty ch String s s public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        } main {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x=0; x 0 x+=(n/500)*1000 x (n/500)*1000 (n/500) n 500 1000 n=n%500 n n%500 n 500 x+=(n/5)*5 x (n/5)*5 (n/5) n 5 5 System.out.println(x) System.out.println System.out System System.out x String[] args args public class Main {
        static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        }

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        }
    } public class Main {
        static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        }

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        }
    } Main
    import java.util.*;
    public class Main {
        static boolean find(String s) {
            Stack<Character> ch = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch1 = s.charAt(i);
                if (ch1 == '(') ch.push(ch1);
                else if (ch1 == ')') {
                    if (ch.isEmpty() || ch.peek() != '(') return false;
                    ch.pop();
                }
            }
            return ch.isEmpty();
        }

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int x=0;
           x+=(n/500)*1000;
           n=n%500;
           x+=(n/5)*5;
            System.out.println(x);
        }
    }
