/*Author: Satyajeet Singh, Delhi Technological University*/
    import java.io.*;
    import java.util.*;
    import java.text.*; 
    import java.lang.*;
    import java.math.*;

public class Main{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Pair> graph[];
/****************************************Solutions Begins***************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }

/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    }
/**************************************Bit Manipulation**************************************************/
    static int set(int mask,int bit){
        return (mask|(1<<bit));
    }
    static int unset(int mask,int bit){
        return (mask&(~(1<<bit)));
    }
    static int countBit(int mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    }
    static boolean checkBit(int mask,int bit){
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    }
    static void printMask(int mask){
        System.out.println(Integer.toBinaryString(mask));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    }    
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/******************************************Long Pair*************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }
    
            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }
    
            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }
    
            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }
    
            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    }
/********************************************End***********************************************************/
} import java.io.*; io.* java import java.util.*; util.* java import java.text.*; text.* java import java.lang.*; lang.* java import java.math.*; math.* java public class Main{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Pair> graph[];
/****************************************Solutions Begins***************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }

/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    }
/**************************************Bit Manipulation**************************************************/
    static int set(int mask,int bit){
        return (mask|(1<<bit));
    }
    static int unset(int mask,int bit){
        return (mask&(~(1<<bit)));
    }
    static int countBit(int mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    }
    static boolean checkBit(int mask,int bit){
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    }
    static void printMask(int mask){
        System.out.println(Integer.toBinaryString(mask));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    }    
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/******************************************Long Pair*************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }
    
            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }
    
            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }
    
            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }
    
            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    }
/********************************************End***********************************************************/
} Main /*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); out new PrintWriter(new OutputStreamWriter(System.out)) static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) static long mod=(long)1e9+7; mod (long)1e9+7 (long)1e9 7 static long mod1=998244353; mod1 998244353 static boolean sieve[]; sieve static ArrayList<Integer> primes; primes static ArrayList<Long> factorial; factorial static HashSet<Pair> graph[]; graph /****************************************Solutions Begins***************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    } main {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    } String st[]=br.readLine().split(" "); st br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n=Integer.parseInt(st[0]); n Integer.parseInt(st[0]) Integer.parseInt Integer st[0] st 0 st=br.readLine().split(" ") st br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int input[]=new int[n]; input new int[n] n for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            input[i]=Integer.parseInt(st[i]);
        } {
            input[i]=Integer.parseInt(st[i]);
        } input[i]=Integer.parseInt(st[i]) input[i] input i Integer.parseInt(st[i]) Integer.parseInt Integer st[i] st i int ans=0; ans 0 for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        } {
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        } ArrayList<Integer> list=new ArrayList<>(); list new ArrayList<>() list.add(input[i-1]) list.add list input[i-1] input i-1 i 1 list.add(input[i]) list.add list input[i] input i list.add(input[i+1]) list.add list input[i+1] input i+1 i 1 Collections.sort(list) Collections.sort Collections list if(list.get(1)==input[i]){
                ans++;
            } list.get(1)==input[i] list.get(1) list.get list 1 input[i] input i {
                ans++;
            } ans++ ans out.println(ans) out.println out ans out.flush() out.flush out out.close() out.close out String[] args args /***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    } printPrecision {
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    } DecimalFormat ft = new DecimalFormat("0.00000000000000000"); ft new DecimalFormat("0.00000000000000000") out.println(ft.format(d)) out.println out ft.format(d) ft.format ft d double d d /**************************************Bit Manipulation**************************************************/
    static int set(int mask,int bit){
        return (mask|(1<<bit));
    } set {
        return (mask|(1<<bit));
    } return (mask|(1<<bit)); (mask|(1<<bit)) mask (1<<bit) 1 bit int mask mask int bit bit static int unset(int mask,int bit){
        return (mask&(~(1<<bit)));
    } unset {
        return (mask&(~(1<<bit)));
    } return (mask&(~(1<<bit))); (mask&(~(1<<bit))) mask (~(1<<bit)) (1<<bit) 1 bit int mask mask int bit bit static int countBit(int mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    } countBit {
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    } int ans=0; ans 0 while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        } mask!=0 mask 0 {
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        } if(mask%2==1){
                ans++;
            } mask%2==1 mask%2 mask 2 1 {
                ans++;
            } ans++ ans mask/=2 mask 2 return ans; ans int mask mask static boolean checkBit(int mask,int bit){
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    } checkBit {
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    } int a=mask&(1<<bit); a mask&(1<<bit) mask (1<<bit) 1 bit if(a!=0){
            return true;
        }
        else{
            return false;
        } a!=0 a 0 {
            return true;
        } return true; true {
            return false;
        } return false; false int mask mask int bit bit static void printMask(int mask){
        System.out.println(Integer.toBinaryString(mask));
    } printMask {
        System.out.println(Integer.toBinaryString(mask));
    } System.out.println(Integer.toBinaryString(mask)) System.out.println System.out System System.out Integer.toBinaryString(mask) Integer.toBinaryString Integer mask int mask mask /******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    } Makegraph {
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    } graph=new HashSet[n] graph new HashSet[n] n for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            graph[i]=new HashSet<>();
        } {
            graph[i]=new HashSet<>();
        } graph[i]=new HashSet<>() graph[i] graph i new HashSet<>() int n n static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    } addEdge {
        graph[a].add(new Pair(b,c));
    } graph[a].add(new Pair(b,c)) graph[a].add graph[a] graph a new Pair(b,c) int a a int b b int c c /*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    } debug {
        System.out.println(Arrays.deepToString(o));
    } System.out.println(Arrays.deepToString(o)) System.out.println System.out System System.out Arrays.deepToString(o) Arrays.deepToString Arrays o Object... o o /************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    } modulo {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    } long x=1; x 1 long y=a; y a while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        } b > 0 b 0 {
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        } if(b%2 == 1){
                x=(x*y)%c;
            } b%2 == 1 b%2 b 2 1 {
                x=(x*y)%c;
            } x=(x*y)%c x (x*y)%c (x*y) x y c y = (y*y)%c y (y*y)%c (y*y) y y c b /= 2 b 2 return  x%c; x%c x c long a a long b b long c c /********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    } gcd {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    } if(x==0)
            return y; x==0 x 0 return y; y if(y==0)
            return x; y==0 y 0 return x; x long r=0 r 0 a a b; b a = (x > y) ? x : y a (x > y) ? x : y (x > y) x y x y b = (x < y) ? x : y b (x < y) ? x : y (x < y) x y x y r = b r b while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        } a % b != 0 a % b a b 0 {
            r = a % b;
            a = b;
            b = r;
        } r = a % b r a % b a b a = b a b b = r b r return r; r long x x long y y /******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    } sieveMake {
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    } sieve=new boolean[n] sieve new boolean[n] n Arrays.fill(sieve,true) Arrays.fill Arrays sieve true sieve[0]=false sieve[0] sieve 0 false sieve[1]=false sieve[1] sieve 1 false for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        } int i=2; int i=2; i 2 i*i<n i*i i i n i++ i++ i {
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        } {
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        } if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            } sieve[i] sieve i {
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            } for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                } int j=i*i; int j=i*i; j i*i i i j<n j n j+=i j+=i j i {
                    sieve[j]=false;
                } {
                    sieve[j]=false;
                } sieve[j]=false sieve[j] sieve j false primes=new ArrayList<Integer>() primes new ArrayList<Integer>() for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(sieve[i]){
                primes.add(i);
            }
        } {
            if(sieve[i]){
                primes.add(i);
            }
        } if(sieve[i]){
                primes.add(i);
            } sieve[i] sieve i {
                primes.add(i);
            } primes.add(i) primes.add primes i int n n     static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        }
    } PairComp public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        } compare {
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        } if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            } p1.u!=p2.u p1.u p1 p1.u p2.u p2 p2.u {
                return p1.u-p2.u;
            } return p1.u-p2.u; p1.u-p2.u p1.u p1 p1.u p2.u p2 p2.u {
                return p1.v-p2.v;
            } return p1.v-p2.v; p1.v-p2.v p1.v p1 p1.v p2.v p2 p2.v Pair p1 p1 Pair p2 p2 Comparator static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    } Pair int u; u int v; v int index=-1; index -1 1 public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        } Pair {
            this.u = u;
            this.v = v;
        } this.u = u this.u this this.u u this.v = v this.v this this.v v int u u int v v public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        } hashCode {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        } int hu = (int) (u ^ (u >>> 32)); hu (int) (u ^ (u >>> 32)) u (u >>> 32) u 32 int hv = (int) (v ^ (v >>> 32)); hv (int) (v ^ (v >>> 32)) v (v >>> 32) v 32 return 31 * hu + hv; 31 * hu + hv 31 * hu 31 hu hv public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        } equals {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        } Pair other = (Pair) o; other (Pair) o return u == other.u && v == other.v; u == other.u && v == other.v u == other.u u other.u other other.u v == other.v v other.v other other.v Object o o public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        } compareTo {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        } if(index!=other.index)
                return Long.compare(index, other.index); index!=other.index index other.index other other.index return Long.compare(index, other.index); Long.compare(index, other.index) Long.compare Long index other.index other other.index return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u); Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u) Long.compare(v, other.v)!=0 Long.compare(v, other.v) Long.compare Long v other.v other other.v 0 Long.compare(v, other.v) Long.compare Long v other.v other other.v Long.compare(u, other.u) Long.compare Long u other.u other other.u Pair other other public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        } toString {
            return "[u=" + u + ", v=" + v + "]";
        } return "[u=" + u + ", v=" + v + "]"; "[u=" + u + ", v=" + v + "]" v ", v=" "[u=" + u + ", v=" + v + "]" "[u=" u ", v=" v "]" Comparable     static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        }
    } PairCompL public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        } compare {
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        } long aa=p2.u-p1.u; aa p2.u-p1.u p2.u p2 p2.u p1.u p1 p1.u if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            } aa<0 aa 0 {
                return -1;
            } return -1; -1 1 if(aa>0){
                return 1;
            }
            else{
                return 0;
            } aa>0 aa 0 {
                return 1;
            } return 1; 1 {
                return 0;
            } return 0; 0 Pairl p1 p1 Pairl p2 p2 Comparator static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }
    
            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }
    
            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }
    
            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }
    
            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        } Pairl long u; u long v; v int index=-1; index -1 1 public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            } Pairl {
                this.u = u;
                this.v = v;
            } this.u = u this.u this this.u u this.v = v this.v this this.v v long u u long v v public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            } hashCode {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            } int hu = (int) (u ^ (u >>> 32)); hu (int) (u ^ (u >>> 32)) u (u >>> 32) u 32 int hv = (int) (v ^ (v >>> 32)); hv (int) (v ^ (v >>> 32)) v (v >>> 32) v 32 return 31 * hu + hv; 31 * hu + hv 31 * hu 31 hu hv public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            } equals {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            } Pair other = (Pair) o; other (Pair) o return u == other.u && v == other.v; u == other.u && v == other.v u == other.u u other.u other other.u v == other.v v other.v other other.v Object o o public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            } compareTo {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            } if(index!=other.index)
                    return Long.compare(index, other.index); index!=other.index index other.index other other.index return Long.compare(index, other.index); Long.compare(index, other.index) Long.compare Long index other.index other other.index return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u); Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u) Long.compare(v, other.v)!=0 Long.compare(v, other.v) Long.compare Long v other.v other other.v 0 Long.compare(v, other.v) Long.compare Long v other.v other other.v Long.compare(u, other.u) Long.compare Long u other.u other other.u Pair other other public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            } toString {
                return "[u=" + u + ", v=" + v + "]";
            } return "[u=" + u + ", v=" + v + "]"; "[u=" + u + ", v=" + v + "]" v ", v=" "[u=" + u + ", v=" + v + "]" "[u=" u ", v=" v "]" Comparable public class Main{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Pair> graph[];
/****************************************Solutions Begins***************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }

/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    }
/**************************************Bit Manipulation**************************************************/
    static int set(int mask,int bit){
        return (mask|(1<<bit));
    }
    static int unset(int mask,int bit){
        return (mask&(~(1<<bit)));
    }
    static int countBit(int mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    }
    static boolean checkBit(int mask,int bit){
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    }
    static void printMask(int mask){
        System.out.println(Integer.toBinaryString(mask));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    }    
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/******************************************Long Pair*************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }
    
            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }
    
            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }
    
            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }
    
            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    }
/********************************************End***********************************************************/
} public class Main{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Pair> graph[];
/****************************************Solutions Begins***************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }

/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    }
/**************************************Bit Manipulation**************************************************/
    static int set(int mask,int bit){
        return (mask|(1<<bit));
    }
    static int unset(int mask,int bit){
        return (mask&(~(1<<bit)));
    }
    static int countBit(int mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    }
    static boolean checkBit(int mask,int bit){
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    }
    static void printMask(int mask){
        System.out.println(Integer.toBinaryString(mask));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    }    
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/******************************************Long Pair*************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }
    
            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }
    
            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }
    
            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }
    
            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    }
/********************************************End***********************************************************/
} Main
/*Author: Satyajeet Singh, Delhi Technological University*/
    import java.io.*;
    import java.util.*;
    import java.text.*; 
    import java.lang.*;
    import java.math.*;

public class Main{
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Pair> graph[];
/****************************************Solutions Begins***************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        int n=Integer.parseInt(st[0]);
        st=br.readLine().split(" ");
        int input[]=new int[n];
        for(int i=0;i<n;i++){
            input[i]=Integer.parseInt(st[i]);
        }
        int ans=0;
       // debug(input);
        for(int i=1;i<n-1;i++){
            ArrayList<Integer> list=new ArrayList<>();
            list.add(input[i-1]);
            list.add(input[i]);
            list.add(input[i+1]);
            Collections.sort(list);
            if(list.get(1)==input[i]){
                ans++;
            }
        }
        out.println(ans);

/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }

/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000000000"); 
        out.println(ft.format(d));
    }
/**************************************Bit Manipulation**************************************************/
    static int set(int mask,int bit){
        return (mask|(1<<bit));
    }
    static int unset(int mask,int bit){
        return (mask&(~(1<<bit)));
    }
    static int countBit(int mask){
        int ans=0;
        while(mask!=0){
            if(mask%2==1){
                ans++;
            }
            mask/=2;
        }
        return ans;
    }
    static boolean checkBit(int mask,int bit){
        int a=mask&(1<<bit);
        if(a!=0){
            return true;
        }
        else{
            return false;
        }
    }
    static void printMask(int mask){
        System.out.println(Integer.toBinaryString(mask));
    }
/******************************************Graph*********************************************************/
    static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }
    static void addEdge(int a,int b,int c){
        graph[a].add(new Pair(b,c));
    }    
/*********************************************PAIR********************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u!=p2.u){
                return p1.u-p2.u;
            }
            else{
                return p1.v-p2.v;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/******************************************Long Pair*************************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            long aa=p2.u-p1.u;
            if(aa<0){
                return -1;
            }
            else if(aa>0){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pairl implements Comparable<Pair> {
            long u;
            long v;
            int index=-1;
            public Pairl(long u, long v) {
                this.u = u;
                this.v = v;
            }
    
            public int hashCode() {
                int hu = (int) (u ^ (u >>> 32));
                int hv = (int) (v ^ (v >>> 32));
                return 31 * hu + hv;
            }
    
            public boolean equals(Object o) {
                Pair other = (Pair) o;
                return u == other.u && v == other.v;
            }
    
            public int compareTo(Pair other) {
                if(index!=other.index)
                    return Long.compare(index, other.index);
                return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
            }
    
            public String toString() {
                return "[u=" + u + ", v=" + v + "]";
            }
        }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/************************************MODULAR EXPONENTIATION***********************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/********************************************GCD**********************************************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/******************************************SIEVE**********************************************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    }
/********************************************End***********************************************************/
}