IDENTIFICATION DIVISION.
PROGRAM-ID. 132B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP  PIC X(60).
01 N    PIC 9(2).
01 TBL.
   03 P PIC 9(2) OCCURS 20.
01 P1   PIC 9(2).
01 P2   PIC 9(2).
01 I    PIC 9(2).
01 K    PIC 9(2).
01 OUT  PIC Z9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
  ACCEPT INP.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
*>
    MOVE INP(P1:P2 - P1) TO P(I) 
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  MOVE 0 TO K.
  PERFORM VARYING I FROM 2 BY 1 UNTIL I >= N
   IF (P(I - 1) < P(I) AND P(I) < P(I + 1)) OR
      (P(I - 1) > P(I) AND P(I) > P(I + 1))
     ADD 1 TO K
    END-IF
  END-PERFORM.
*>
  MOVE K TO OUT.
  DISPLAY OUT.
*>
  STOP RUN.
