import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int kadomatu = 0; int N = Integer.parseInt(reader.readLine()); String[] inputs = reader.readLine().split(" "); for (int i = 0; i < N - 2; i++) { int a = Integer.parseInt(inputs[i]); int b = Integer.parseInt(inputs[i + 1]); int c = Integer.parseInt(inputs[i + 2]); if (isKadomatu(a, b, c)) { kadomatu += 1; } } System.out.println(kadomatu); } private static boolean isKadomatu(int a, int b, int c) { if (a != b && a != c && b != c) { int middle; if (a <= b && b <= c) { middle = b; } else if (b <= a && a <= c) { middle = a; } else { middle = c; } if (middle == a || middle == c) { return true; } else { return false; } } else { return false; } } }