A - 山の頂上 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 233 点

問題文

高橋君は山道を歩きながら、道沿いに並んだ N 個の地点で順に標高を記録しました。地点 i(1 \leq i \leq N)の標高は A_i です。

ある地点 i(ただし 1 < i < N)が

A_{i-1} < A_i かつ A_i > A_{i+1}

を満たすとき、すなわち両隣の地点よりも標高が厳密に高いとき、その地点を「山頂」と呼びます。

標高データに含まれる「山頂」の個数を求めてください。

制約

  • 3 \leq N \leq 2 \times 10^5
  • 0 \leq A_i \leq 10^9(1 \leq i \leq N)
  • 入力はすべて整数である

入力

N
A_1 A_2 \cdots A_N
  • 1 行目には、地点の数を表す整数 N が与えられる。
  • 2 行目には、各地点の標高を表す N 個の整数 A_1, A_2, \ldots, A_N が空白区切りで与えられる。

出力

「山頂」である地点の個数を 1 行に出力してください。


入力例 1

5
1 3 2 4 1

出力例 1

2

入力例 2

4
1 2 3 4

出力例 2

0

入力例 3

12
2 5 1 4 3 6 6 5 8 2 7 1

出力例 3

4

入力例 4

25
0 3 1 4 2 5 3 6 4 7 5 8 6 9 7 10 8 11 9 12 10 13 11 14 0

出力例 4

12

入力例 5

3
0 1000000000 0

出力例 5

1

Score : 233 pts

Problem Statement

Takahashi walked along a mountain trail and recorded the elevation at N points lined up along the path, in order. The elevation at point i (1 \leq i \leq N) is A_i.

A point i (where 1 < i < N) is called a "peak" if it satisfies

A_{i-1} < A_i and A_i > A_{i+1},

that is, if its elevation is strictly higher than both of its neighboring points.

Find the number of "peaks" contained in the elevation data.

Constraints

  • 3 \leq N \leq 2 \times 10^5
  • 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers

Input

N
A_1 A_2 \cdots A_N
  • The first line contains an integer N, representing the number of points.
  • The second line contains N integers A_1, A_2, \ldots, A_N separated by spaces, representing the elevation at each point.

Output

Print the number of points that are "peaks" on a single line.


Sample Input 1

5
1 3 2 4 1

Sample Output 1

2

Sample Input 2

4
1 2 3 4

Sample Output 2

0

Sample Input 3

12
2 5 1 4 3 6 6 5 8 2 7 1

Sample Output 3

4

Sample Input 4

25
0 3 1 4 2 5 3 6 4 7 5 8 6 9 7 10 8 11 9 12 10 13 11 14 0

Sample Output 4

12

Sample Input 5

3
0 1000000000 0

Sample Output 5

1