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 9(18) OCCURS 100000.
01 X          PIC X(19).
01 ER         PIC 9(01).
01 ONEC       PIC 9(06).
01 FLG-ERR    PIC X(01).
01 CNT        PIC 9(18) COMP.
01 CNTW       PIC 9(18) COMP.
01 OUT        PIC Z(17)9.
01 OUT-R      REDEFINES OUT PIC X(18).
01 OUT2       PIC X(19).
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE ZERO TO TBL ONEC ER.
  MOVE SPACE TO OUT-R.
  MOVE 1 TO P1
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N OR OUT-R NOT = SPACE
    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 ER
    ELSE
      IF (A(I) = 0)
        MOVE 0 TO OUT
      ELSE
        IF (A(I) = 1)
          ADD 1 TO ONEC
        END-IF
      END-IF
    END-IF
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  IF (ER = 1 AND ONEC = N - 1) AND (OUT-R = SPACE)
    MOVE '1000000000000000000' TO OUT2
  ELSE
    MOVE SPACE                 TO OUT2
  END-IF.
*>
  MOVE '0' TO FLG-ERR
  MOVE 0   TO ER
  IF (OUT-R = SPACE) AND (OUT2 = SPACE)
    MOVE 1   TO CNT CNTW
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > N OR CNT = 0
      COMPUTE CNT = CNT * A(I)
      IF (A(I) NOT = 1) AND (CNT = CNTW)
        MOVE 1 TO ER
      ELSE
        MOVE CNT TO CNTW
      END-IF
    END-PERFORM
    IF (ER = 1) AND (I > N)
      IF (A(I - 1)(18:1) = 0) OR (A(I - 2)(18:1) = 0) THEN
        MOVE '1000000000000000000' TO OUT2
      ELSE
        MOVE 1 TO FLG-ERR
      END-IF         
    ELSE
      MOVE 1 TO FLG-ERR
    END-IF      
  END-IF
*>
  IF (FLG-ERR = 1)
    DISPLAY '-1'
  ELSE
    IF (OUT-R = SPACE)
      IF (OUT2 = SPACE)
        MOVE CNT TO OUT
        DISPLAY FUNCTION TRIM(OUT)
      ELSE
        DISPLAY OUT2
      END-IF 
    ELSE
      DISPLAY FUNCTION TRIM(OUT)
    END-IF
  END-IF.
*>
  STOP RUN.
