Problem:
Score : 200 points

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.

Sample Input 1

5
1 3 5 4 2

Sample 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.

Sample Input 2

9
9 6 3 2 5 8 7 4 1

Sample Output 2

5

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace __C__ProgramingContest
{
    class Program
    {
        static void Main(string[] args)
        {
            int num5 = 5;
            int num9 = 9;

            ////論理積
            //int numCalc = num5 & num9;

            //Console.Write(Convert.ToString(num5, 2).PadLeft(8, '0'));
            //Console.WriteLine("({0})", num5);

            //Console.Write(Convert.ToString(num9, 2).PadLeft(8, '0'));
            //Console.WriteLine("({0})", num9);

            //Console.WriteLine("{0} & {1} =", num5, num9);

            //Console.Write(Convert.ToString(numCalc, 2).PadLeft(8, '0'));
            //Console.WriteLine("({0})", numCalc);
            // 整数の入力
            int a = int.Parse(Console.ReadLine());
            int ans = 0;
            //int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            // 100個の要素を0で初期化（intをnewした場合はゼロクリアされる）
            int[] x = new int[100005];
            int[] y = new int[100005];
            int[] z = new int[100005];
            //int[,] count = new int[1003,1003];

            string[] input = Console.ReadLine().Split(' ');
            for (int i = 0; i < a; i++)
            {
                x[i] = int.Parse(input[i]);
            }
            for (int i = 0; i < a - 2; i++)
            {
                if ((x[i] < x[i + 1] && x[i + 1] < x[i + 2])
                    ||(x[i] > x[i + 1] && x[i + 1] > x[i + 2]))
                {
                    ans++;
                }
            }
            // 文字列の入力
            //string s = Console.ReadLine();
            //出力
            //Console.WriteLine((a + b) + " " + s);
            Console.WriteLine(ans);

        }
    }
}