stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 8.68913862638336x):
#include<stdio.h> 

main()

{

	long long z[100005],i,j,k=0,l=0,t=0,n;

	scanf("%lld",&n);

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

	scanf("%lld",&z[i]);

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

	{

		if(k==0)

		{

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

			{

				if(z[i]!=z[j])

				{

					if(z[j]>z[i])

						k=1;

					else

						k=-1;

					i=j-1;

					break;

				}

			}

		}

		else

		{

			if(k==1&&z[i+1]<z[i])

				{l++;k=0;t=1;}

			if(k==-1&&z[i+1]>z[i])

			{	l++;k=0;t=1;}

		}

	}

	

	printf("%lld\n",l+1);

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

#include <vector>

#include <algorithm>

#include <fstream>

#include <map>

#include <set>

#include <string>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#define mod 1000000007

using namespace std;



int main()

{

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

    int n; cin >> n;

    vector<int> v(n, 0);

    int flag = 0;

    int ret = 1;

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

        cin >> v[i];

        if (i == 0) continue;

        if (flag == 1) {

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

                flag = 0;

                ++ret;

            }

        } else if (flag == -1) {

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

                flag = 0;

                ++ret;

            }

        } else {

            if (v[i] > v[i - 1]) flag = 1;

            else if (v[i] < v[i - 1]) flag = -1;

        }

    }

    cout << ret << '\n';

    return 0;

}


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

main()

{

	long long z[100005],i,j,k=0,l=0,t=0,n;

	scanf("%lld",&n);

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

	scanf("%lld",&z[i]);

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

	{

		if(k==0)

		{

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

			{

				if(z[i]!=z[j])

				{

					if(z[j]>z[i])

						k=1;

					else

						k=-1;

					i=j-1;

					break;

				}

			}

		}

		else

		{

			if(k==1&&z[i+1]<z[i])

				{l++;k=0;t=1;}

			if(k==-1&&z[i+1]>z[i])

			{	l++;k=0;t=1;}

		}

	}

	

	printf("%lld\n",l+1);

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

#include <iostream>

#include <algorithm>

#include <cstring>

#define N 200010

using namespace std;

int n, a[N];

int sgn(int x) {

	return x < 0 ? -1 : x > 0;

}

int main() {

	scanf("%d", &n);

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

	if (n == 1) {

		puts("1");

		return 0;

	}

	

	int flag;

	if (a[1] == a[2]) flag = 0;

	else flag = (a[1] < a[2] ? -1 : 1);

	int ans = 1;

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

		if (!flag || sgn(a[i - 1] - a[i]) == 0 || sgn(a[i - 1] - a[i]) == flag) {

			if (sgn(a[i - 1] - a[i])) flag = sgn(a[i - 1] - a[i]);

		}

		else {

			flag = 0;

			++ans;

		}

	}

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

}

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

main()

{

	long long z[100005],i,j,k=0,l=0,t=0,n;

	scanf("%lld",&n);

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

	scanf("%lld",&z[i]);

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

	{

		if(k==0)

		{

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

			{

				if(z[i]!=z[j])

				{

					if(z[j]>z[i])

						k=1;

					else

						k=-1;

					i=j-1;

					break;

				}

			}

		}

		else

		{

			if(k==1&&z[i+1]<z[i])

				{l++;k=0;t=1;}

			if(k==-1&&z[i+1]>z[i])

			{	l++;k=0;t=1;}

		}

	}

	

	printf("%lld\n",l+1);

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



int sign(int x) {

	return (x > 0) - (x < 0);

}



int main() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);



	int n; std::cin >> n;

	int ans = 0, t = 0, last = -1;

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

		int x; std::cin >> x;

		if (!i || (sign(x - last) * t == -1)) {

			++ ans; t = 0;

		}

		else if (!t && sign(x - last)) {

			t = sign(x - last);

		}

		last = x;

	}



	std::cout << ans << std::endl;

}

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

main()

{

	long long z[100005],i,j,k=0,l=0,t=0,n;

	scanf("%lld",&n);

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

	scanf("%lld",&z[i]);

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

	{

		if(k==0)

		{

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

			{

				if(z[i]!=z[j])

				{

					if(z[j]>z[i])

						k=1;

					else

						k=-1;

					i=j-1;

					break;

				}

			}

		}

		else

		{

			if(k==1&&z[i+1]<z[i])

				{l++;k=0;t=1;}

			if(k==-1&&z[i+1]>z[i])

			{	l++;k=0;t=1;}

		}

	}

	

	printf("%lld\n",l+1);

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

#include<vector>

using namespace std;

 

int main()

{

	int N;

	cin >> N;

	vector<int> A(N);

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

		cin >> A[i];

	}

	int f = 0, res = 1;

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

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

			if (f > 0) {

				;

			}

			else if (f < 0) {

				f = 0;

				res++;

			}

			else {

				f = 1;

			}

		}

		else if (A[i] == A[i - 1]) {

			;

		}

		else {

			if (f > 0) {

				f = 0;

				res++;

			}

			else if (f < 0) {

				;

			}

			else {

				f = -1;

			}

		}

	}

	cout << res << endl;

	return 0;

}

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

main()

{

	long long z[100005],i,j,k=0,l=0,t=0,n;

	scanf("%lld",&n);

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

	scanf("%lld",&z[i]);

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

	{

		if(k==0)

		{

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

			{

				if(z[i]!=z[j])

				{

					if(z[j]>z[i])

						k=1;

					else

						k=-1;

					i=j-1;

					break;

				}

			}

		}

		else

		{

			if(k==1&&z[i+1]<z[i])

				{l++;k=0;t=1;}

			if(k==-1&&z[i+1]>z[i])

			{	l++;k=0;t=1;}

		}

	}

	

	printf("%lld\n",l+1);

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

using namespace std;

const int N=1e5+10;

int a[N];

int main()

{

	int n;

	cin>>n;

	//vector<int> a(n);

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

	int ans=0;

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

		j=i;

		ans++;

		while(j+1<=n&&a[i]==a[j+1]) j++;

		if(j+1<=n){

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

				while(j+1<=n&&a[j]<=a[j+1]) j++;

			else

				while(j+1<=n&&a[j]>=a[j+1]) j++;

		}

	}

	cout<<ans<<endl;

	return 0;

}


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

main()

{

	long long z[100005],i,j,k=0,l=0,t=0,n;

	scanf("%lld",&n);

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

	scanf("%lld",&z[i]);

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

	{

		if(k==0)

		{

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

			{

				if(z[i]!=z[j])

				{

					if(z[j]>z[i])

						k=1;

					else

						k=-1;

					i=j-1;

					break;

				}

			}

		}

		else

		{

			if(k==1&&z[i+1]<z[i])

				{l++;k=0;t=1;}

			if(k==-1&&z[i+1]>z[i])

			{	l++;k=0;t=1;}

		}

	}

	

	printf("%lld\n",l+1);

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

using namespace std;



int main() {

    int n; cin >> n;

    int arr[n];

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



    int ans = 1, order = 0;

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

        if (order == 0) {

            if (arr[i-1] < arr[i]) order = 1;

            else if (arr[i-1] > arr[i]) order = 2;

            else order = 0;

        } else if ((order == 1 && arr[i-1] <= arr[i]) || (order == 2 && arr[i-1] >= arr[i])) {

            continue;

        } else {

            ans++;

            order = 0;

        }

    }

    cout << ans << '\n';

}
// 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.7732325706189878x):
#include <bits/stdc++.h>



#define PB          push_back

#define PF          push_front

#define MP          make_pair

#define FI          first

#define SE          second

#define SIZE( A )   int( ( A ).size( ) )

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

#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )



using namespace std;



typedef long long           ll;

typedef unsigned long long  ull;

typedef long double         lf;

typedef pair< int, int >    pii;

typedef pair< ll, ll >      pll;

typedef vector< bool >      vb;

typedef vector< lf >        vd;

typedef vector< ll >        vll;

typedef vector< int >       vi;

typedef vector< pii >       vpii;



const int MAXN = int( 2e5 );

const int MOD  = int( 360 );

const int oo   = INT_MAX;



int n;

int arr[ MAXN ];



int main( ) {



  #ifdef LOCAL

    freopen( "input", "r", stdin );

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

  #else

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

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

    ios_base::sync_with_stdio( 0 );

    cin.tie( 0 );

  #endif



  while( cin >> n ) {

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

      cin >> arr[ i ];

    }

    int ans = 0;

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

      ++ans;

      if( i+1 == n ) {

        break;

      }

      int j = i+1;

      int tp = ( arr[ i ] < arr[ j ] ? -1 : ( arr[ i ] > arr[ j ] ? 1 : 0 ) );

      while( j+1 < n ) {

        int tp2 = ( arr[ j ] < arr[ j+1 ] ? -1 : ( arr[ j ] > arr[ j+1 ] ? 1 : 0 ) );

        if( tp2 == 0 || tp == 0 || tp == tp2 ) {

          ++j;

          tp = ( tp2 != 0 ? tp2 : tp );

        } else {

          break;

        }

      }

      i = j;

    }

    cout << ans << '\n';

  }



  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.77358395412926x):
#include <bits/stdc++.h>

using namespace std;



typedef vector<int> vi;



int main() {

    int n;

    cin >> n;

    vi arr(n);

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



    int cont = 0;

    string state = "__";

    

    if(n < 3) {

        cout << "1\n";

        return 0;

    }



    /*if(arr[0] <= arr[1]) state = "CRE";

    if(arr[0] > arr[1]) state = "DCR";*/



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



        if(state == "__") {            

            if(arr[i] == arr[i+1]) continue;

            else if(arr[i] < arr[i+1])state = "CRE";

            else if(arr[i] > arr[i+1]) state = "DCR";

            continue;

        }



        if(arr[i] < arr[i+1] && state != "CRE") {

            cont++;



            state = "__";

            continue;

        }



        if(arr[i] > arr[i+1] && state != "DCR") {

            cont++;



            state = "__";

            continue;

        }



    }

    cout << cont + 1 << '\n';

    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.8095917744228056x):
#include <bits/stdc++.h>

#define x first

#define y second

#define y1 secondy1

#define rank tipa_rank

#define pb push_back

#define mp make_pair

#define pow10 tipa_pow10

#define ll long long

#define INF 1000000000

#define EPS 1e-9

#define EPS2 1e-8

#define PI acos(-1.0)

using namespace std;

const int MOD = INF + 7;

const int base = 2;

int n;

int a[100000];

vector<int> A;

int main()

{

	scanf("%d" , &n);

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

	{

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

		if(A.size() && A.back() != a[i] || !A.size())

		{

			A.push_back(a[i]);

		}

	}

	int ans = 1;

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

	{

		//cout << i << endl;

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

			ans++ , i++;

	}

	cout << ans;

}
// 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.7754876412921214x):
#include <bits/stdc++.h>



int N;

int A[110000];



int main () {

	std::ios::sync_with_stdio (0);

	std::cin >> N;

	for (int i = 0; i < N; ++i) std::cin >> A[i];

	int ord = 0, ans = 1;

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

		if (A[i] == A[i + 1]) continue;

		else if (ord == 0) {

			ord = (A[i] < A[i + 1]) ? -1 : 1;

		} else if ((ord == 1 && A[i] < A[i + 1]) || (ord == -1 && A[i] > A[i + 1])) {

			ord = 0;

			++ans;

		}

	}

	std::cout << ans << std::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.819544263049497x):
#include <bits/stdc++.h>

using namespace std;



const int N = 1e5 + 10;



int a[N];



int main(){

	int n, cnt, p, flag;

	scanf("%d",&n);

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

	if (n <= 2){

		printf("1\n");

		return 0;

	}

	cnt = 1; p = 2; flag = 0;

	if (a[p] > a[p - 1]) flag = 1;

	else if (a[p] < a[p - 1]) flag = -1;

	p++;

	while (p <= n){

		if ((a[p] > a[p - 1] && flag == -1) || (a[p] < a[p - 1] && flag == 1)){

			cnt++;

			if (n - p <= 1) break;

			p++;

			flag = 0;

			if (a[p] > a[p - 1]) flag = 1;

			else if (a[p] < a[p - 1]) flag = -1;

			p++;

		}

		else{

			if (a[p] > a[p - 1]) flag = 1;

			else if (a[p] < a[p - 1]) flag = -1;

			p++;

		}

	}

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

	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.8315313987195947x):
#include <bits/stdc++.h>

using namespace std;



const int N = 1e5 + 10;



int a[N];



int main(){

	int n, cnt, p, flag;

	scanf("%d",&n);

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

	if (n <= 2){

		printf("1\n");

		return 0;

	}

	cnt = 1; p = 2; flag = 0;

	if (a[p] > a[p - 1]) flag = 1;

	else if (a[p] < a[p - 1]) flag = -1;

	p++;

	while (p <= n){

		if ((a[p] > a[p - 1] && flag == -1) || (a[p] < a[p - 1] && flag == 1)){

			cnt++;

			if (n - p <= 1) break;

			p++;

			flag = 0;

			if (a[p] > a[p - 1]) flag = 1;

			else if (a[p] < a[p - 1]) flag = -1;

			p++;

		}

		else{

			if (a[p] > a[p - 1]) flag = 1;

			else if (a[p] < a[p - 1]) flag = -1;

			p++;

		}

	}

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

	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.776187584719869x):
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-12, PI = acos(-1);

const int N = 6e5 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;

const ll inf = 1e18;



int arr[N];



int main() {

    fastIO;

    int n, k, a;

    cin >> n;

    int ans = 1;

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

        cin >> arr[i];

    }

    int prv = arr[0], dir = 0;

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

        if(arr[i] == prv) continue;

        if(dir == 0) {

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

                dir = 1;

                prv = arr[i];

            } else if(prv - arr[i] >= 1) {

                dir = -1;

                prv = arr[i];

            } else {

                assert(0);

            }

        } else {

            if(dir == 1) {

                if(arr[i] >= prv) {

                    prv = arr[i];

                } else {

                    ++ans;

                    prv = arr[i];

                    dir = 0;

                }

            } else {

                if(arr[i] <= prv) {

                    prv = arr[i];

                } else {

                    ++ans;

                    prv = arr[i];

                    dir = 0;

                }

            }

        }

    }

    cout << ans;



    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.787889087115802x):
#include<bits/stdc++.h>

using namespace std;

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

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-12, PI = acos(-1);

const int N = 6e5 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;

const ll inf = 1e18;



int arr[N];



int main() {

    fastIO;

    int n, k, a;

    cin >> n;

    int ans = 1;

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

        cin >> arr[i];

    }

    int prv = arr[0], dir = 0;

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

        if(arr[i] == prv) continue;

        if(dir == 0) {

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

                dir = 1;

                prv = arr[i];

            } else if(prv - arr[i] >= 1) {

                dir = -1;

                prv = arr[i];

            } else {

                assert(0);

            }

        } else {

            if(dir == 1) {

                if(arr[i] >= prv) {

                    prv = arr[i];

                } else {

                    ++ans;

                    prv = arr[i];

                    dir = 0;

                }

            } else {

                if(arr[i] <= prv) {

                    prv = arr[i];

                } else {

                    ++ans;

                    prv = arr[i];

                    dir = 0;

                }

            }

        }

    }

    cout << ans;



    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.7959207301373266x):
#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;

}