IDENTIFICATION DIVISION.
PROGRAM-ID. 123B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N     PIC 9(3).
01 N-R   REDEFINES N.
   03 N1 PIC 9(2).
   03 N2 PIC 9(1).
01 N-R2  REDEFINES N.
   03 N3 PIC 99V9.
01 W1    PIC 9(3).
01 N2W   PIC 9(2).
01 M1    PIC 9(3).
01 M2    PIC 9(3).
01 I     PIC 9(1).
01 GK    PIC 9(3).
01 OUT   PIC ZZ9.
*>
PROCEDURE DIVISION.
  MOVE 10 TO N2W.
  MOVE  0 TO GK M1 M2.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5
    ACCEPT N
    COMPUTE W1 = N3 + 0.9
    COMPUTE W1 = W1 * 10
    IF (N2 > 0) AND (N2 < N2W)
      COMPUTE GK = GK + M1 - M2 + N
      MOVE W1 TO M1
      MOVE N  TO M2
      MOVE N2 TO N2W
    ELSE
      ADD  W1 TO GK 
    END-IF
  END-PERFORM.  
*>
  MOVE GK TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.
