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

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <string>

#include <iostream>

#include <algorithm>

#include <queue>

#include <map>



using namespace std;



typedef long long ll;

const int Maxn = 1e9 + 10;

const int N = 1e5 + 10;

const int INF=(0x7fffffff)/2;

int dp[105][305];

int n, W;

int w[105], v[105];

int d, ans=0;

int main(){

	int i, j, k;

	while(~scanf("%d%d",&n,&W)){

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

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

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

			for(j = 0; j <= 300; j++)

				dp[i][j]=0;

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

			for(j = n; j > 0; j--)

				for(k = 300; k >= 0; k--){

				d = w[i] - w[1];

				if(k < d)

					break;

				dp[j][k] = max(dp[j][k], dp[j-1][k-d] + v[i]);

				}

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

			for(j = 0; j <= 300; j++)

				if(1ll * i * w[1] + 1ll * j <= 1ll * W)

					ans = max(ans, dp[i][j]);

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

	}

	return 0;

}

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

#include <cstring>

#include <cmath>

#include <algorithm>

using namespace std;

typedef long long LL;

struct huowu

{

	int w,v;

}g[105];

huowu A[105], B[105], C[105], D[105];

bool cmp(huowu a,huowu b)

{

	return a.v > b.v;

}

int n,W;

int main()

{

	scanf("%d %d",&n,&W);

	int a, b, c, d, f;

	a = b = c = d = f = 0;

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

	{

		scanf("%d %d",&g[i].w,&g[i].v);

		if(g[i].w == g[1].w)

		{

			A[++a] = g[i];

		}

		else if(g[i].w == g[1].w + 1)

		{

			B[++b] = g[i];

		}

		else if(g[i].w == g[1].w + 2)

		{

			C[++c] = g[i];

		}

		else if(g[i].w == g[1].w + 3)

		{

			D[++d] = g[i];

		}

	}

	sort(A + 1,A + 1 + a,cmp);

	sort(B + 1,B + 1 + b,cmp);

	sort(C + 1,C + 1 + c,cmp);

	sort(D + 1,D + 1 + d,cmp);

	LL swa[110],swb[110],swc[110],swd[110];

	LL sva[110],svb[110],svc[110],svd[110];

	swa[0] = swb[0] = swc[0] = swd[0] = 0;  

    sva[0] = svb[0] = svc[0] = svd[0] = 0;  

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

    {  

        swa[i] = swa[i - 1] + A[i].w;  

        sva[i] = sva[i - 1] + A[i].v;  

    }  

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

    {  

        swb[i] = swb[i - 1] + B[i].w;  

        svb[i] = svb[i - 1] + B[i].v;  

     }  

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

     {  

         swc[i] = swc[i - 1] + C[i].w;  

         svc[i] = svc[i - 1] + C[i].v;  

     }  

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

     {  

        swd[i] = swd[i - 1] + D[i].w;  

        svd[i] = svd[i - 1] + D[i].v;  

      }  

    int sumv = 0;  

    int ans = 0;  

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

    {  

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

         {  

            for(int k = 0;k <= c;k++)  

            {  

             for(int l = 0;l <= d;l++)  

              {  

			      LL sum = swa[i] + swb[j] + swc[k] + swd[l];  

					if(sum <= (LL)W)  

					{  

                      f = max((LL)f,sva[i] + svb[j] + svc[k] + svd[l]);  

					}  

			 }  

            }  

        }  

    }  

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

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

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



using namespace std;

const int N = 1e5 + 10;



int n, a[N];



int main()

{

	scanf("%d", &n);

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

	int ans = 0;

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

	{

		bool ii = 0, d = 0;

		int j;

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

		{

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

			{

				ii = 1;

			}

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

			{

				d = 1;

			}

			if (ii && d)

			{

				break;

			}

		}

		i = j;

		ans++;

	}

	cout << ans << endl;

	return 0;

}

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



using namespace std;



int N;

int A[110000];



int main () {

	scanf ("%d", &N);

	for (int i = 0; i < N; i++) scanf ("%d", &A[i]);

	int ans = 1, pos = A[1] - A[0];

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

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

		if (1LL * pos * (A[i] - A[i - 1]) < 0) {

			ans++;

			pos = 0;

		}

	}

	printf ("%d\n", 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: 9.364693232270708x):
#include <cstdio>



using namespace std;



int N;

int A[110000];



int main () {

	scanf ("%d", &N);

	for (int i = 0; i < N; i++) scanf ("%d", &A[i]);

	int ans = 1, pos = A[1] - A[0];

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

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

		if (1LL * pos * (A[i] - A[i - 1]) < 0) {

			ans++;

			pos = 0;

		}

	}

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

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



using namespace std;



int N;

int A[110000];



int main () {

	scanf ("%d", &N);

	for (int i = 0; i < N; i++) scanf ("%d", &A[i]);

	int ans = 1, pos = A[1] - A[0];

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

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

		if (1LL * pos * (A[i] - A[i - 1]) < 0) {

			ans++;

			pos = 0;

		}

	}

	printf ("%d\n", 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.8197924894320048x):
#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);

}
// 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.7753844726257222x):
#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;

}
// 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.7775078069421109x):
#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;

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



using namespace std;

const int N = 1e5 + 10;



int n, a[N];



int main()

{

	scanf("%d", &n);

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

	int ans = 0;

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

	{

		bool ii = 0, d = 0;

		int j;

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

		{

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

			{

				ii = 1;

			}

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

			{

				d = 1;

			}

			if (ii && d)

			{

				break;

			}

		}

		i = j;

		ans++;

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.212531712740795x):
#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]);

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



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: 9.37198220403181x):
#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]);

//		for(;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 <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: 5.2256796067487095x):
#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]);

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

#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: 5.150027961131436x):
#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]);

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



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: 5.2788465532601085x):
#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]);

//		for(;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<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: 5.272540670386507x):
#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]);

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



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

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



using namespace std;

const int N = 1e5 + 10;



int n, a[N];



int main()

{

	scanf("%d", &n);

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

	int ans = 0;

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

	{

		bool ii = 0, d = 0;

		int j;

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

		{

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

			{

				ii = 1;

			}

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

			{

				d = 1;

			}

			if (ii && d)

			{

				break;

			}

		}

		i = j;

		ans++;

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.83274612140637x):
#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);

}