IDENTIFICATION DIVISION.
PROGRAM-ID. A-BEGINNER.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP     PIC X(100).
01 IN-DATA.
   03 DT-X1 PIC X(10).
   03 DT-X2 PIC X(10).
   03 DT-X3 PIC X(10).
01 IN-LEN.
   03 DT-L1 PIC 9(2).
   03 DT-L2 PIC 9(2).
   03 DT-L3 PIC 9(2).
01 IN-N     PIC 9(3).
01 IN-NUM.
   03 IN-NO PIC 9(3)    OCCURS 10.

01 I        PIC 9(2).
01 X        PIC 9(2). 
01 Y        PIC 9(2). 
01 SW-HIT   PIC X.

01 TBL-MATRIX.
   03 TBL-Y     OCCURS 3.
     05 TBL-X   OCCURS 3.
       07 TBL-A PIC 9(3).
01 TBL-BINGO.
   03 TBL-BX    PIC 9(1) OCCURS 3.
   03 TBL-BY    PIC 9(1) OCCURS 3.
   03 TBL-BS    PIC 9(1) OCCURS 2.

PROCEDURE DIVISION.
MAIN-001.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3
    ACCEPT INP
    UNSTRING INP DELIMITED BY ALL ' '
        INTO DT-X1 COUNT IN DT-L1
             DT-X2 COUNT IN DT-L2
             DT-X3 COUNT IN DT-L3
    MOVE DT-X1(1:DT-L1) TO TBL-A(I 1)
    MOVE DT-X2(1:DT-L2) TO TBL-A(I 2)
    MOVE DT-X3(1:DT-L3) TO TBL-A(I 3)
  END-PERFORM. 

  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO DT-X1 COUNT IN DT-L1.
  MOVE DT-X1(1:DT-L1) TO IN-N.

  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3
    MOVE 0 TO TBL-BX(I)
    MOVE 0 TO TBL-BY(I)
  END-PERFORM.
  MOVE   0 TO TBL-BS(1).
  MOVE   0 TO TBL-BS(2).  

  PERFORM VARYING I FROM 1 BY 1 UNTIL I > IN-N
    ACCEPT INP
    UNSTRING INP DELIMITED BY ALL ' '
        INTO DT-X1 COUNT IN DT-L1
    MOVE DT-X1(1:DT-L1) TO IN-NO(I)

    MOVE '0' TO SW-HIT
    PERFORM VARYING Y FROM 1 BY 1 UNTIL Y > 3 OR SW-HIT = '1'
      PERFORM VARYING X FROM 1 BY 1 UNTIL X > 3 OR SW-HIT = '1'
        IF IN-NO(I) = TBL-A(Y X)
           ADD  1   TO TBL-BX(X)
           ADD  1   TO TBL-BY(Y)
           IF (X = Y)
             ADD 1  TO TBL-BS(1)
           END-IF
           IF (X + Y = 4)
             ADD 1  TO TBL-BS(2)
           END-IF
 
           MOVE '1' TO SW-HIT
        END-IF
      END-PERFORM 
    END-PERFORM
  END-PERFORM.
  
  MOVE '0' TO SW-HIT
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3 OR SW-HIT = '1'
    IF (TBL-BX(I) >= 3) OR (TBL-BY(I) > 3)
      MOVE '1' TO SW-HIT
    END-IF 
  END-PERFORM.
  IF (SW-HIT = '1' ) OR (TBL-BS(1) >= 3) OR (TBL-BS(2) >= 3)
    DISPLAY 'Yes'
  ELSE
    DISPLAY 'No' 
  END-IF.

MAIN-EXIT.
  STOP RUN.
      