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

using namespace std;

int main()

{

	int n;

	cin>>n;

	long long a[100000+5]={0};

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

		cin>>a[i];

	int num=0;

	int i=0;

	while(i<n)

	{

		if(i==n-1)

		{num++;break;}

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

		{

			int j;

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

			{

				if(a[j]<=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

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

		{

			int j;

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

			{

				if(a[j]>=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

		else if(a[i]==a[i+1])

		{

			i++;

		}

		else

		{

			num++;

			i++;

		}

	}

	cout<<num<<endl;

	return 0;

}

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



using namespace std;



int arr[100005], fault[100005];



int main(){

    int N, ans = 1, temp = 0;

    cin >> N;

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

        cin >> arr[i];

        if(i > 1){

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

                temp++;

                fault[temp] = 0;

            } else if (arr[i] < arr[i-1]){

                temp++;

                fault[temp] = 1;

            }

        }

    }

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

        if(fault[i] != fault[i+1]){

             ans++;

             i++;

        }

    }

    cout << ans << endl;

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

using namespace std;



const int N = 100000 + 10;



const int Up = 0;

const int Down = 1;



int n;

int aa[N];

int dp[N][2];



int main() {

	scanf( "%d", &n );

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

		scanf( "%d", aa + i );

	}

	memset( dp, 0x3f, sizeof(dp) );

	dp[1][Up] = dp[1][Down] = 1;

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

		dp[i][Up] = dp[i-1][Up] + (aa[i] < aa[i-1]);

		dp[i][Down] = dp[i-1][Down] + (aa[i] > aa[i-1]);

		dp[i][Up] = min( dp[i][Up], dp[i-1][Down] + 1 );

		dp[i][Down] = min( dp[i][Down], dp[i-1][Up] + 1 );

	}

	printf( "%d\n", min(dp[n][Up],dp[n][Down]) );

}




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

#include <cstring>

#include <cmath>

#include <algorithm>

#define ll long long

using namespace std;



ll arr[100005];

int memo[100005];



int main()

{

    int n;

    cin >> n;

    

    memset (memo,0,sizeof(memo));

    int ans = 1;

    int track = 2;

    //if track = 0 it means that it is increasing, track = 1 means it is decreasing track = 2 is neutral

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

        cin >> arr[i];

        if (i >= 2){

          if (track == 2 && arr[i] != arr[i-1]){

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

              track = 0;

            else

              track = 1;

          }

          else if (track != 2){

            if (arr[i] > arr [i-1] && track == 1){

              ans++;

              track = 2;

            }

            else if (arr[i] < arr [i-1] && track == 0){

              ans++;

              track = 2;

            }

          }

        }

    }

    

    

    

    cout << ans << endl;



    return 0;

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

using namespace std;

int main()

{

	int n;

	cin>>n;

	long long a[100000+5]={0};

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

		cin>>a[i];

	int num=0;

	int i=0;

	while(i<n)

	{

		if(i==n-1)

		{num++;break;}

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

		{

			int j;

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

			{

				if(a[j]<=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

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

		{

			int j;

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

			{

				if(a[j]>=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

		else if(a[i]==a[i+1])

		{

			i++;

		}

		else

		{

			num++;

			i++;

		}

	}

	cout<<num<<endl;

	return 0;

}

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

#include <cstring>

#include <cmath>

#include <algorithm>

#define ll long long

using namespace std;



ll arr[100005];

int memo[100005];



int main()

{

    int n;

    cin >> n;

    

    memset (memo,0,sizeof(memo));

    int ans = 1;

    int track = 2;

    //if track = 0 it means that it is increasing, track = 1 means it is decreasing track = 2 is neutral

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

        cin >> arr[i];

        if (i >= 2){

          if (track == 2 && arr[i] != arr[i-1]){

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

              track = 0;

            else

              track = 1;

          }

          else if (track != 2){

            if (arr[i] > arr [i-1] && track == 1){

              ans++;

              track = 2;

            }

            else if (arr[i] < arr [i-1] && track == 0){

              ans++;

              track = 2;

            }

          }

        }

    }

    

    

    

    cout << ans << endl;



    return 0;

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

using namespace std;



const int N = 100000 + 10;



const int Up = 0;

const int Down = 1;



int n;

int aa[N];

int dp[N][2];



int main() {

	scanf( "%d", &n );

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

		scanf( "%d", aa + i );

	}

	memset( dp, 0x3f, sizeof(dp) );

	dp[1][Up] = dp[1][Down] = 1;

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

		dp[i][Up] = dp[i-1][Up] + (aa[i] < aa[i-1]);

		dp[i][Down] = dp[i-1][Down] + (aa[i] > aa[i-1]);

		dp[i][Up] = min( dp[i][Up], dp[i-1][Down] + 1 );

		dp[i][Down] = min( dp[i][Down], dp[i-1][Up] + 1 );

	}

	printf( "%d\n", min(dp[n][Up],dp[n][Down]) );

}




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

using namespace std;

int n , x[200000] , pos , ans , now;

int main(){

	cin >> n;

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

		cin >> x[i];

	}

	now = 0;

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

		if(now == 0){

			if(x[i] == x[i - 1])now = 0;

			if(x[i] > x[i - 1])now = 1;

			if(x[i] < x[i - 1])now = 2;

		}

		else if(now == 1){

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

				now = 0;

				ans++;

			}

		}

		else if(now == 2){

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

				now = 0;

				ans++;

			}

		}

	}

	cout << ans + 1 << endl;

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

using namespace std;

int main()

{

	int n;

	cin>>n;

	long long a[100000+5]={0};

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

		cin>>a[i];

	int num=0;

	int i=0;

	while(i<n)

	{

		if(i==n-1)

		{num++;break;}

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

		{

			int j;

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

			{

				if(a[j]<=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

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

		{

			int j;

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

			{

				if(a[j]>=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

		else if(a[i]==a[i+1])

		{

			i++;

		}

		else

		{

			num++;

			i++;

		}

	}

	cout<<num<<endl;

	return 0;

}

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

using namespace std;

int n , x[200000] , pos , ans , now;

int main(){

	cin >> n;

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

		cin >> x[i];

	}

	now = 0;

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

		if(now == 0){

			if(x[i] == x[i - 1])now = 0;

			if(x[i] > x[i - 1])now = 1;

			if(x[i] < x[i - 1])now = 2;

		}

		else if(now == 1){

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

				now = 0;

				ans++;

			}

		}

		else if(now == 2){

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

				now = 0;

				ans++;

			}

		}

	}

	cout << ans + 1 << endl;

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

#include <cstring>

#include <cmath>

#include <algorithm>

#define ll long long

using namespace std;



ll arr[100005];

int memo[100005];



int main()

{

    int n;

    cin >> n;

    

    memset (memo,0,sizeof(memo));

    int ans = 1;

    int track = 2;

    //if track = 0 it means that it is increasing, track = 1 means it is decreasing track = 2 is neutral

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

        cin >> arr[i];

        if (i >= 2){

          if (track == 2 && arr[i] != arr[i-1]){

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

              track = 0;

            else

              track = 1;

          }

          else if (track != 2){

            if (arr[i] > arr [i-1] && track == 1){

              ans++;

              track = 2;

            }

            else if (arr[i] < arr [i-1] && track == 0){

              ans++;

              track = 2;

            }

          }

        }

    }

    

    

    

    cout << ans << endl;



    return 0;

}

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

using namespace std;

int n , x[200000] , pos , ans , now;

int main(){

	cin >> n;

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

		cin >> x[i];

	}

	now = 0;

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

		if(now == 0){

			if(x[i] == x[i - 1])now = 0;

			if(x[i] > x[i - 1])now = 1;

			if(x[i] < x[i - 1])now = 2;

		}

		else if(now == 1){

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

				now = 0;

				ans++;

			}

		}

		else if(now == 2){

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

				now = 0;

				ans++;

			}

		}

	}

	cout << ans + 1 << endl;

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

using namespace std;



const int N = 100000 + 10;



const int Up = 0;

const int Down = 1;



int n;

int aa[N];

int dp[N][2];



int main() {

	scanf( "%d", &n );

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

		scanf( "%d", aa + i );

	}

	memset( dp, 0x3f, sizeof(dp) );

	dp[1][Up] = dp[1][Down] = 1;

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

		dp[i][Up] = dp[i-1][Up] + (aa[i] < aa[i-1]);

		dp[i][Down] = dp[i-1][Down] + (aa[i] > aa[i-1]);

		dp[i][Up] = min( dp[i][Up], dp[i-1][Down] + 1 );

		dp[i][Down] = min( dp[i][Down], dp[i-1][Up] + 1 );

	}

	printf( "%d\n", min(dp[n][Up],dp[n][Down]) );

}




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

using namespace std;



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

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

#define fi first

#define se second

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define dbg(x) cout << #x << " = " << x << endl

#define F_OR(i, a, b, s) for(int i = (a); (s) > 0 ? i < (b) : i >= (b); i += (s))

#define F_OR1(e) F_OR(i, 0, e, 1)

#define F_OR2(i, e) F_OR(i, 0, e, 1)

#define F_OR3(i, b, e) F_OR(i, b, e, 1)

#define F_OR4(i, b, e, s) F_OR(i, b, e, s)

#define GET5(a, b, c, d, e, ...) e

#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)

#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define ite(i, x) for(auto& i: x)



typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vl;

typedef vector<pll> vll;

typedef vector<pii> vii;

typedef vector<string> vs;

typedef vector<bool> vb;





int main() {

    #ifdef LOCAL

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

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

    #else

        #define endl '\n'

    #endif

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n; cin >> n;

    int ans = 1;

    bool a, b;

    a = b = 0;

    int ant; cin >> ant;

    FOR(i, n - 1){

        int m; cin >> m;

        if(m > ant) a = 1;

        if(m < ant) b = 1;

        if(a && b) a = b = 0, ++ans;

        ant = m;

    }

    cout << ans << endl;

    return 0;

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

using namespace std;

int main()

{

	int n;

	cin>>n;

	long long a[100000+5]={0};

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

		cin>>a[i];

	int num=0;

	int i=0;

	while(i<n)

	{

		if(i==n-1)

		{num++;break;}

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

		{

			int j;

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

			{

				if(a[j]<=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

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

		{

			int j;

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

			{

				if(a[j]>=a[j+1])

					continue;

				else

					break;

			}

			num++;

			i=j+1;

		}

		else if(a[i]==a[i+1])

		{

			i++;

		}

		else

		{

			num++;

			i++;

		}

	}

	cout<<num<<endl;

	return 0;

}

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

using namespace std;



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

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

#define fi first

#define se second

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define dbg(x) cout << #x << " = " << x << endl

#define F_OR(i, a, b, s) for(int i = (a); (s) > 0 ? i < (b) : i >= (b); i += (s))

#define F_OR1(e) F_OR(i, 0, e, 1)

#define F_OR2(i, e) F_OR(i, 0, e, 1)

#define F_OR3(i, b, e) F_OR(i, b, e, 1)

#define F_OR4(i, b, e, s) F_OR(i, b, e, s)

#define GET5(a, b, c, d, e, ...) e

#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)

#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define ite(i, x) for(auto& i: x)



typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vl;

typedef vector<pll> vll;

typedef vector<pii> vii;

typedef vector<string> vs;

typedef vector<bool> vb;





int main() {

    #ifdef LOCAL

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

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

    #else

        #define endl '\n'

    #endif

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n; cin >> n;

    int ans = 1;

    bool a, b;

    a = b = 0;

    int ant; cin >> ant;

    FOR(i, n - 1){

        int m; cin >> m;

        if(m > ant) a = 1;

        if(m < ant) b = 1;

        if(a && b) a = b = 0, ++ans;

        ant = m;

    }

    cout << ans << endl;

    return 0;

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

#include <cstring>

#include <cmath>

#include <algorithm>

#define ll long long

using namespace std;



ll arr[100005];

int memo[100005];



int main()

{

    int n;

    cin >> n;

    

    memset (memo,0,sizeof(memo));

    int ans = 1;

    int track = 2;

    //if track = 0 it means that it is increasing, track = 1 means it is decreasing track = 2 is neutral

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

        cin >> arr[i];

        if (i >= 2){

          if (track == 2 && arr[i] != arr[i-1]){

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

              track = 0;

            else

              track = 1;

          }

          else if (track != 2){

            if (arr[i] > arr [i-1] && track == 1){

              ans++;

              track = 2;

            }

            else if (arr[i] < arr [i-1] && track == 0){

              ans++;

              track = 2;

            }

          }

        }

    }

    

    

    

    cout << ans << endl;



    return 0;

}

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

using namespace std;



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

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

#define fi first

#define se second

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define dbg(x) cout << #x << " = " << x << endl

#define F_OR(i, a, b, s) for(int i = (a); (s) > 0 ? i < (b) : i >= (b); i += (s))

#define F_OR1(e) F_OR(i, 0, e, 1)

#define F_OR2(i, e) F_OR(i, 0, e, 1)

#define F_OR3(i, b, e) F_OR(i, b, e, 1)

#define F_OR4(i, b, e, s) F_OR(i, b, e, s)

#define GET5(a, b, c, d, e, ...) e

#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)

#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

#define ite(i, x) for(auto& i: x)



typedef long long ll;

typedef long double ld;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vl;

typedef vector<pll> vll;

typedef vector<pii> vii;

typedef vector<string> vs;

typedef vector<bool> vb;





int main() {

    #ifdef LOCAL

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

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

    #else

        #define endl '\n'

    #endif

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n; cin >> n;

    int ans = 1;

    bool a, b;

    a = b = 0;

    int ant; cin >> ant;

    FOR(i, n - 1){

        int m; cin >> m;

        if(m > ant) a = 1;

        if(m < ant) b = 1;

        if(a && b) a = b = 0, ++ans;

        ant = m;

    }

    cout << ans << endl;

    return 0;

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

using namespace std;

struct node

{

    int x,note=0x3f;

}a[100005]; 

int main()

{ 

    int n,ans=1;

    cin>>n; 

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

	{

        cin>>a[i].x;

    }

    a[1].note=2;

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

	{

        if(a[i-1].note==0)

		{

            if(a[i].x>a[i-1].x) a[i].note=2,ans++;

              else a[i].note=0;

        }

		else if(a[i-1].note==1)

		{

            if(a[i].x>=a[i-1].x) a[i].note=1;

              else a[i].note=2,ans++;

        }

		else if(a[i-1].note==2)

		{

            if(a[i].x<a[i-1].x) a[i].note=0;

              else if(a[i].x==a[i-1].x) a[i].note=2;

                else a[i].note=1;

        }

    }

    cout<<ans<<endl;

    return 0;

}

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

using namespace std;

int n;

const int N=100005;

int a[N],f[N],ans=1;

int main(){

    scanf("%d",&n);

    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    f[1]=0;

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

        if(f[i-1]==1){

            if(a[i-1]>a[i]) f[i]=0,ans++;

            else f[i]=1;

        }

        else if(f[i-1]==2){

            if(a[i-1]<a[i]) f[i]=0,ans++; 

            else f[i]=2;

        }

        else{

            if(a[i-1]>a[i]) f[i]=2;

            else if(a[i-1]<a[i]) f[i]=1;

            else f[i]=0;

        }

    }

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

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

using namespace std;



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

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

#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



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

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

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 100100;



int A[MAX];



int main()

{

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

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



	int n;

	scanf("%d", &n);

	FOR (i, 0, n)

	{

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

	}



	if (n == 1)

	{

		cout<<1<<endl;

		return 0;

	}





	int res = 1;

	int t = -1;

	FOR (i, 1, n)

	{

		if (t == -1)

		{

			if (A[i] > A[i-1]) t = 0;

			if (A[i] < A[i-1]) t = 1;

		}



		if (t != -1)

		{

			if (A[i] >= A[i-1] && t == 0) continue;

			if (A[i] <= A[i-1] && t == 1) continue;



			res++;

			t = -1;

		}

	}

	cout<<res<<endl;



}


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

#include<cstring>

#include<algorithm>

typedef long long LL;

using namespace std;

#define max_n 100005

int a[max_n];

int main()

{

	int n,k=1,ans,i;

	bool sign,res=false;

	scanf("%d",&n);

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

	if(n==1)

	{

		printf("1\n");

		return 0;

	}

	ans=a[0];

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

	{

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

		if(!res)

		{

			if(a[i]>ans)

			{

				sign=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				sign=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(sign)

			{

				if(a[i]>=ans)

					ans=a[i];

				else

				{

					k++;

					ans=a[i];

					res=false;

				}

			}

			else

			{

				if(a[i]<=ans)

					ans=a[i];

				else

				{

					k++;

					ans=a[i];

					res=false;

				}

			}

		}

	}

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

	return 0;

}
// Slower C++ solution:
#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;



/*

<url:https://agc013.contest.atcoder.jp/tasks/agc013_a>

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

長さ N の配列 A が与えられます。

 A を何箇所かで切って、A の連続した部分であるようないくつかの数列に分けます。

 この時、分けられたあとの数列は全て、単調非減少または単調非増加な列になっている必要があります。

 最小で何個の数列に分ければ良いかを求めて下さい。

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



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



 先に、隣り合う値が等しい部分に関しては、処理を簡単にするために、unique等で

 削除しておくと楽

 

 あとは、順番に現在 単調増加なのか減少なのか、または確定できないのか

 といったフラグを持っておき、実際にシミュレーションしていく

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

*/

int main(void) {

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

    ll N; cin >> N;

    vector<ll> A(N); for(auto& in:A) cin >> in;

    A.erase(unique(A.begin(),A.end()),A.end());

    int mode = 0;

    int ans = 1;

    for(int i = 0 ; i < (int)A.size()-1;i++){

        if(mode == 0){

            if(A[i] < A[i+1]) mode = 1;

            else mode = -1;

        }else{

            if(mode == 1){

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

                    ans++;

                    mode = 0;

                }

            }else{

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

                    ans++;

                    mode = 0;

                }

            }

        }

    }

    cout << ans << endl;

	return 0;

}


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

#include<cstring>

#include<algorithm>

typedef long long LL;

using namespace std;

#define max_n 100005

int a[max_n];

int main()

{

	int n,k=1,ans,i;

	bool sign,res=false;

	scanf("%d",&n);

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

	if(n==1)

	{

		printf("1\n");

		return 0;

	}

	ans=a[0];

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

	{

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

		if(!res)

		{

			if(a[i]>ans)

			{

				sign=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				sign=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(sign)

			{

				if(a[i]>=ans)

					ans=a[i];

				else

				{

					k++;

					ans=a[i];

					res=false;

				}

			}

			else

			{

				if(a[i]<=ans)

					ans=a[i];

				else

				{

					k++;

					ans=a[i];

					res=false;

				}

			}

		}

	}

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

	return 0;

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

#include <cstring>

using namespace std;

int pd[100010],arr[100010];

int main()

{

    int n,m,ans=0,T=0;

    memset(pd,0,sizeof(pd));

    cin>>n;

    

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

    {

        cin>>arr[i];

    }



    T=arr[2]-arr[1];

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

        if(T==0)T=arr[i]-arr[i-1];

        if(1LL* T * (arr[i]-arr[i-1])<0){

            ans++;

            T=0;

        }

    }

    

    cout<<ans+1<<endl;

}

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

#include<iostream>

#include<algorithm>

using namespace std;

const int maxn=1e5+5;

int a[maxn]={0};

int main()

{

	int n,t=0,f=1,sum=0;

	cin>>n;

	while(n--)

	{

		long long x;

		cin>>x;

		if(t==0)

		{

			f=1;

			a[t]=x;

			t++;

		}

		else if(t==1)

		{

			if(a[t-1]==x)

				t=0;

			else if(a[t-1]<x)

				f=1;

			else if(a[t-1]>x)

				f=-1;

			a[t]=x;

			t++;

		}

		else

		{

			if(f==1)

			{

				if(a[t-1]>x)

				{

					sum++;

					t=0;

					a[t]=x;

					t++;

				}

				else

				{

					a[t]=x;

					t++;

				}

			}

			else

			{

				if(a[t-1]<x)

				{

					sum++;

					t=0;

					a[t]=x;

					t++;

				}

				else

				{

					a[t]=x;

					t++;

				}

			}

		}

	}

	cout<<sum+1<<endl;

}