import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    } main {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc long happiness = 0; happiness 0 happiness += (n / 500) * 1000 happiness (n / 500) * 1000 (n / 500) n 500 1000 n = n % 500 n n % 500 n 500 happiness += (n / 5) * 5 happiness (n / 5) * 5 (n / 5) n 5 5 System.out.println(happiness) System.out.println System.out System System.out happiness String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long happiness = 0;
        happiness += (n / 500) * 1000;
        n = n % 500;
        happiness += (n / 5) * 5;
        System.out.println(happiness);
    }
}