       IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC047-B.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 STR PIC X(18).
       77 W PIC 9(3).
       77 H PIC 9(3).
       77 N PIC 9(3).
       77 I PIC 9(3).
       77 X PIC 9(3).
       77 Y PIC 9(3).
       77 XI PIC 9(3).
       77 YI PIC 9(3).
       77 A PIC 9(1).
       77 J PIC 9(3).
       77 K PIC 9(3).
       01 ARR.
           03 YA OCCURS 100 TIMES.
               05 XA OCCURS 100 TIMES PIC 9(1) VALUE ZERO.
       77 ANS PIC 9(5) VALUE ZERO.
       77 ANSS PIC Z(4)9.

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
            ACCEPT STR FROM SYSIN.
            UNSTRING STR DELIMITED " "
             INTO W H N.
            PERFORM VARYING I FROM 1 BY 1
             UNTIL N < I
               ACCEPT STR FROM SYSIN
               UNSTRING STR DELIMITED " "
                INTO X Y A
               EVALUATE A
                   WHEN 1
                       COMPUTE XI = X
                       PERFORM VARYING J FROM 1 BY 1
                        UNTIL H < J
                           PERFORM VARYING K FROM 1 BY 1
                            UNTIL XI < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
                   WHEN 2
                       COMPUTE XI = X + 1
                       PERFORM VARYING J FROM 1 BY 1
                        UNTIL H < J
                           PERFORM VARYING K FROM XI BY 1
                            UNTIL W < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
                   WHEN 3
                       COMPUTE YI = Y
                       PERFORM VARYING J FROM 1 BY 1
                        UNTIL YI < J
                           PERFORM VARYING K FROM 1 BY 1
                            UNTIL W < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
                   WHEN 4
                       COMPUTE YI = Y + 1
                       PERFORM VARYING J FROM YI BY 1
                        UNTIL H < J
                           PERFORM VARYING K FROM 1 BY 1
                            UNTIL W < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
               END-EVALUATE
            END-PERFORM.
            PERFORM VARYING J FROM 1 BY 1
             UNTIL H < J
               PERFORM VARYING K FROM 1 BY 1
                UNTIL W < K
                   IF XA (J K) = 0 THEN
                       ADD 1 TO ANS
                   END-IF
               END-PERFORM
            END-PERFORM.
            MOVE ANS TO ANSS.
            DISPLAY ANSS.
            STOP RUN.
       END PROGRAM ABC047-B.
