Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	bool a;
	bool b;
} P;
int main( void ){
	int N; cin >> N;
	int prev_input, input, cnt = 2, ans = 1; cin >> prev_input >> input;
	while(input == prev_input && cnt < N){
		cin >> input;
		cnt++;
	}
	bool is_inc = input >= prev_input;
	rep( i, 0, N - cnt ){
		prev_input = input;
		cin >> input;
		if (input == prev_input);
		else if (input >= prev_input ^ is_inc){
			if (i + cnt + 1 <  N){
				prev_input = input;
				cin >> input; cnt++;
				while(input == prev_input & i + cnt + 1 <  N){
					cin >> input;
					cnt++;
				}
				is_inc = input >= prev_input;
			}
			// is_inc = input >= prev_input;
			ans++;
		}
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	bool a;
	bool b;
} P;
int main( void ){
	int N; cin >> N;
	int prev_input, input, cnt = 2, ans = 1; cin >> prev_input >> input;
	while(input == prev_input && cnt < N){
		cin >> input;
		cnt++;
	}
	bool is_inc = input >= prev_input;
	rep( i, 0, N - cnt ){
		prev_input = input;
		cin >> input;
		if (input == prev_input);
		else if (input >= prev_input ^ is_inc){
			if (i + cnt + 1 <  N){
				prev_input = input;
				cin >> input; cnt++;
				while(input == prev_input & i + cnt + 1 <  N){
					cin >> input;
					cnt++;
				}
				is_inc = input >= prev_input;
			}
			// is_inc = input >= prev_input;
			ans++;
		}
	}
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Compiler output:
a.cc:113:10: error: redefinition of 'const ll INF'
  113 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:15:10: note: 'const ll INF' previously defined here
   15 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:114:11: error: redefinition of 'const int k_mod'
  114 | const int k_mod = 1e9 + 7;
      |           ^~~~~
a.cc:16:11: note: 'const int k_mod' previously defined here
   16 | const int k_mod = 1e9 + 7;
      |           ^~~~~
a.cc:119:3: error: conflicting declaration 'typedef struct edge edge'
  119 | } edge;
      |   ^~~~
a.cc:21:3: note: previous declaration as 'typedef struct edge edge'
   21 | } edge;
      |   ^~~~
a.cc:123:3: error: conflicting declaration 'typedef struct P P'
  123 | } P;
      |   ^
a.cc:25:3: note: previous declaration as 'typedef struct P P'
   25 | } P;
      |   ^
a.cc:124:5: error: redefinition of 'int main()'
  124 | int main( void ){
      |     ^~~~
a.cc:26:5: note: 'int main()' previously defined here
   26 | int main( void ){
      |     ^~~~
a.cc:153:6: error: redefinition of 'int* eratosthenes(int)'
  153 | int* eratosthenes( int N ){
      |      ^~~~~~~~~~~~
a.cc:55:6: note: 'int* eratosthenes(int)' previously defined here
   55 | int* eratosthenes( int N ){
      |      ^~~~~~~~~~~~
a.cc:171:25: error: redefinition of 'template<class T> void cumulative_sum(T, size_t)'
  171 | template <class T> void cumulative_sum( T array, size_t N ) {
      |                         ^~~~~~~~~~~~~~
a.cc:73:25: note: 'template<class T> void cumulative_sum(T, size_t)' previously declared here
   73 | template <class T> void cumulative_sum( T array, size_t N ) {
      |                         ^~~~~~~~~~~~~~
a.cc:176:25: error: redefinition of 'template<class T> bool chmax(T&, T)'
  176 | template <class T> bool chmax( T& a, T b ) {
      |                         ^~~~~
a.cc:78:25: note: 'template<class T> bool chmax(T&, T)' previously declared here
   78 | template <class T> bool chmax( T& a, T b ) {
      |                         ^~~~~
a.cc:182:25: error: redefinition of 'template<class T> bool chmin(T&, T)'
  182 | template <class T> bool chmin( T& a, T b ) {
      |                         ^~~~~
a.cc:84:25: note: 'template<class T> bool chmin(T&, T)' previously declared here
   84 | template <class T> bool chmin( T& a, T b ) {
      |                         ^~~~~
a.cc:188:6: error: redefinition of 'bool bit_search(int, int)'
  188 | bool bit_search( int pattern, int N ){
      |      ^~~~~~~~~~
a.cc:90:6: note: 'bool bit_search(int, int)' previously defined here
   90 | bool bit_search( int pattern, int N ){
      |      ^~~~~~~~~~