#CCBOTPBA0000018. Đếm cặp đổi chiều (Count Local Peaks)

Đếm cặp đổi chiều (Count Local Peaks)

Count Local Peaks

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Count strict local peaks: an interior value must be greater than both immediate neighbors. Equal values do not form peaks; fewer than three values give zero.

Input

n, then exactly n integers.

Output

Number of strict local peaks.

Subtasks

  • Subtask 1 (20%): n ≤ 20, |a_i| ≤ 100.

  • Subtask 2 (30%): n ≤ 1000, |a_i| ≤ 10^6.

  • Subtask 3 (50%): n ≤ 100000, |a_i| ≤ 10^9.

Examples

Example 1

Input:

5
1 3 2 4 1

Output:

2

Explanation: The middle values 3 and 4 are each strictly higher than both neighbors.

Example 2

Input:

3
2 2 1

Output:

0

Explanation: The middle value ties its left neighbor, so it is not a peak.