import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    static Scanner sc=new Scanner(in);
    public static void main(String[] args) {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.awt.*; awt.* java import java.awt.geom.*; geom.* java.awt import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
    static Scanner sc=new Scanner(in);
    public static void main(String[] args) {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    }
} Main static Scanner sc=new Scanner(in); sc new Scanner(in) public static void main(String[] args) {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    } main {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    } int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p=new int[n]; p new int[n] n for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i]=sc.nextInt();
        } {
            p[i]=sc.nextInt();
        } p[i]=sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc int ans=0; ans 0 for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++; int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++; if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++; p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1] p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) p[i] + p[i + 1] + p[i + 2] p[i] + p[i + 1] + p[i + 2] p[i] p i p[i + 1] p i + 1 i 1 p[i + 2] p i + 2 i 2 min(p[i], min(p[i + 1], p[i + 2])) min p[i] p i min(p[i + 1], p[i + 2]) min p[i + 1] p i + 1 i 1 p[i + 2] p i + 2 i 2 max(p[i], max(p[i + 1], p[i + 2])) max p[i] p i max(p[i + 1], p[i + 2]) max p[i + 1] p i + 1 i 1 p[i + 2] p i + 2 i 2 p[i + 1] p i + 1 i 1 ans++ ans out.println(ans) out.println out ans String[] args args public class Main {
    static Scanner sc=new Scanner(in);
    public static void main(String[] args) {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    }
} public class Main {
    static Scanner sc=new Scanner(in);
    public static void main(String[] args) {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    }
} Main
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    static Scanner sc=new Scanner(in);
    public static void main(String[] args) {
        int n=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ans=0;
        for (int i = 0; i < n - 2; i++)
            if (p[i] + p[i + 1] + p[i + 2] - min(p[i], min(p[i + 1], p[i + 2])) - max(p[i], max(p[i + 1], p[i + 2])) == p[i + 1])
                ans++;
            out.println(ans);
    }
}