import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    }
} Main public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    } main {
        Main main = new Main();
        main.solve();
    } Main main = new Main(); main new Main() main.solve() main.solve main String[] args args public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    } solve {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    } Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))); scan new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] p = new int[n]; p new int[n] n for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            p[i] = scan.nextInt();
        } {
            p[i] = scan.nextInt();
        } p[i] = scan.nextInt() p[i] p i scan.nextInt() scan.nextInt scan long answer = 0; answer 0 for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        } int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        } {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        } int j = i + 1; j i + 1 i 1 int k = j + 1; k j + 1 j 1 if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            } p[i] < p[j] && p[j] < p[k] p[i] < p[j] p[i] p i p[j] p j p[j] < p[k] p[j] p j p[k] p k {
                answer +=1;
            } answer +=1 answer 1 if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            } p[k] < p[j] && p[j] < p[i] p[k] < p[j] p[k] p k p[j] p j p[j] < p[i] p[j] p j p[i] p i {
                answer +=1;
            } answer +=1 answer 1 System.out.println(answer) System.out.println System.out System System.out answer public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    }
} public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int[] p = new int[n];
        for (int i = 0 ; i < n; i++) {
            p[i] = scan.nextInt();
        }
        long answer = 0;
        for (int i = 0; i < n - 2; i++) {
            int j = i + 1;
            int k = j + 1;
            if (p[i] < p[j] && p[j] < p[k]) {
                answer +=1;
            }
            if (p[k] < p[j] && p[j] < p[i]) {
                answer +=1;
            }
        }
        System.out.println(answer);
    }
}
