import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { int count = Integer.parseInt(buff.readLine()); String[] box = buff.readLine().split(" "); int[] height = new int[count]; for(int i = 0; i < count; ++i){ height[i] = Integer.parseInt(box[i]); } int ans = 0; for(int i = 1; i < count-1; ++i){ int max = 0, min = 101; boolean flag = false; for(int j = -1; j < 2; ++j){ if(max == height[i+j] || min == height[i+j]){ flag = true; break; } if(max < height[i+j]){ max = height[i+j]; } if(min > height[i+j]){ min = height[i+j]; } } if(flag){ continue; } if(max != height[i-1] && min != height[i-1] || max != height[i+1] && min != height[i+1]){ ++ans; } } System.out.println(ans); } catch (NumberFormatException e) { e.getStackTrace(); } catch (IOException e) { e.getStackTrace(); } catch (Exception e) { e.getStackTrace(); } } }