AtCoder Beginner Contest 132
B
Ordinary Number
AtCoder
⌀ 0
原题
← AC →
翻译中…

Problem Statement

翻译中…

We have a permutation $p$ = {$p_1,\ p_2,\ ...,\ p_n$} of {$1,\ 2,\ ...,\ n$}.

翻译中…

Print the number of elements $p_i$ ($1 < i < n$) that satisfy the following condition:

翻译中…
  • $p_i$ is the second smallest number among the three numbers $p_{i - 1}$, $p_i$, and $p_{i + 1}$.
翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $3 \leq n \leq 20$
  • $p$ is a permutation of {$1,\ 2,\ ...,\ n$}.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

n
p_1 p_2 ... p_n

翻译中…

Output

翻译中…

Print the number of elements $p_i$ ($1 < i < n$) that satisfy the condition.

翻译中…

样例

Input #1
5
1 3 5 4 2
Output #1
2
$p_2 = 3$ is the second smallest number among $p_1 = 1$, $p_2 = 3$, and $p_3 = 5$. Also, $p_4 = 4$ is the second smallest number among $p_3 = 5$, $p_4 = 4$, and $p_5 = 2$. These two elements satisfy the condition.
Input #2
9
9 6 3 2 5 8 7 4 1
Output #2
5
题目信息
题号
abc132_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。