stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>



using namespace std;



int main(void){

    string S;

    string T;

    int N;



    cin >> S >> T;

    cin >> N;



    int s_s = 0;

    int s_e = 0;

    int t_s = 0;

    int t_e = 0;



    int s_a = 0;

    int S_asum[1000000+1];

    S_asum[0] = 0;

    for(int j=1;j<=S.length();j++){

        /*if(S[j-1] == 'A'){

            s_a++;

        }

        S_asum[j] = s_a;

        */

        S_asum[j] = S_asum[j-1] + S[j -1] - 'A' + 1;

    }

    int t_a = 0;

    int T_asum[1000000+1];

    T_asum[0] = 0;

    for(int j=1;j<=T.length();j++){

        /*

        if(T[j-1] == 'A'){

            t_a++;

        }

        T_asum[j] = t_a;

        */

        T_asum[j] = T_asum[j-1] + T[j -1] - 'A' + 1;

    }

    S_asum[0] = 0;

    T_asum[0] = 0;



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



        cin >> s_s >> s_e >> t_s >> t_e;

        int s_tmp = 0;

        int t_tmp = 0;



        s_tmp = S_asum[s_e] - S_asum[s_s-1];

        t_tmp = T_asum[t_e] - T_asum[t_s-1];



        string ans = "NO";

        if(s_tmp % 3 == t_tmp % 3){

            ans = "YES";

        }

        cout << ans << endl;

    }

    return 0;

}

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

#include <algorithm>

#include <bits/stdc++.h>



using namespace std;



int main(void){

    string S;

    string T;

    int N;



    cin >> S >> T;

    

    cin >> N;



    int s_s, s_e, t_s, t_e;



    int S_asum[100005];

    S_asum[0] = 0;

    for(int j=1;j<=S.length();j++){

        S_asum[j] = (S_asum[j-1] + S[j -1] - 'A' + 1) % 3;

    }

    int T_asum[100005];

    T_asum[0] = 0;

    for(int j=1;j<=T.length();j++){

        T_asum[j] = (T_asum[j-1] + T[j -1] - 'A' + 1) % 3;

    }



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



        /*cin >> s_s >> s_e >> t_s >> t_e;*/

        scanf("%d%d%d%d", &s_s, &s_e, &t_s, &t_e);



        int s_tmp = 0;

        int t_tmp = 0;



        s_tmp = S_asum[s_e] - S_asum[s_s-1] + 3;

        t_tmp = T_asum[t_e] - T_asum[t_s-1] + 3;



        /*string ans = "NO";*/

        if((s_tmp - t_tmp) % 3 == 0){

            /*ans = "YES";*/

            printf("YES\n");

        }

        else{printf("NO\n");}

        /*cout << ans << endl;*/

    }

    return 0;

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

#include <algorithm>



using namespace std;



int main(void){

    string S;

    string T;

    int N;



    cin >> S >> T;

    cin >> N;



    int s_s = 0;

    int s_e = 0;

    int t_s = 0;

    int t_e = 0;



    int s_a = 0;

    int S_asum[1000000+1];

    S_asum[0] = 0;

    for(int j=1;j<=S.length();j++){

        /*if(S[j-1] == 'A'){

            s_a++;

        }

        S_asum[j] = s_a;

        */

        S_asum[j] = S_asum[j-1] + S[j -1] - 'A' + 1;

    }

    int t_a = 0;

    int T_asum[1000000+1];

    T_asum[0] = 0;

    for(int j=1;j<=T.length();j++){

        /*

        if(T[j-1] == 'A'){

            t_a++;

        }

        T_asum[j] = t_a;

        */

        T_asum[j] = T_asum[j-1] + T[j -1] - 'A' + 1;

    }

    S_asum[0] = 0;

    T_asum[0] = 0;



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



        cin >> s_s >> s_e >> t_s >> t_e;

        int s_tmp = 0;

        int t_tmp = 0;



        s_tmp = S_asum[s_e] - S_asum[s_s-1];

        t_tmp = T_asum[t_e] - T_asum[t_s-1];



        string ans = "NO";

        if(s_tmp % 3 == t_tmp % 3){

            ans = "YES";

        }

        cout << ans << endl;

    }

    return 0;

}

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

#include <algorithm>

#include <bits/stdc++.h>



using namespace std;



int main(void){

    string S;

    string T;

    int N;



    cin >> S >> T;

    

    cin >> N;



    int s_s, s_e, t_s, t_e;



    int S_asum[100005];

    S_asum[0] = 0;

    for(int j=1;j<=S.length();j++){

        S_asum[j] = (S_asum[j-1] + S[j -1] - 'A' + 1) % 3;

    }

    int T_asum[100005];

    T_asum[0] = 0;

    for(int j=1;j<=T.length();j++){

        T_asum[j] = (T_asum[j-1] + T[j -1] - 'A' + 1) % 3;

    }



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



        cin >> s_s >> s_e >> t_s >> t_e;

        /*scanf("%d%d%d%d", &s_s, &s_e, &t_s, &t_e);*/



        int s_tmp = 0;

        int t_tmp = 0;



        s_tmp = S_asum[s_e] - S_asum[s_s-1] + 3;

        t_tmp = T_asum[t_e] - T_asum[t_s-1] + 3;



        /*string ans = "NO";*/

        if((s_tmp - t_tmp) % 3 == 0){

            /*ans = "YES";*/

            printf("YES\n");

        }

        else{printf("NO\n");}

        /*cout << ans << endl;*/

    }

    return 0;

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

#include <algorithm>



using namespace std;



int main(void){

    string S;

    string T;

    int N;



    cin >> S >> T;

    cin >> N;



    int s_s = 0;

    int s_e = 0;

    int t_s = 0;

    int t_e = 0;



    int s_a = 0;

    int S_asum[1000000+1];

    S_asum[0] = 0;

    for(int j=1;j<=S.length();j++){

        /*if(S[j-1] == 'A'){

            s_a++;

        }

        S_asum[j] = s_a;

        */

        S_asum[j] = S_asum[j-1] + S[j -1] - 'A' + 1;

    }

    int t_a = 0;

    int T_asum[1000000+1];

    T_asum[0] = 0;

    for(int j=1;j<=T.length();j++){

        /*

        if(T[j-1] == 'A'){

            t_a++;

        }

        T_asum[j] = t_a;

        */

        T_asum[j] = T_asum[j-1] + T[j -1] - 'A' + 1;

    }

    S_asum[0] = 0;

    T_asum[0] = 0;



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



        cin >> s_s >> s_e >> t_s >> t_e;

        int s_tmp = 0;

        int t_tmp = 0;



        s_tmp = S_asum[s_e] - S_asum[s_s-1];

        t_tmp = T_asum[t_e] - T_asum[t_s-1];



        string ans = "NO";

        if(s_tmp % 3 == t_tmp % 3){

            ans = "YES";

        }

        cout << ans << endl;

    }

    return 0;

}

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

#include <algorithm>

#include <bits/stdc++.h>



using namespace std;



int main(void){

    string S;

    string T;

    int N;



    cin >> S >> T;

    

    cin >> N;



    int s_s, s_e, t_s, t_e;



    int S_asum[100005];

    S_asum[0] = 0;

    for(int j=1;j<=S.length();j++){

        S_asum[j] = (S_asum[j-1] + S[j -1] - 'A' + 1) % 3;

    }

    int T_asum[100005];

    T_asum[0] = 0;

    for(int j=1;j<=T.length();j++){

        T_asum[j] = (T_asum[j-1] + T[j -1] - 'A' + 1) % 3;

    }



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



        /*cin >> s_s >> s_e >> t_s >> t_e;*/

        scanf("%d%d%d%d", &s_s, &s_e, &t_s, &t_e);



        int s_tmp = 0;

        int t_tmp = 0;



        s_tmp = S_asum[s_e] - S_asum[s_s-1] + 3;

        t_tmp = T_asum[t_e] - T_asum[t_s-1] + 3;



        string ans = "NO";

        if((s_tmp - t_tmp) % 3 == 0){

            ans = "YES";

        }

        cout << ans << endl;

    }

    return 0;

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



using namespace std;



int mod3sum(int a, int b){

    int ans = (a+b)%3;

    if(ans < 0){ans+=3;}

    return ans;

}

int main(){

    string S, T;

    cin >> S >> T;

    int s[S.size()+1], t[T.size()+1]; //how many more A than B

    int queries;

    cin >> queries;

    s[0] = 0;

    t[0] = 0;

    for(int one = 0; one < S.size(); one++){

        if(S[one] == 'A'){s[one+1] = mod3sum(s[one], 1);}

        else{s[one+1] = mod3sum(s[one], -1);}

    }

    for(int one = 0; one < T.size(); one++){

        if(T[one] == 'A'){t[one+1] = mod3sum(t[one], 1);}

        else{t[one+1] = mod3sum(t[one], -1);}

    }



    for(int one = 0; one < queries; one++){

        int s1, s2, t1, t2;

        cin >> s1 >> s2 >> t1 >> t2;

        int sval = mod3sum(s[s2], -s[s1-1]);

        int tval = mod3sum(t[t2], -t[t1-1]);

        if(sval == tval){cout << "YES" << endl;}

        else{cout << "NO" << endl;}

    }

}

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

using namespace std;

char s1[100005],s2[100005];

int q,cnt1[100005],cnt2[100005];

int main(){

    scanf("%s%s%d",s1+1,s2+1,&q);

    for(int i=1;s1[i];++i)

        cnt1[i]=cnt1[i-1]+s1[i]-'A'+1;

    for(int i=1;s2[i];++i)

        cnt2[i]=cnt2[i-1]+s2[i]-'A'+1;

    while(q--){

    	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);

        if((cnt1[b]-cnt1[a-1])%3==(cnt2[d]-cnt2[c-1])%3) puts("YES");

        else puts("NO");

    }

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

#include<cstdio> 

char s[100005],t[100005];  

int sp[100005],tp[100005],q,a,b,c,d,i;  

int main(){  

    scanf("%s%s%d",s+1,t+1,&q);  

    for(i=1;s[i];++i)  sp[i]=sp[i-1]+s[i]-'A'+1;  

    for(i=1;t[i];++i)  tp[i]=tp[i-1]+t[i]-'A'+1;  

    while(q--){  

        scanf("%d%d%d%d",&a,&b,&c,&d);

        if((sp[b]-sp[a-1])%3==(tp[d]-tp[c-1])%3) printf("YES\n");

        else printf("NO\n");

    }

    return 0;

}


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

using namespace std;

char s1[100005],s2[100005];

int q,cnt1[100005],cnt2[100005];

int main(){

    scanf("%s%s%d",s1+1,s2+1,&q);

    for(int i=1;s1[i];++i)

        cnt1[i]=cnt1[i-1]+s1[i]-'A'+1;

    for(int i=1;s2[i];++i)

        cnt2[i]=cnt2[i-1]+s2[i]-'A'+1;

    while(q--){

    	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);

        if((cnt1[b]-cnt1[a-1])%3==(cnt2[d]-cnt2[c-1])%3) puts("YES");

        else puts("NO");

    }

}
// Slower C++ solution:




#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<math.h>

#include<stack>

#include<queue>

#include<vector>

#include<algorithm>

#include<string>

#include<iostream>

using namespace std;









int main() {

    char s[100005],t[100005];

    int q;

    scanf("%s %s",s,t);

    scanf("%d",&q);

    int ss[100005],tt[100005];

    ss[0]=0;

    tt[0]=0;

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

        if(s[i]=='A')ss[i+1]=ss[i]+1;

        else ss[i+1]=ss[i]+2;

    }

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

        if(t[i]=='A')tt[i+1]=tt[i]+1;

        else tt[i+1]=tt[i]+2;

    }

    

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

        int a,b,c,d;

        scanf("%d %d %d %d",&a,&b,&c,&d);

        if((399999+(ss[b]-ss[a-1])-(tt[d]-tt[c-1]))%3==0)printf("YES\n");

        else printf("NO\n");

    }

    

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8178978582792211x):




#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<math.h>

#include<stack>

#include<queue>

#include<vector>

#include<algorithm>

#include<string>

#include<iostream>

using namespace std;









int main() {

    char s[100005],t[100005];

    int q;

    scanf("%s %s",s,t);

    int ss[100005],tt[100005];

    ss[0]=0;

    tt[0]=0;

    int las=strlen(s),lat=strlen(t);

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

        if(s[i]=='A')ss[i+1]=ss[i]+1;

        else ss[i+1]=ss[i]+2;

    }

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

        if(t[i]=='A')tt[i+1]=tt[i]+1;

        else tt[i+1]=tt[i]+2;

    }

    

    scanf("%d",&q);

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

        int a,b,c,d;

        scanf("%d %d %d %d",&a,&b,&c,&d);

        if((399999+(ss[b]-ss[a-1])-(tt[d]-tt[c-1]))%3==0)printf("YES\n");

        else printf("NO\n");

    }

    

    return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef long double ld; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



int dp1[100001];

int dp2[100001];



int sum1(int l, int r)

{

	if(l==0) return dp1[r];

	else return dp1[r]-dp1[l-1];

}



int sum2(int l, int r)

{

	if(l==0) return dp2[r];

	else return dp2[r]-dp2[l-1];

}





int main()

{

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

	string s, t;

	cin>>s>>t;

	int q; cin>>q;

	int n = s.length(); int m = t.length();

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

	{

		if(s[i]=='A') dp1[i]=1;

		else dp1[i]=-1;

		if(i>0) dp1[i]+=dp1[i-1];

	}

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

	{

		if(t[i]=='A') dp2[i]=1;

		else dp2[i]=-1;

		if(i>0) dp2[i]+=dp2[i-1];

	}

	while(q--)

	{

		int l1,r1,l2,r2;

		cin>>l1>>r1>>l2>>r2;

		l1--;r1--;l2--;r2--;

		int s1 = sum1(l1,r1);

		int s2 = sum2(l2,r2);

		s1-=s2;

		if(s1<0) s1=-s1;

		if(s1%3==0)

		{

			cout<<"YES\n";

		}

		else

		{

			cout<<"NO\n";

		}

	}

}


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

#include<cstring>

const int maxl=1e5+5;

char s[maxl],t[maxl];

int S[maxl],T[maxl];

int main(){

	scanf("%s",s+1);scanf("%s",t+1);

	int q,a,b,c,d;scanf("%d",&q);

	for(int i=1;s[i];i++)S[i]=S[i-1]+s[i]-'A'+1;  

    for(int i=1;t[i];i++)T[i]=T[i-1]+t[i]-'A'+1;  

    while(q--)

        scanf("%d%d%d%d",&a,&b,&c,&d),

		puts(((S[b]-S[a-1])%3==(T[d]-T[c-1])%3)?"YES":"NO");

	return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef long double ld; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



int dp1[100001];

int dp2[100001];



int sum1(int l, int r)

{

	if(l==0) return dp1[r];

	else return dp1[r]-dp1[l-1];

}



int sum2(int l, int r)

{

	if(l==0) return dp2[r];

	else return dp2[r]-dp2[l-1];

}





int main()

{

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

	string s, t;

	cin>>s>>t;

	int q; cin>>q;

	int n = s.length(); int m = t.length();

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

	{

		if(s[i]=='A') dp1[i]=1;

		else dp1[i]=-1;

		if(i>0) dp1[i]+=dp1[i-1];

	}

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

	{

		if(t[i]=='A') dp2[i]=1;

		else dp2[i]=-1;

		if(i>0) dp2[i]+=dp2[i-1];

	}

	while(q--)

	{

		int l1,r1,l2,r2;

		cin>>l1>>r1>>l2>>r2;

		l1--;r1--;l2--;r2--;

		int s1 = sum1(l1,r1);

		int s2 = sum2(l2,r2);

		s1-=s2;

		if(s1<0) s1=-s1;

		if(s1%3==0)

		{

			cout<<"YES\n";

		}

		else

		{

			cout<<"NO\n";

		}

	}

}


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

#include <string.h>

#define R register

#define MN 100005

int n,m,q,x,y,xx,yy,aa[MN],bb[MN];

char a[MN],b[MN];

inline int read(){

	R int x; R bool f; R char c;

	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');

	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));

	return f?-x:x;

}

int main(){

	scanf("%s%s",a+1,b+1);

	n=strlen(a+1),m=strlen(b+1);

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

		aa[i]=a[i]-'A'+aa[i-1]+1;

	for (R int i=1; i<=m; ++i)

		bb[i]=b[i]-'A'+bb[i-1]+1;

	q=read();while(q--){

		x=read(),y=read(),xx=read(),yy=read();

		(aa[y]-aa[x-1])%3==(bb[yy]-bb[xx-1])%3?

			puts("YES"):puts("NO");

	}return 0;

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

using namespace std;

typedef long long ll;

int P[21];

int main()

{

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

	ll n;

	cin >> n;

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

	{

		cin >> P[i];

	}

	int sum = 0;

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

	{

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

		{

			sum++;

		}

	}

	cout << sum << '\n';

	return 0;

}

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

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

            count++;

    }



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



    return 0;

}
// Slower C++ solution:


#include<bits/stdc++.h>

#include<iostream>

using namespace std;

int a[25],b[5];

int main()

{

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

	memset(a,0,sizeof(a));

	int n,sum=0;

	cin>>n;

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

	{

		cin>>a[i];

	}

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

	{

		b[0]=a[i-1];b[1]=a[i];b[2]=a[i+1];

		sort(b,b+3);

		if(b[1]==a[i])sum++; 	

	}

	cout<<sum;

	

	

	}

	

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

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

            count++;

    }



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



    return 0;

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

using namespace std;

#define INS(x) x.begin(),x.end()

int a[25];

int main()

{

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

    int n;

    cin>>n;

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

        cin>>a[i];

    vector<int> b;

    int ans=0;

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

    {

        b.clear();

        for (int j=0;j<3;j++)

            b.push_back(a[i+j]);

        sort(INS(b));

        if (a[i]!=a[i+1]&&a[i+1]!=a[i+2]&&a[i+1]==b[1]) ans++;

    }

    cout<<ans<<'\n'; 

    return 0;

}

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

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

            count++;

    }



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



    return 0;

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

#include<cstring>

#include<cstdio>

#include<cstdlib>

#include<map>

#include<ctime>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<stack>

#include<vector>

#include<bitset>

#include<string>

#define ll long long 

#define ull unsigned long long 

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

#define rint register int 

#define rll register long long 

#define rull register unsigned long long 

#define rchar register char

#define rstring register string 

#define rfloat register float

#define rdouble register double 

#define fio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

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

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

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

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

#define lFor(i,a,b) for(ll i=a;i<b;i++)

#define lFOR(i,a,b) for(ll i=a;i<=b;i++)

#define lcFor(i,a,b) for(ll i=a;i>b;i--)

#define lcFOR(i,a,b) for(ll i=a;i>=b;i--)

using namespace std;

int main()

{

   int a[25],b[3];

   int n,ans=0;

   cin>>n;

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

 {

  cin>>a[i];

 }

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

 {

 b[0]=a[i-1];

 b[1]=a[i];

 b[2]=a[i+1];

  sort(b,b+3);

  if(b[1]==a[i])

  {

  	ans++; 

  }

     

 }

 cout<<ans;

 

 }

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

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

            count++;

    }



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



    return 0;

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



using namespace std;





int main()

{

  int t;cin>>t;

  int arra[t];

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

  {

      cin>>arra[i];

  }

  int cnt=0;

  for(int j=1;j<t-1;j++)

  {

     if((arra[j-1]<arra[j] && arra[j]<arra[j+1])||(arra[j-1]>arra[j] && arra[j]>arra[j+1])) cnt++;

  }

    cout<<cnt<<endl;

}

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

        if((P[i-1]<=P[i] && P[i]<P[i+1]) || (P[i-1]>P[i] && P[i]>=P[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 a[n];

    int counter=0;

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

    cin>>a[i];

}

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

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

        counter=counter+1;

    }

}

cout<<counter<<endl;

}


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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

        if((P[i-1]<=P[i] && P[i]<P[i+1]) || (P[i-1]>P[i] && P[i]>=P[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 n,s=0;

	cin>>n;

	int p[n];

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

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

	cout<<s;

	return 0;

}

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

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

            count++;

    }



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



    return 0;

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

using namespace std;

vector <int> numbers;

bool condition(int i){

	int max=numbers[i-1], min=max;

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

		if(numbers[j]>max) max = numbers[j];

		if(numbers[j]<min) min = numbers[j];

	}

	if (numbers[i] == min || numbers[i] == max) return false;

	return true; 

}



int main(){

	int n, x, cont=0;

	cin >> n;

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

		cin >>x;

		numbers.push_back(x);

	}

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

		if (condition(i)) cont++;

	}

	cout << cont;

	return 0;

}

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



int main()

{

    int n, i, count=0;



    scanf("%d", &n);



    int P[n+1];



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

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

    }



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

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

            count++;

    }



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



    return 0;

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

using namespace std;

typedef long long ll;

int P[21];

int main()

{

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

	ll n;

	cin >> n;

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

	{

		cin >> P[i];

	}

	int sum = 0;

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

	{

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

		{

			sum++;

		}

	}

	cout << sum << '\n';

	return 0;

}

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

int main()

{

    int k;

    scanf("%d",&k);

    int a[k+10],i,count=0;

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

    {

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

    }

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

    {

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

       {

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

       }

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

       {

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

       }

    }

    printf("%d",count);

    return 0;

}