IDENTIFICATION DIVISION.
PROGRAM-ID. 169C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP          PIC X(1900000).
*>
WORKING-STORAGE SECTION.
01 N          PIC 9(06) COMP.
01 P1         PIC 9(07) COMP.
01 P2         PIC 9(07) COMP.
01 I          PIC 9(06) COMP.
01 TBL.
   03 A       PIC S9(18) OCCURS 100000.
01 X          PIC X(19).
01 PL         PIC 9(01).
01 FLG-ERR    PIC X(01).
01 CNT        PIC S9(18) COMP.
01 CNTW       PIC S9(18) COMP.
01 AMR        PIC 9(18)  COMP.
01 AMR2       PIC 9(18)  COMP.
01 OUT        PIC Z(17)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE ZERO TO TBL.
  MOVE 1 TO CNT.
  MOVE 1 TO P1
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N OR CNT = 0
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I) X
    IF (X(19:1) NOT = ' ') 
      MOVE -1 TO A(I)
    ELSE
      IF (A(I) = 0) 
        MOVE 0 TO CNT
      END-IF
    END-IF
*>
    COMPUTE P1 = P2 + 1
  END-PERFORM.

*>
  MOVE 999999999999999999 TO CNTW.
  MOVE 1                  TO PL.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N OR CNT <= 0
    IF (A(I) = -1) 
      IF (CNTW = 999999999999999999)
        MOVE  1 TO CNTW
      ELSE
        MOVE -1 TO CNT
      END-IF
    ELSE
      DIVIDE CNTW BY A(I) GIVING CNTW REMAINDER AMR
      IF (AMR + PL = A(I)) AND (A(I) > 1) AND (AMR2 = 0)
        ADD  1 TO CNTW
        MOVE 0 TO PL
      END-IF
*>
      IF (CNTW = 0)
        MOVE -1 TO CNT
      ELSE
        IF (CNTW = 1) AND (AMR = 0)
          MOVE -9 TO CNT
        END-IF
      END-IF
      MOVE AMR TO AMR2
    END-IF
*>
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  EVALUATE CNT
    WHEN 0
      DISPLAY '0'
    WHEN -1
      DISPLAY '-1'
    WHEN -9
      DISPLAY '1000000000000000000'
    WHEN OTHER
      PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
        COMPUTE CNT = CNT * A(I)
      END-PERFORM
*>
      MOVE CNT TO OUT
      DISPLAY FUNCTION TRIM(OUT)
  END-EVALUATE.
*>
  STOP RUN.
