IDENTIFICATION DIVISION.
PROGRAM-ID. 137B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP   PIC  X(100).
01 K     PIC  9(3).
01 X     PIC  9(3).
01 M     PIC S9(3).
01 P     PIC S9(3).
01 I     PIC S9(3).
01 J     PIC S9(3).
01 POS   PIC  9(3).
01 W1    PIC  ZZZ9.
01 W-R1  REDEFINES W1.
   03 W2 PIC ---9.
01 W-R2  REDEFINES W1.
   03 W  PIC X(1) OCCURS 4.
01 OUT   PIC  X(700).
*>  
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO K X.
*>
  COMPUTE M = X - K + 1.
  COMPUTE P = X + K - 1.
display M ' ' P
*>
  MOVE SPACE TO OUT.
  MOVE 1     TO POS.
  PERFORM VARYING I FROM M BY 1 UNTIL I > P
    IF (I < 0)
      MOVE I TO W2
    ELSE
      MOVE I TO W1
    END-IF  
    PERFORM VARYING J FROM 1 BY 1 UNTIL J > 4
      IF (W(J) NOT = ' ')
        MOVE W(J) TO OUT(POS:1)
        ADD 1     TO POS
      END-IF
    END-PERFORM  
    MOVE ' ' TO OUT(POS:1)
    ADD 1    TO POS
  END-PERFORM.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.
