IDENTIFICATION DIVISION.
PROGRAM-ID. 160B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X          PIC 9(10).
01 S1         PIC 9(8).
01 S2         PIC 9(3).
01 A          PIC 9(3).
01 OUT        PIC Z(9)9.
*>
PROCEDURE DIVISION.
  ACCEPT X.
*>
  DIVIDE X BY 500 GIVING S1 REMAINDER A.
  DIVIDE A BY 5   GIVING S2.
  COMPUTE OUT = S1 * 1000 + S2 * 5.
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.