
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    }
} import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    } main {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    } Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = std.nextInt(); n std.nextInt() std.nextInt std int[] p = new int[n]; p new int[n] n for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = std.nextInt();
        } {
            p[i] = std.nextInt();
        } p[i] = std.nextInt() p[i] p i std.nextInt() std.nextInt std long count = 0; count 0 for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        } {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        } PriorityQueue<Integer> pq = new PriorityQueue<>(3); pq new PriorityQueue<>(3) int left = p[i - 1]; left p[i - 1] p i - 1 i 1 int right = p[i + 1]; right p[i + 1] p i + 1 i 1 int v = p[i]; v p[i] p i pq.add(left) pq.add pq left pq.add(right) pq.add pq right pq.add(v) pq.add pq v pq.poll() pq.poll pq if (v == pq.poll()) {
                count++;
            } v == pq.poll() v pq.poll() pq.poll pq {
                count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    }
} Main

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        long count = 0;
        for (int i = 1; i < n - 1; i++) {
            PriorityQueue<Integer> pq = new PriorityQueue<>(3);
            int left = p[i - 1];
            int right = p[i + 1];
            int v = p[i];
            pq.add(left);
            pq.add(right);
            pq.add(v);
            pq.poll();
            if (v == pq.poll()) {
                count++;
            }
        }

        System.out.println(count);
    }
}
