This page is still under construction.

Parts of this page are still being built. What you see may change.

Counting Peaks of Infection

Time limit1sMemory limit1024 MB

Summary
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

nn is the number of days on which positive case counts are reported (3≤n≤10003 \le n \le 1000). viv_i is the number of positive cases on day ii, an integer between 0 and 1000 inclusive. v1v_1 is 0, and vi≠vi+1v_i \ne v_{i+1} for 1≤i<n1 \le i < n. 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.

Examples1

  1. Example 1

    Input
    3
    0 1000 0
    5
    0 1 2 0 1
    3
    0 1 2
    7
    0 1 0 1 8 7 6
    11
    0 4 3 7 6 10 7 8 4 6 10
    0
    
    Expected output
    1
    1
    0
    2
    4