import java.util.Arrays; import java.util.Scanner; public class No116 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // N本の竹を配列に格納 int[] take = new int[n]; for(int i = 0; i < n; i++){ take[i] = sc.nextInt(); } sc.close(); int kadomatuCount = 0; for(int i = 0; i < n - 2; i++){ // いずれかが同じ長さであれば回避 if(take[i] == take[i + 1] || take[i + 1] == take[i + 2] || take[i] == take[i + 2]){ continue; } // 隣接する3本を1つの別の配列にする int[] takeTemp = new int[3]; takeTemp[0] = take[i]; takeTemp[1] = take[i + 1]; takeTemp[2] = take[i + 2]; // 3本を並べ替え Arrays.sort(takeTemp); // 2番目が左端か右端なら門松列 if(takeTemp[1] == take[i] || takeTemp[1] == take[i + 2]){ kadomatuCount++; } } System.out.println(kadomatuCount); } }