stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

using namespace std;



int main() {

    int len=0;

    cin >> len;

    int *var = new int[len];

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

        cin >> var[i];

    }

    int flag=0;//符合条件的数量

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

        int tmp[3];

        tmp[0] = var[i-1];

        tmp[1] = var[i];

        tmp[2] = var[i+1];

        sort(tmp,tmp+3);

        if(tmp[1] == var[i]){

            flag++;

        }

    }

    cout<<flag;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<math.h>

int main()

{

	int a, b, c, d, e, f, g, h, i, p;

	scanf("%d",&a);

	int z[30];

	b = 0;

	for (i = 0; i < a; i++)scanf("%d", &z[i]);

	for (i = 0; i < a - 2; i++)

	{

		if (z[i + 1] > z[i] && z[i + 1] < z[i + 2] || z[i + 1]<z[i] && z[i + 1]>z[i + 2])b++;

	}

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





	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+10;

const int mod=1e6+3;

typedef long long ll;

#define inf 0x3f3f3f3f

#define mem(a,b) memset(a,b,sizeof(a))

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

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

#define pi acos(-1.0)

#define mid ((l+r)>>1)

#define lson rt<<1,l,mid

#define rson rt<<1|1,mid+1,r

void read(int &x)

{

	int f=1;x=0;

	char ch=getchar();

	while(ch<'0'||ch>'9')

	{

		if(ch=='-')f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();

	x*=f;

}

int a[maxn];

int main()

{

	int n;

	read(n);

	per(i,0,n)read(a[i]);

	int ans=0;

	rep(i,1,n-2)

	{

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

		ans++;

	}

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

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<math.h>

int main()

{

	int a, b, c, d, e, f, g, h, i, p;

	scanf("%d",&a);

	int z[30];

	b = 0;

	for (i = 0; i < a; i++)scanf("%d", &z[i]);

	for (i = 0; i < a - 2; i++)

	{

		if (z[i + 1] > z[i] && z[i + 1] < z[i + 2] || z[i + 1]<z[i] && z[i + 1]>z[i + 2])b++;

	}

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





	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main() {

  int n;

  cin >> n;

  int arr[n];

  for (int i = 0; i < n; ++i) cin >> arr[i];

  int cont = 0;

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

    if (arr[i] > min(arr[i-1], arr[i+1]) && arr[i] < max(arr[i-1], arr[i+1]) ) cont++;

  }

  cout << cont;

}

// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int a[100];

int main()

{

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

	int n, p;

	while (cin >> n)

	{

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

			cin >> a[i];

		int count = 0;

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

		{

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

				count++;

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

				count++;

		}

		cout << count << '\n';



	}



	return 0;

}

// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<algorithm>

using namespace std;

int main()

{

	int n,sum=0;

	cin >> n;

	long long a[21];

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

		cin >> a[i];

	for (int 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++;

	}

	cout << sum << endl;

}

// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    int n;

    cin >> n;

    int p[20];

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

        cin >> p[i];

    }

    int num = 0;

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

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

            if(p[i+1] < p[i]) {

                num++;

            }

        }

        else if (p[i-1] < p[i]) {

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

                num++;

            }

        }

    }

    cout << num;

}


// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    int n;

    cin>>n;

    int a[n];

    int cnt=0;

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

    {

        cin>>a[i];

    }



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

    {

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

        {

            cnt++;

        }

    }



    cout<<cnt;

}


// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{ int n,c=0;

  cin>>n;

  int arr[n];

   for(int i=0 ;i<n ;i++) cin>>arr[i];

    for(int i=1;i<n-1;i++) if(((arr[i]>arr[i-1])&&(arr[i]<arr[i+1]))||((arr[i]<arr[i-1])&&(arr[i]>arr[i+1]))) c++;

    cout<<c;

    return 0;

}


// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int n, a[22], c;



int main()

{

    cin >> n;

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

        cin >> a[i];

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

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

            c++;

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

            c++;

    }

    cout << c;

    return 0;

}




// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main()

{

	int n;

	cin >> n;

	int x;

	vector<int> v;

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

	{

		cin >> x;

		v.push_back(x);

	}

	int count = 0;

	int now, prev, next;

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

	{

		now = v[i];

		next = v[i + 1];

		prev = v[i - 1];



		if ((now > next && now < prev) || (now > prev && now < next))

			count++;

	}

	cout << count << endl;

}




// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



int main(){

    int n; cin >> n;

    int ar[n];

    int count = 0;

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

        cin >> ar[i];

    }

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

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

            continue;

        }else count++;

    }

    cout << count;

    return 0;

}

// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define endl "\n"

#define fore(i,x,n) for(int i=x;i<n;i++)

#define all(a) a.begin(),a.end()

#define pb push_back

#define ordenar(a) sort(all(a))

typedef long long ll;

typedef vector<int> vi;



int n;



int main(){



    cin>>n;



    vi a(n);



    fore(i,0,n) cin>>a[i];



    int cont=0;



    fore(i,1,n-1){

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

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

    }



    cout<<cont;



    return 0;

}

// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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


// Optimized solution to the same problem (faster):
#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;

  }

  

    

   

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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; 

} 

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

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

        {

            total++;

        }

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

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;





}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

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

        {

            total++;

        }

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

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#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;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

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

        {

            total++;

        }

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

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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();

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

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

        {

            total++;

        }

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

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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";

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

    int num,i,j,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

    }

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

    {

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

        {

            total++;

        }

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

        {

            total++;

        }

    }

    printf("%d",total);

    return 0;

}


// Fastest known solution for this problem: