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

using namespace std;

typedef long long ll;

int main(){

	ios::sync_with_stdio(false);

	cin.tie(nullptr);

	int l,r,d; cin>>l>>r>>d;

	int ans=0;

	for(int i=l;i<=r;i++){

		if(i%d==0) ans++;

	}

	cout<<ans<<"\n";

	return 0;

}

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



int main() {

	int l,r,d;

	scanf("%d %d %d", &l, &r, &d);

	int kelipatan = 0;

	for(int i = l; i <= r; i++){

		if ( i % d == 0){

		kelipatan ++;

			

		}

		

	}

	printf("%d", kelipatan);

	return 0;

}

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

#define forp(x,a,b) for(int x=a; x<b; x++)



using namespace std;





int main(){

    

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

     

     int l,r,d;

     cin>>l>>r>>d;

     int x=r/d-(l-1)/d;

     cout<<x;

    

    

    return 0;}

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



int main() {

	int l,r,d;

	scanf("%d %d %d", &l, &r, &d);

	int kelipatan = 0;

	for(int i = l; i <= r; i++){

		if ( i % d == 0){

		kelipatan ++;

			

		}

		

	}

	printf("%d", kelipatan);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define taskname "test"



#include <algorithm>

#include <iostream>

#include <cstdio>

#include <vector>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

using namespace std;

typedef long long lli;

typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

string s, t;

int q;



struct fenwick

{

    int val[maxn];



    void init(string&s)

    {

        fill(begin(val), end(val), 0);

        for(int i = 1; i < (int)s.size(); ++i)

        {

            int x = i;

            for(; x < maxn; x += x & -x)

                val[x] += (s[i] - 'A' + 1);

        }

    }



    int get(int x)

    {

        int res = 0;

        for(; x > 0; x -= x & -x)

            res += val[x];

        return res;

    }



    int get(int l, int r)

    {

        return get(r) - get(l - 1);

    }

} tree_s, tree_t;



void read_input()

{

    cin >> s >> t;

    s = " " + s; t = " " + t;

    cin >> q;

}



void solve()

{

    tree_s.init(s); tree_t.init(t);

    for(; q > 0; --q)

    {

        int a, b, c, d;

        cin >> a >> b >> c >> d;

        if(tree_s.get(a, b) % 3 == tree_t.get(c, d) % 3)

            cout << "YES\n";

        else cout << "NO\n";

    }

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    read_input();

    solve();

}


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



using namespace std;

const int Sz = 1e6 + 5;

int a[Sz],b[Sz];

string s, t;

int q, l, r, l2, r2;

int32_t main(){

    //freopen("inp.txt", "r", stdin);

    //freopen("out.txt", "w", stdout);

    cin >> s >> t;

    s = " " + s;

    t = " " + t;

    a[0] = 0;

    b[0] = 0;

    for(int i = 1; i < s.size(); i++){

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

        else a[i] = a[i - 1] + 2;

    }

    for(int i = 1; i < t.size(); i++){

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

        else b[i] = b[i - 1] + 2;

    }

    cin >> q;

    while(q--){

        cin >> l >> r >> l2 >> r2;

        int x = (a[r] - a[l - 1]) % 3;

        int y = (b[r2] - b[l2 - 1]) % 3;

        if(abs(x) == abs(y)) cout << "YES\n";

        else cout << "NO\n";

        //cerr << x << " " << y << "\n";

    }

    return 0;

}


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

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;

template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){

    out << "(" << o.first << "," << o.second << ")"; return out;

}



/*

<url:https://arc071.contest.atcoder.jp/tasks/arc071_c>

問題文============================================================

 A, B からなる文字列に対して、次の操作を考えます。

 

 文字列中の 1 文字を選ぶ。それが A なら BB で、 B なら AA で置き換える。

 AAA か BBB であるような部分文字列を選び、消す。

 例えば、ABA という文字列で 1 番目の操作を 1 文字目に対して行うと、 BBBA となります。

 また、BBBAAAA に対して 2 番目の操作を 4 文字目から 6 文字目に対して行うと、 BBBA となります。

 

 これらの操作を何回でも好きな順で行うことができます。

 

 文字列 S,T と q 個のクエリ ai,bi,ci,di が与えられます。

 各クエリに対して、

 S の部分文字列 SaiSai+1…Sbi を

 T の部分文字列 TciTci+1…Tdi にすることができるか判定してください。

 

 1≤|S|,|T|≤10^5

 S,T は文字A,Bからなる。

 1≤q≤10^5

 1≤ai≤bi≤|S|

 1≤ci≤di≤|T|



=================================================================



解説=============================================================

 

 SとTの部分文字列 s,t を全て B へ変形した時、

 そのBの数の差が 3 の倍数であるとき、 YESとなる。

 

 前処理で累積和を用いて、Bの数を数え上げておけば　各クエリについて O(1) で回答できる

 

================================================================

*/

void solve(){

    string S,T; cin >> S >> T;

    int Q; cin >> Q;

    vector<int> cusumS(S.length()+1,0),cusumT(T.length()+1,0);

    for(int i = 0; i < S.length();i++){

        if(S[i] == 'A') cusumS[i+1] = cusumS[i] + 2;

        else cusumS[i+1] = cusumS[i] + 1;

    }

    for(int i = 0; i < T.length();i++){

        if(T[i] == 'A') cusumT[i+1] = cusumT[i] + 2;

        else cusumT[i+1] = cusumT[i] + 1;

    }

    while(Q--){

        int a,b,c,d; cin >> a >> b >> c >> d;

        if(abs((cusumS[b]-cusumS[a-1])-(cusumT[d]-cusumT[c-1]))%3 == 0) cout << "YES" << endl;

        else cout << "NO" << endl;

    }

}

int main(void) {

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

    solve();

	return 0;

}


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

#define N 100005

char s[N],t[N];

int a,b,c,d,x[N],y[N];

inline void solve() {

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

	puts(((x[b]-x[a-1]-y[d]+y[c-1])%3+3)%3?"NO":"YES");

}

int main() {

	int Q;

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

	x[0]=y[0]=0;

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

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

	while(Q--) solve();

	return 0;

}

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

}

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

}

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

    }

}

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

    }

}  

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

}


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

    }

}  

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




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

}


// Optimized solution to the same problem (faster):




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

}


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

		}

	}

}


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

}

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

}

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

}

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


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

	

	

	}

	

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

}

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

}

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

}

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

 

 }

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

}

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

}

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

}

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

}


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

}

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

}

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

}

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

}

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

}

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

#include <vector>

#include <algorithm>



using namespace std;



int main()

{

	vector<int> v;

	int num,tmp,min = 0;

	cin >> num;

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

	{

		cin >> tmp;

		v.push_back(tmp);

	}

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

	{

		vector<int> v2 = { v[i - 1],v[i],v[i + 1] };

		sort(v2.begin(), v2.end());

		if (v2[1] == v[i])

			min++;

	}

	cout << min;

	system("pause");

	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: