       IDENTIFICATION DIVISION.
       PROGRAM-ID. DAY09-PART1.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       78 LS-BUFFER-SIZE VALUE 25.
       77 LS-NUMBER PIC 9(20).
       77 LS-INDEX PIC 9(2) VALUE 1.
       77 LS-INDEX-SEARCH1 PIC 9(2).
       77 LS-INDEX-SEARCH2 PIC 9(2).
       77 LS-SUM PIC 9(20).
       01 LS-BUFFER.
           05 LS-ELEMENT PIC 9(20) VALUE 0 OCCURS LS-BUFFER-SIZE TIMES.

       PROCEDURE DIVISION.
           PERFORM READ-NUMBER THRU MOVE-TO-BUFFER LS-BUFFER-SIZE TIMES.
           PERFORM MAIN-LOOP UNTIL 1 < 0.
           STOP RUN.

       READ-NUMBER.
           ACCEPT LS-NUMBER ON EXCEPTION EXIT SECTION.

       MOVE-TO-BUFFER.
           MOVE LS-NUMBER TO LS-ELEMENT(LS-INDEX).
           ADD 1 TO LS-INDEX.
           IF LS-INDEX GREATER THAN LS-BUFFER-SIZE
                   SET LS-INDEX TO 1
           END-IF.

       MAIN-LOOP.
           PERFORM READ-NUMBER.
           PERFORM FIND-MATCH.
           PERFORM MOVE-TO-BUFFER.

       FIND-MATCH.
           PERFORM VARYING LS-INDEX-SEARCH1 FROM 1 BY 1 UNTIL
                   LS-INDEX-SEARCH1>LS-BUFFER-SIZE
                   AFTER LS-INDEX-SEARCH2 FROM 1 BY 1
                   UNTIL LS-INDEX-SEARCH2>LS-BUFFER-SIZE

                   IF LS-ELEMENT(LS-INDEX-SEARCH1) NOT EQUAL
                           LS-ELEMENT(LS-INDEX-SEARCH2) THEN

                           ADD LS-ELEMENT(LS-INDEX-SEARCH1) TO
                           LS-ELEMENT(LS-INDEX-SEARCH2) GIVING LS-SUM

                           IF LS-SUM EQUAL LS-NUMBER
                           THEN EXIT PERFORM END-IF
                   END-IF
           END-PERFORM.

           IF LS-SUM NOT EQUAL LS-NUMBER
                   DISPLAY "NOT FOUND " LS-NUMBER
           END-IF.
