Counting Peaks of Infection
Time limit1sMemory limit1024 MB
Count the peaks in each dataset of daily positive case counts, where a peak is a day with more cases than both the day before and the day after.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
For the new infectious disease, COVID-99, the numbers of new positive cases from PCR tests conducted in the city are reported daily. The municipal public relations department asks you to write a program that counts the number of peaks so far in the positive case counts.
Here, a peak is a day on which the number of positive cases is greater than both the day before and the next day. PCR tests started before the disease spread in the city, so the number of positive cases on the first day is zero. The last reported day is not counted as a peak. No two consecutive days have the same number of positive cases.

Figure A-1: Numbers of positive cases for the last dataset. Red circles mark the peaks.
Input
The input consists of multiple datasets. Each dataset has the following format.
n
v1 ... vn
is the number of days on which positive case counts are reported (). is the number of positive cases on day , an integer between 0 and 1000 inclusive. is 0, and for . The input ends with a line containing a single 0. There are at most 100 datasets.
Output
For each dataset, output the number of peaks on its own line.