import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] nums = new int[n]; nums new int[n] n for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            nums[i] = Integer.parseInt(sc.next());
        } {
            nums[i] = Integer.parseInt(sc.next());
        } nums[i] = Integer.parseInt(sc.next()) nums[i] nums i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int endIndex = 2; endIndex 2 int cnt = 0; cnt 0 for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        } {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        } if (endIndex + 1 > n) break; endIndex + 1 > n endIndex + 1 endIndex 1 n break; if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            } (nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex]) (nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) nums[i] > nums[i - 1] nums[i] nums i nums[i - 1] nums i - 1 i 1 nums[i] < nums[endIndex] nums[i] nums i nums[endIndex] nums endIndex (nums[i] < nums[i - 1] && nums[i] > nums[endIndex]) nums[i] < nums[i - 1] nums[i] nums i nums[i - 1] nums i - 1 i 1 nums[i] > nums[endIndex] nums[i] nums i nums[endIndex] nums endIndex {
                cnt++;
            } cnt++ cnt endIndex++ endIndex System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(sc.next());
        }
        int endIndex = 2;
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            if (endIndex + 1 > n) break;
            if ((nums[i] > nums[i - 1] && nums[i] < nums[endIndex]) || (nums[i] < nums[i - 1] && nums[i] > nums[endIndex])) {
                cnt++;
            }
            endIndex++;
        }
        System.out.println(cnt);
    }
}
