stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

void verificar(int a,int b,int c,int &n){

    if((b<a&&b>c||b<c&&b>a))

        n++;

}

int main(){

    int n;

    int sum=0;

    

    cin >>n;

    int* arr=new int[n];

    for(int i=0;i<n;++i){

        cin>>arr[i];

    }

    for(int i=1;i<n-1;++i){

        verificar(arr[i-1],arr[i],arr[i+1],sum);

    }

    cout <<sum;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.210139920918533x):
#include <stdio.h>

int main()

{

  int r,count=0;

  scanf("%d",&r);

  int ar[r];

  for(int i=0;i<r;i++)

  {

    scanf("%d",&ar[i]);

  }

  for(int i=1;i<r-1;i++)

  {

    if(((ar[i-1]<ar[i])&&(ar[i]<ar[i+1]))||((ar[i-1]>ar[i])&&(ar[i]>ar[i+1])))

  {

    count++;

  }

  

  }

  printf("%d\n",count);

  return 0;

  }
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;



main()

{

    int n, c = 0;;

    cin >> n;

    int arr[n];

    for(int i = 0; i < n; i++){

        cin >> arr[i];

    }

    for(int i = 0; i < n - 2; i++){

        int arr1[] = {arr[i], arr[i+1], arr[i+2]};

        if(arr[i+1] != *max_element(arr1, arr1+3) && arr[i+1] != *min_element(arr1, arr1+3)){

            c++;

        }



    }

    cout << c;





}











///promy_pompom

//hello world


// Faster C++ solution for the same problem (measured speedup: 5.206376985230951x):
#include <stdio.h>

int main()

{

  int r,count=0;

  scanf("%d",&r);

  int ar[r];

  for(int i=0;i<r;i++)

  {

    scanf("%d",&ar[i]);

  }

  for(int i=1;i<r-1;i++)

  {

    if(((ar[i-1]<ar[i])&&(ar[i]<ar[i+1]))||((ar[i-1]>ar[i])&&(ar[i]>ar[i+1])))

  {

    count++;

  }

  

  }

  printf("%d\n",count);

  return 0;

  }
// Slower C++ solution:
#include <iostream> 

#include <algorithm>

using namespace std;



int n,arr[10000];

int main(){

	cin>>n;

	for(int i=0;i<n;i++){

		cin>>arr[i]; 

	} 

	int sum=0,min1,min2;

	for(int i=0;i<n-2;i++){

		min1=arr[i+1];

		int s[]={arr[i],arr[i+1],arr[i+2]};

		sort(s,s+3);

		min2=s[1];

		if(min1==min2){

			sum++; 

		}

	} 

	cout<<sum;

	return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.205822663429782x):
#include<stdio.h>

int main()

{

	int n,i,sum;

	scanf("%d",&n);

	int a[n+10];

	for(i=0;i<n;i++)

	scanf("%d",&a[i]);

	sum=0;

	for(i=1;i<n-1;i++)

	{

		if(a[i]<a[i+1]&&a[i]>a[i-1])

		sum++;

		else if(a[i]>a[i+1]&&a[i]<a[i-1])

		sum++;

	} 

	printf("%d\n",sum);

}
// Slower C++ solution:
#include <iostream> 

#include <algorithm>

using namespace std;



int n,arr[10000];

int main(){

	cin>>n;

	for(int i=0;i<n;i++){

		cin>>arr[i]; 

	} 

	int sum=0,min1,min2;

	for(int i=0;i<n-2;i++){

		min1=arr[i+1];

		int s[]={arr[i],arr[i+1],arr[i+2]};

		sort(s,s+3);

		min2=s[1];

		if(min1==min2){

			sum++; 

		}

	} 

	cout<<sum;

	return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.207316628205356x):
#include<stdio.h>

int a[30];

int main()

{

	int n,i;

	scanf("%d",&n);

	for(i=1;i<=n;i++)

	    scanf("%d",&a[i]);

	int num=0;    

	for(i=2;i<=n-1;i++)

		if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]))num++;

	printf("%d\n",num);    

 }
// Slower C++ solution:
#include <iostream> 

#include <algorithm>

using namespace std;



int n,arr[10000];

int main(){

	cin>>n;

	for(int i=0;i<n;i++){

		cin>>arr[i]; 

	} 

	int sum=0,min1,min2;

	for(int i=0;i<n-2;i++){

		min1=arr[i+1];

		int s[]={arr[i],arr[i+1],arr[i+2]};

		sort(s,s+3);

		min2=s[1];

		if(min1==min2){

			sum++; 

		}

	} 

	cout<<sum;

	return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.215990336623625x):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define PY "YES\n"    // printf(PY);

#define PN "NO\n"     // printf(PN);



int main()

{

    int n, count=0, i;

    scanf("%d", &n);

    int arr[n+5];



    for(i=1; i<=n; i++)

        scanf("%d", &arr[i]);





    for(i=2; i<n; i++)

    {

        if(arr[i]<arr[i-1] && arr[i]>arr[i+1])

            count++;

        else if(arr[i]>arr[i-1] && arr[i]<arr[i+1])

            count++;

    }



    printf("%d\n", count);



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h> 



using namespace std;



int main()

{

    int a,b,c,d;

    cin >> a;

    int x[a];

    b = 0;

    for(int i = 0;i < a;i++){

        cin >> x[i];

    }

    for(int i = 1;i < (a-1);i++){

        c = 0;

        if(x[i] > x[i+1]){

            c++;

        }

        if(x[i] > x[i-1]){

            c++;

        }

        if(c == 1){

            b++;

        }

    }

    cout <<b<<endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2232067281382575x):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define PY "YES\n"    // printf(PY);

#define PN "NO\n"     // printf(PN);



int main()

{

    int n, count=0, i;

    scanf("%d", &n);

    int arr[n+5];



    for(i=1; i<=n; i++)

        scanf("%d", &arr[i]);





    for(i=2; i<n; i++)

    {

        if(arr[i]<arr[i-1] && arr[i]>arr[i+1])

            count++;

        else if(arr[i]>arr[i-1] && arr[i]<arr[i+1])

            count++;

    }



    printf("%d\n", count);



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

int n;

cin>>n;

int vec[21];

int cont=0;

for(int i=0;i<n;i++){

	cin>>vec[i];

}

for(int i=0;i<n;i++){

	if(i!=0&&i!=n-1){

		if(vec[i]>vec[i-1]&&vec[i]<vec[i+1]||vec[i]<vec[i-1]&&vec[i]>vec[i+1])

		cont++;

	}

}

cout<<cont<<"\n";

    return(0);

}

// Faster C++ solution for the same problem (measured speedup: 5.224468552022131x):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define PY "YES\n"    // printf(PY);

#define PN "NO\n"     // printf(PN);



int main()

{

    int n, count=0, i;

    scanf("%d", &n);

    int arr[n+5];



    for(i=1; i<=n; i++)

        scanf("%d", &arr[i]);





    for(i=2; i<n; i++)

    {

        if(arr[i]<arr[i-1] && arr[i]>arr[i+1])

            count++;

        else if(arr[i]>arr[i-1] && arr[i]<arr[i+1])

            count++;

    }



    printf("%d\n", count);



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define fast_io ios::sync_with_stdio(false); cin.tie(NULL)

using namespace std;



int main(){

	fast_io;

	int t;

	cin>>t;	

	int r=0;

	int *num=new int[t];

	for(int i=0;i<t;i++){

		cin>>num[i];

		if(i>=2 && ((num[i-1]>num[i-2] && num[i-1]<num[i])||(num[i-1]<num[i-2] && num[i-1]>num[i]))){

			r++;

		}

	}

	cout<<r;

	system("pause>0");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.299224652933673x):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define PY "YES\n"    // printf(PY);

#define PN "NO\n"     // printf(PN);



int main()

{

    int n, count=0, i;

    scanf("%d", &n);

    int arr[n+5];



    for(i=1; i<=n; i++)

        scanf("%d", &arr[i]);





    for(i=2; i<n; i++)

    {

        if(arr[i]<arr[i-1] && arr[i]>arr[i+1])

            count++;

        else if(arr[i]>arr[i-1] && arr[i]<arr[i+1])

            count++;

    }



    printf("%d\n", count);



    return 0;

}
// Slower C++ solution:
#include <iostream> 

#include <algorithm>

using namespace std;



int n,arr[10000];

int main(){

	cin>>n;

	for(int i=0;i<n;i++){

		cin>>arr[i]; 

	} 

	int sum=0,min1,min2;

	for(int i=0;i<n-2;i++){

		min1=arr[i+1];

		int s[]={arr[i],arr[i+1],arr[i+2]};

		sort(s,s+3);

		min2=s[1];

		if(min1==min2){

			sum++; 

		}

	} 

	cout<<sum;

	return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.213953006109073x):
#include<stdio.h>

int main()

{

    int x;

    scanf("%d",&x);

    int a[x+10],i,j,cnt=0;

    for(i=0;i<x;i++)

    {

        scanf("%d",&a[i]);

    }

    for(i=1;i<x-1;i++)

    {

       if(a[i]>a[i-1])

       {

           if(a[i]<a[i+1])cnt++;

       }

       else if(a[i]<a[i-1])

       {

           if(a[i]>a[i+1])cnt++;

       }

    }

    printf("%d",cnt);

}
// Slower C++ solution:
#include<bits/stdc++.h> 



using namespace std;



int main()

{

    int a,b,c,d;

    cin >> a;

    int x[a];

    b = 0;

    for(int i = 0;i < a;i++){

        cin >> x[i];

    }

    for(int i = 1;i < (a-1);i++){

        c = 0;

        if(x[i] > x[i+1]){

            c++;

        }

        if(x[i] > x[i-1]){

            c++;

        }

        if(c == 1){

            b++;

        }

    }

    cout <<b<<endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.221166578950035x):
#include<stdio.h>

int main()

{

    int x;

    scanf("%d",&x);

    int a[x+10],i,j,cnt=0;

    for(i=0;i<x;i++)

    {

        scanf("%d",&a[i]);

    }

    for(i=1;i<x-1;i++)

    {

       if(a[i]>a[i-1])

       {

           if(a[i]<a[i+1])cnt++;

       }

       else if(a[i]<a[i-1])

       {

           if(a[i]>a[i+1])cnt++;

       }

    }

    printf("%d",cnt);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

int n;

cin>>n;

int vec[21];

int cont=0;

for(int i=0;i<n;i++){

	cin>>vec[i];

}

for(int i=0;i<n;i++){

	if(i!=0&&i!=n-1){

		if(vec[i]>vec[i-1]&&vec[i]<vec[i+1]||vec[i]<vec[i-1]&&vec[i]>vec[i+1])

		cont++;

	}

}

cout<<cont<<"\n";

    return(0);

}

// Faster C++ solution for the same problem (measured speedup: 5.222427909974041x):
#include<stdio.h>

int main()

{

    int x;

    scanf("%d",&x);

    int a[x+10],i,j,cnt=0;

    for(i=0;i<x;i++)

    {

        scanf("%d",&a[i]);

    }

    for(i=1;i<x-1;i++)

    {

       if(a[i]>a[i-1])

       {

           if(a[i]<a[i+1])cnt++;

       }

       else if(a[i]<a[i-1])

       {

           if(a[i]>a[i+1])cnt++;

       }

    }

    printf("%d",cnt);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define fast_io ios::sync_with_stdio(false); cin.tie(NULL)

using namespace std;



int main(){

	fast_io;

	int t;

	cin>>t;	

	int r=0;

	int *num=new int[t];

	for(int i=0;i<t;i++){

		cin>>num[i];

		if(i>=2 && ((num[i-1]>num[i-2] && num[i-1]<num[i])||(num[i-1]<num[i-2] && num[i-1]>num[i]))){

			r++;

		}

	}

	cout<<r;

	system("pause>0");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.297154811658647x):
#include<stdio.h>

int main()

{

    int x;

    scanf("%d",&x);

    int a[x+10],i,j,cnt=0;

    for(i=0;i<x;i++)

    {

        scanf("%d",&a[i]);

    }

    for(i=1;i<x-1;i++)

    {

       if(a[i]>a[i-1])

       {

           if(a[i]<a[i+1])cnt++;

       }

       else if(a[i]<a[i-1])

       {

           if(a[i]>a[i+1])cnt++;

       }

    }

    printf("%d",cnt);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main() {

	int N;

	cin>>N;

	int p[N+2];

	for(int i=1;i<=N;i++) {

		cin>>p[i];

	}

	int cnt = 0, minVal,maxVal;

	for(int i=2;i<N;i++) {

		minVal = min(min(p[i-1], p[i]), p[i+1]);

		maxVal = max(max(p[i-1], p[i]), p[i+1]);

		if(p[i] > minVal and p[i]< maxVal) cnt++;

	}

	printf("%d\n",cnt);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.1428269215832065x):
#include<cstdio>

int aa[30];

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int i;

		for(i=0;i<n;i++)

		{

			scanf("%d",&aa[i]);

		}

		int num=0;

		for(i=1;i<=n-2;i++)

		{

			if(aa[i]>aa[i-1]&&aa[i]<aa[i+1]||aa[i]<aa[i-1]&&aa[i]>aa[i+1])

			num++;

		}

		printf("%d\n",num);

		

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main() {

	int N;

	cin>>N;

	int p[N+2];

	for(int i=1;i<=N;i++) {

		cin>>p[i];

	}

	int cnt = 0, minVal,maxVal;

	for(int i=2;i<N;i++) {

		minVal = min(min(p[i-1], p[i]), p[i+1]);

		maxVal = max(max(p[i-1], p[i]), p[i+1]);

		if(p[i] > minVal and p[i]< maxVal) cnt++;

	}

	printf("%d\n",cnt);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.161892959772658x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;

#include <algorithm>

int main()

{



    vector<long int> a;

    int n;

    cin >> n;

    for (int i = 0, f; i < n; i++)

    {

        cin >> f;

        a.push_back(f);



    }

    int o = 0;

    for (int i = 1; i < n - 1; i++)

    {

        if(a[i] > a[i - 1] && a[i] < a[i + 1])

            o++;

        else if (a[i] > a[i + 1] && a[i] < a[i - 1])

            o++;

    }

    cout << o;





}

// Faster C++ solution for the same problem (measured speedup: 5.2722890455696545x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:


#include <iostream>

#include <bits/stdc++.h>

#include <stdio.h>



using namespace std;



#define loop(i, a, b) for (int i = int(a); i <= int(b) - 1; i++)

#define rloop(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)

#define scfi1(v) scanf("%d", &v)

#define scfi2(v1, v2) scanf("%d %d", &v1, &v2)

#define scfll1(v) scanf("%I64d", &v);

#define scfll2(v1, v2) scanf("%I64d %I64d", &v1, &v2)

#define sz(v) int(v.size())

#define ALL(c) c.begin(), c.end()

#define pb push_back

#define mp make_pair

#define test(x) cout << #x << " => { " << (x) << " }\n";



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<vi> vvi;

typedef vector<bool> vb;

typedef vector<pii> vp;



int n,x,cnt=0;

vi a;

int main()

{

    scfi1(n);

    loop(i ,0 , n){

        scfi1(x);

        a.pb(x);

    }

    for(int i=1;i<n-1;i++)

    {

        if((a[i]<=a[i+1] && a[i]>=a[i-1])|| (a[i]>=a[i+1] && a[i]<=a[i-1]))

            cnt++;

    }

    cout<<cnt;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.225675608514567x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define INF 1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define arr array

#define _min(a) *min_element(a.begin(), a.end());

#define _max(a) *max_element(a.begin(), a.end());

#define _sort(x) sort(x.begin(), x.end())

#define _rsort(x) sort(x.rbegin(), x.rend())

#define _reverse(x) reverse(x.begin(), x.end())

#define _debug(x) cout << #x << " = " << x << endl;

#define debug(x, y) cout << #x " = " << x << " " << #y << " = " << y << endl;

#define _lower_bound(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()

#define _upper_bound(a, x) upper_bound(a.begin(), a.end(), x) - a.begin()

typedef long long ll;

using namespace std;



void solve() {	 

	int n, cnt = 0; cin >> n;

	vector<int> a(n); for (auto &u : a) cin >> u;

	for (int i = 1; i < n - 1; ++i) {

		if (a[i] > a[i - 1] && a[i] < a[i + 1] || a[i] < a[i - 1] && a[i] > a[i + 1]) {

			++cnt;

		}

	}

	cout << cnt << endl;

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(nullptr);



    // int t; cin >> t;

    // while(t--) 

        solve();

}

// Faster C++ solution for the same problem (measured speedup: 5.331392533931045x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include<bits/stdc++.h>

int main()

{

	int n;

	std::cin>>n;

	int arr[n];

	for(int i=0;i<n;i++)

	std::cin>>arr[i];

	int j=0;

	for(int i=1;i<n-1;i++)

	{

		if(arr[i]<arr[i-1] and arr[i]>arr[i+1])

		j++;

		else if(arr[i]>arr[i-1] and arr[i]<arr[i+1])

		j++;

	}

	std::cout<<j<<"\n";

}

// Faster C++ solution for the same problem (measured speedup: 5.226296551426304x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main()  {

    int n;

    cin>>n;

    int a[n];

    

    for(int i=0; i<n;i++){

        cin>>a[i];

        }

    int c=0;

    for(int i=1; i<n-1;i++){

        if((a[i]<a[i-1]&&a[i]>a[i+1])||(a[i]>a[i-1] && a[i]<a[i+1]))

            c++;

        }

        cout<<c;

}

// Faster C++ solution for the same problem (measured speedup: 5.2163804100114906x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;



using std::vector;



int main()

{

    int n;

    cin >> n;



    vector<int> numbers(n);



    for (int i = 0; i < n; i++)

    {

        cin >> numbers[i];

    }



    int count = 0;

    for (int i = 0; i < n-2; i++)

    {

        if((numbers[i] < numbers[i+1] && numbers[i+1] < numbers[i+2]) || (numbers[i] > numbers[i+1] && numbers[i+1] > numbers[i+2]))

        {

            count++;

        }

    }



    cout << count << endl;





    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.233265670652751x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

void debug() {cout<<endl;}

template<typename T,typename... Args>

void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}

#define forn(i,a,b) for(int i=a;i<b;++i)

#define SZ(x) int(x.size())

#define pb push_back

#define F first

#define S second

#define endl "\n"

typedef long long ll;

typedef pair<int, int> pii;



int main() {

    ios::sync_with_stdio(0); cin.tie(0);

    int n;

    cin >> n;

    int v[n];

    forn(i, 0, n) {

        cin >> v[i];

    }

    int ans = 0;

    forn(i, 1, n-1) {

        int aux[3] = {v[i-1], v[i], v[i+1]};

        sort(aux, aux+3);

        if (v[i] == aux[1]) ans++;

    }

    cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.295823821218735x):
#include<stdio.h>

int main()

{

    int n,i,j,k,c=0;

    scanf("%d", &n);

    int s[n+5];

    for(i=0;i<n;i++)

    {

        scanf("%d", &s[i]);

    }

    for(i=1;i<n-1;i++)

    {

        if(s[i-1]<s[i])

        {

            if(s[i]<s[i+1])

                c++;

        }

        else if(s[i-1]>s[i])

        {

            if(s[i]>s[i+1])

                c++;

        }

    }

    printf("%d\n", c);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main() {

	int N;

	cin>>N;

	int p[N+2];

	for(int i=1;i<=N;i++) {

		cin>>p[i];

	}

	int cnt = 0, minVal,maxVal;

	for(int i=2;i<N;i++) {

		minVal = min(min(p[i-1], p[i]), p[i+1]);

		maxVal = max(max(p[i-1], p[i]), p[i+1]);

		if(p[i] > minVal and p[i]< maxVal) cnt++;

	}

	printf("%d\n",cnt);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.172633970758361x):
#include<stdio.h>



int main()

{

    int i,j,a[30],n,temp=0;



    scanf("%d",&n);



    for(i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

    }



    for(i=1;i<n-1;i++)

    {

        if(a[i-1]<a[i] && a[i]<a[i+1])

            temp++;



        else if(a[i-1]>a[i] && a[i]>a[i+1])

            temp++;

    }



    printf("%d",temp);



    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>



using namespace std;

#include <algorithm>

int main()

{



    vector<long int> a;

    int n;

    cin >> n;

    for (int i = 0, f; i < n; i++)

    {

        cin >> f;

        a.push_back(f);



    }

    int o = 0;

    for (int i = 1; i < n - 1; i++)

    {

        if(a[i] > a[i - 1] && a[i] < a[i + 1])

            o++;

        else if (a[i] > a[i + 1] && a[i] < a[i - 1])

            o++;

    }

    cout << o;





}

// Faster C++ solution for the same problem (measured speedup: 5.283259771812834x):
#include<stdio.h>



int main()

{

    int i,j,a[30],n,temp=0;



    scanf("%d",&n);



    for(i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

    }



    for(i=1;i<n-1;i++)

    {

        if(a[i-1]<a[i] && a[i]<a[i+1])

            temp++;



        else if(a[i-1]>a[i] && a[i]>a[i+1])

            temp++;

    }



    printf("%d",temp);



    return 0;

}
// Slower C++ solution:


#include <iostream>

#include <bits/stdc++.h>

#include <stdio.h>



using namespace std;



#define loop(i, a, b) for (int i = int(a); i <= int(b) - 1; i++)

#define rloop(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)

#define scfi1(v) scanf("%d", &v)

#define scfi2(v1, v2) scanf("%d %d", &v1, &v2)

#define scfll1(v) scanf("%I64d", &v);

#define scfll2(v1, v2) scanf("%I64d %I64d", &v1, &v2)

#define sz(v) int(v.size())

#define ALL(c) c.begin(), c.end()

#define pb push_back

#define mp make_pair

#define test(x) cout << #x << " => { " << (x) << " }\n";



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<vi> vvi;

typedef vector<bool> vb;

typedef vector<pii> vp;



int n,x,cnt=0;

vi a;

int main()

{

    scfi1(n);

    loop(i ,0 , n){

        scfi1(x);

        a.pb(x);

    }

    for(int i=1;i<n-1;i++)

    {

        if((a[i]<=a[i+1] && a[i]>=a[i-1])|| (a[i]>=a[i+1] && a[i]<=a[i-1]))

            cnt++;

    }

    cout<<cnt;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.236549340216521x):
#include<stdio.h>



int main()

{

    int i,j,a[30],n,temp=0;



    scanf("%d",&n);



    for(i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

    }



    for(i=1;i<n-1;i++)

    {

        if(a[i-1]<a[i] && a[i]<a[i+1])

            temp++;



        else if(a[i-1]>a[i] && a[i]>a[i+1])

            temp++;

    }



    printf("%d",temp);



    return 0;

}