IDENTIFICATION DIVISION.
PROGRAM-ID. 161D.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N    PIC 9(6).
01 TBL.
   03 X PIC 9(10) COMP OCCURS 100002.
01 I    PIC 9(06) COMP.
01 L    PIC 9(06) COMP.
01 S    PIC 9(09) COMP.
01 A    PIC 9(01) COMP.
01 OUT  PIC Z(9)9.
*>  
PROCEDURE DIVISION.
  ACCEPT N.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 9
    MOVE I TO X(I)
  END-PERFORM.
*>
  MOVE 9 TO L.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N OR L >= N
    DIVIDE X(I) BY 10 GIVING S REMAINDER A
    IF (A > 0) THEN
      ADD 1 TO L
      COMPUTE X(L) = X(I) * 10 + A - 1
    END-IF
*>
    ADD 1 TO L
    COMPUTE X(L) = X(I) * 10 + A
*>
    IF (A < 9) THEN
      ADD 1 TO L
      COMPUTE X(L) = X(I) * 10 + A + 1
    END-IF
  END-PERFORM.
*>
  MOVE X(N) TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.
 