stablegradients/pie-gem5-pairs huggingface dataset:
// 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.4053646014852372x):
#include<bits/stdc++.h>

using namespace std;

int a[100005];

int main()

{

	int n,k=1,anss,i;

	bool flag,ress=false;

	scanf("%d",&n);

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

	if(n==1)

	{

		printf("1\n");

		return 0;

	}

	anss=a[0];

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

	{

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

		if(!ress)

		{

			if(a[i]>anss)

			{

				flag=true;

				ress=true;

				anss=a[i];

			}

			else if(a[i]<anss)

			{

				flag=false;

				ress=true;

				anss=a[i];

			}

		}

		else

		{

			if(flag)

			{

				if(a[i]>=anss)

					anss=a[i];

				else

				{

					k++;

					anss=a[i];

					ress=false;

				}

			}

			else

			{

				if(a[i]<=anss)

					anss=a[i];

				else

				{

					k++;

					anss=a[i];

					ress=false;

				}

			}

		}

	}

	cout<<k<<endl;

	

}
// 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.4030650010499048x):
#include<iostream>

using namespace std;

long long  a[100005];

int main()

{

	int n;

	cin>>n;

	int i,j;

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

	cin>>a[i];

	int count=1;

	int flag;

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

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

			{

				if(i==n-1)

				{

				i++;

				count++;

				break;	

				}

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

				break;

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

				flag=1;

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

				flag=0;

				if(flag)

				{

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

					continue;

					else {

						count++;

						break;

					}

				}

				else {

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

					continue;

					else {

						count++;

						break;

					}

				}

			}

			cout<<count;

			return 0;

	

}
// 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 flag,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)

			{

				flag=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				flag=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(flag)

			{

				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 flag,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)

			{

				flag=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				flag=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(flag)

			{

				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: 7.327317374177359x):


#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 flag,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)

			{

				flag=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				flag=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(flag)

			{

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

}

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


#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 flag,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)

			{

				flag=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				flag=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(flag)

			{

				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;

int a[100005];

int main()

{

	int n,k=1,anss,i;

	bool flag,ress=false;

	scanf("%d",&n);

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

	if(n==1)

	{

		printf("1\n");

		return 0;

	}

	anss=a[0];

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

	{

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

		if(!ress)

		{

			if(a[i]>anss)

			{

				flag=true;

				ress=true;

				anss=a[i];

			}

			else if(a[i]<anss)

			{

				flag=false;

				ress=true;

				anss=a[i];

			}

		}

		else

		{

			if(flag)

			{

				if(a[i]>=anss)

					anss=a[i];

				else

				{

					k++;

					anss=a[i];

					ress=false;

				}

			}

			else

			{

				if(a[i]<=anss)

					anss=a[i];

				else

				{

					k++;

					anss=a[i];

					ress=false;

				}

			}

		}

	}

	cout<<k<<endl;

	

}


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


#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 flag,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)

			{

				flag=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				flag=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(flag)

			{

				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>

using namespace std;

long long  a[100005];

int main()

{

	int n;

	cin>>n;

	int i,j;

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

	cin>>a[i];

	int count=1;

	int flag;

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

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

			{

				if(i==n-1)

				{

				i++;

				count++;

				break;	

				}

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

				break;

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

				flag=1;

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

				flag=0;

				if(flag)

				{

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

					continue;

					else {

						count++;

						break;

					}

				}

				else {

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

					continue;

					else {

						count++;

						break;

					}

				}

			}

			cout<<count;

			return 0;

	

}

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


#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 flag,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)

			{

				flag=true;

				res=true;

				ans=a[i];

			}

			else if(a[i]<ans)

			{

				flag=false;

				res=true;

				ans=a[i];

			}

		}

		else

		{

			if(flag)

			{

				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.4055470753249057x):
#include<cstdio>

#include<algorithm>

#include<cstdlib>

#include<iostream>

using namespace std;

int n,ans=1,m[100066];

int main(){

	cin>>n;

	bool jia=false,jian=false,flag=false;

	for(int i=1;i<=n;i++)cin>>m[i];

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

		if(jia==false&&jian==false&&m[i]!=m[i+1]){

			if(m[i+1]>m[i])jia=true;

			else if(m[i+1]<m[i])jian=true;

		}

		if(i!=1) {

			if(m[i]==m[i-1])continue;

			else if(m[i]>m[i-1]){

				if(jia==false&&jian==true){

					ans++;jian=false;

				}

			}

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

				if(jian==false&&jia==true){

					ans++;jia=false;

				}

			}

		}

		if(jia==false&&jian==false&&m[i]!=m[i+1]){

			if(m[i+1]>m[i])jia=true;

			else if(m[i+1]<m[i])jian=true;

		}

	}

	cout<<ans;

	return 0;

}
// 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.209815375858762x):
#include <cstdio>

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	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.3277448944694905x):
#include <cstdio>

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	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: 7.324617215761013x):
#include <cstdio>

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	return 0;

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

}

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

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	return 0;

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

using namespace std;

int a[100005];

int main()

{

	int n,k=1,anss,i;

	bool flag,ress=false;

	scanf("%d",&n);

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

	if(n==1)

	{

		printf("1\n");

		return 0;

	}

	anss=a[0];

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

	{

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

		if(!ress)

		{

			if(a[i]>anss)

			{

				flag=true;

				ress=true;

				anss=a[i];

			}

			else if(a[i]<anss)

			{

				flag=false;

				ress=true;

				anss=a[i];

			}

		}

		else

		{

			if(flag)

			{

				if(a[i]>=anss)

					anss=a[i];

				else

				{

					k++;

					anss=a[i];

					ress=false;

				}

			}

			else

			{

				if(a[i]<=anss)

					anss=a[i];

				else

				{

					k++;

					anss=a[i];

					ress=false;

				}

			}

		}

	}

	cout<<k<<endl;

	

}


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

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	return 0;

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

using namespace std;

long long  a[100005];

int main()

{

	int n;

	cin>>n;

	int i,j;

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

	cin>>a[i];

	int count=1;

	int flag;

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

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

			{

				if(i==n-1)

				{

				i++;

				count++;

				break;	

				}

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

				break;

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

				flag=1;

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

				flag=0;

				if(flag)

				{

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

					continue;

					else {

						count++;

						break;

					}

				}

				else {

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

					continue;

					else {

						count++;

						break;

					}

				}

			}

			cout<<count;

			return 0;

	

}

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

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	return 0;

}