IDENTIFICATION DIVISION.
PROGRAM-ID. A-BEGINNER.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP     PIC X(501).
01 IN-DATA.
   03 DT-X1 PIC X(10).
   03 DT-X2 PIC X(10).
01 IN-LEN.
   03 DT-L1 PIC 9(2).
   03 DT-L2 PIC 9(2).
01 IN-N     PIC 9(3).
01 IN-A-ALL.
   03 IN-A  PIC 9(4) OCCURS 100.
01 IN-AW1   PIC 9(4).
01 IN-AW2   PIC 9(4).
01 I        PIC 9(3).
01 P1       PIC 9(3).
01 P2       PIC 9(3).
01 OUT-N    PIC X(8).
 
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO DT-X1 COUNT IN DT-L1.
  MOVE DT-X1(1:DT-L1) TO IN-N.
 
  ACCEPT INP.
  MOVE 1 TO I.
  MOVE 1 TO P1.
  PERFORM UNTIL I > IN-N
    MOVE P1 TO P2
    PERFORM UNTIL INP(P1:1) < '0' OR INP(P1:1) > '9'
      ADD 1 TO P1
    END-PERFORM
 
    MOVE INP(P2:P1 - P2) TO IN-A(I)
    ADD 1 TO I
    ADD 1 TO P1
  END-PERFORM.
 
  MOVE 'APPROVED' TO OUT-N.
  MOVE 1 TO I.
  PERFORM UNTIL (I > IN-N) OR
                (OUT-N = 'DENIED')
    COMPUTE IN-AW1 = IN-A(I) / 2
    IF (IN-A(I) = IN-AW1 * 2)
      COMPUTE IN-AW1 = IN-A(I) / 3
      COMPUTE IN-AW2 = IN-A(I) / 5
      IF (IN-A(I) = IN-AW1 * 3) OR
         (IN-A(I) = IN-AW2 * 5)
        CONTINUE
      ELSE
        MOVE 'DENIED' TO OUT-N
      END-IF
    END-IF
    ADD 1 TO I  
  END-PERFORM.
  DISPLAY OUT-N.
 
MAIN-EXIT.
  STOP RUN.
  