public class No_116 { static int kadomatsu; static void countKadomatsu(int[] array, int i) { if (i + 1 >= array.length) { return; } int left = array[i - 1]; int right = array[i + 1]; int[] newArray = { array[i - 1], array[i], array[i + 1] }; for (int j = 0; j < newArray.length - 1; j++) { for (int k = j + 1; k < newArray.length; k++) { if (newArray[j] > newArray[k]) { int tmp = newArray[j]; newArray[j] = newArray[k]; newArray[k] = tmp; } } } if ((newArray[1] == left || newArray[1] == right) && (newArray[0] != newArray[1] && newArray[1] != newArray[2])) { kadomatsu++; } countKadomatsu(array, ++i); } public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int num = sc.nextInt(); int[] array = new int[num]; for (int i = 0; i < num; i++) { array[i] = sc.nextInt(); } countKadomatsu(array, 1); System.out.println(kadomatsu); sc.close(); } }