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