       IDENTIFICATION DIVISION.
       PROGRAM-ID. AOC-2021-01-2.
       AUTHOR. ANNA KOSIERADZKA.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT INPUTFILE ASSIGN TO "d01.input"
           ORGANIZATION IS LINE SEQUENTIAL.

       DATA DIVISION.

       FILE SECTION.
         FD INPUTFILE.
         01 INPUTRECORD PIC X(4).

       WORKING-STORAGE SECTION.
         01 FILE-STATUS PIC 9 VALUE 0.
         01 WS-MEASURE PIC 9(5).
         01 WS-PREV-MEASURE PIC 9(5) VALUE 99999.
         01 WS-CURR PIC 9(4) VALUE 9999.
         01 WS-PREV-1 PIC 9(4) VALUE 9999.
         01 WS-PREV-2 PIC 9(4) VALUE 9999.
         01 WS-PREV-3 PIC 9(4) VALUE 9999.
         01 WS-NUM PIC 9(4) VALUE 0.

       PROCEDURE DIVISION.
       001-MAIN.
            OPEN INPUT INPUTFILE.
            PERFORM 002-READ UNTIL FILE-STATUS = 1.
            CLOSE INPUTFILE.
            DISPLAY WS-NUM.
            STOP RUN.

       002-READ.
            READ INPUTFILE
                AT END MOVE 1 TO FILE-STATUS
                NOT AT END PERFORM 003-PROCESS-RECORD
            END-READ.

       003-PROCESS-RECORD.
           COMPUTE WS-CURR = FUNCTION NUMVAL(INPUTRECORD)
           COMPUTE WS-MEASURE = WS-CURR + WS-PREV-MEASURE - WS-PREV-1
           IF WS-MEASURE > WS-PREV-MEASURE THEN
               ADD 1 TO WS-NUM
           END-IF
           COMPUTE WS-PREV-MEASURE = WS-MEASURE
           MOVE WS-PREV-2 TO WS-PREV-1
           MOVE WS-PREV-3 TO WS-PREV-2
           MOVE WS-CURR TO WS-PREV-3.
