Problem:
 Score : 300 points    Problem Statement You are given an array A of length N .
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order.
At least how many subarrays do you need to divide A into?      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9  Each A_i is an integer.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print the minimum possible number of subarrays after division of A .        Sample Input 1 6
1 2 3 2 2 1      Sample Output 1 2  One optimal solution is to divide the array into [1,2,3] and [2,2,1] .       Sample Input 2 9
1 2 1 2 1 2 1 2 1      Sample Output 2 5       Sample Input 3 7
1 2 3 2 1 999999999 1000000000      Sample Output 3 3

Solution (Python):
N = int(input())
A = list(map(int, input().split(" ")))

decided = False
upping = True
i = 1
before = A[0]
ans = 1
while i < N:
    if decided:
        if upping:
            if before <= A[i]:
                pass
            else:
                decided = False
                ans += 1
        else:
            if before >= A[i]:
                pass
            else:
                decided = False
                ans += 1
    else:
        if before > A[i]:
            upping = False
            decided = True
        elif before < A[i]:
            upping = True
            decided = True
        elif before == A[i]:
            pass
    before = A[i]
    i += 1
print(ans)

Solution (Python):
def solve():
    N = int(input())
    A = [int(x) for x in input().split()]

    diff = [A[i]-A[i-1] for i in range(1, N)]
    ans = 1

    last = None
    for d in [d for d in diff if d != 0]:
        if d == 0:
            continue
        if last is None:
            last = d
        else:
            if last * d < 0:
                ans += 1
                last = None
            else:
                last = d
    print(ans)


solve()

Solution (Python):
N = int(input())
cnt = 0
tmp = ''
M = list(map(int,input().split()))
L = []
for x in M:
    if x == tmp:
        pass
    else:
        L.append(x)
    tmp = x
    

    
while True:
    try: 
        if L[0] <L[1]>L[2] or L[0] > L[1] <L[2]:
            a0=L.pop(0)
            a1=L.pop(0)
            cnt += 1
        else:
            L.pop(0)
    except:
        break

print(1+cnt)

Solution (Python):




def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			elif diff < 0:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Solution (Python):





def solveProblem(allNumber,aList):
	flag = "Flat"
	count = 1
	for i in range(allNumber - 1):
		b = aList[i + 1] - aList[i]
		if flag == "Plus":
			if b < 0:
				flag = "Flat"
				count = count+1
		elif flag == "Minus":
			if b > 0:
				flag = "Flag"
				count = count+1
		else:
			if b > 0:
				flag = "Plus"
			elif b < 0:
				flag = "Minus"
	answer = count
	return answer

if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().split()))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = 1

if N < 3:
	print(ans)
	exit()

if a[0] < a[1]:
	flag = 1
if a[0] > a[1]:
	flag = -1
if a[0] == a[1]:
	flag = 0


for i in range(2,N):
	if flag == 1 and a[i-1] > a[i]:
		ans += 1
		flag = 0
	elif flag == -1 and a[i-1] < a[i]:
		ans += 1
		flag = 0
	elif flag == 0 and a[i-1] < a[i]:
		flag = 1
	elif flag == 0 and a[i-1] > a[i]:
		flag = -1
	
print(ans)

Solution (Python):
def solve(A, inc):

    ans = 1
    N = len(A)
    l = []
    for i in range(1, N):
        if A[i] > A[i-1]:
            l.append(1)
        elif A[i] < A[i-1]:
            l.append(-1)

    for i in range(1, len(l)):
        if l[i]*l[i-1] < 0:
            l[i] = 0
            ans += 1
    return ans


N = int(input())
A = list(map(int, input().split()))

print(solve(A, True))

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
aN = LIST()

if N == 1:
    print(1)
    exit()



flag = 0
if aN[0] < aN[1]:
    flag = 1
elif aN[0] == aN[1]:
    flag = 0
else:
    flag = 2

cnt = 1

for i in range(2, N):
    if aN[i-1] == aN[i]:
        continue
    elif aN[i-1] > aN[i]:
        if flag == 1:
            cnt += 1
            flag = 0
        else:
            flag = 2
    elif aN[i-1] < aN[i]:
        if flag == 2:
            cnt += 1
            flag = 0
        else:
            flag = 1
print(cnt)

Solution (Python):
n = int(input())
li = list(map(int, input().split()))

ans = 1
inc = 0
tmp = li[0]
for a in li[1:]:
    if inc * (a - tmp) < 0:
        ans += 1
        inc = 0
    else:
        inc += a - tmp
    tmp = a

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = [a[0]] + a
hoge = 0
ans = 1
for i in range(n):
    prev = a[i]
    now = a[i+1]
    
    if hoge == 0:
        if now > prev:
            hoge = 1
        elif now < prev:
            hoge = -1
    
    elif hoge == 1:
        if now < prev:
            hoge = 0
            ans += 1
    
    else:
        if now > prev:
            hoge = 0
            ans += 1
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ans = 1

up = False
down = False
ok = True

t = a[0]
i = 1
while i < N:
    if ok:
        if a[i] > t:
            up = True
            down = False
            ok = False
        elif a[i] == t:
            up = False
            down = False
            ok = True
        else:
            up = False
            down = True
            ok = False
    elif up:
        if a[i] >= t:
            up = True
            down = False
            ok = False
        else:
            up = False
            down = False
            ok = True
            ans += 1
    elif down:
        if a[i] <= t:
            up = False
            down = True
            ok = False
        else:
            up = False
            down = False
            ok = True
            ans += 1
    t = a[i]
    i += 1
print(ans)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
if N==1:
    print(1)
    exit()
T=[[A[0],A[1]]]
for i in range(2,N):
    if len(T[-1])<=1:
        T[-1].append(A[i])
        continue
    if not((T[-1][0]>=A[i-2]>=A[i-1]>=A[i]) or (T[-1][0]<=A[i-2]<=A[i-1]<=A[i])):
        T.append([A[i]])
    else:
        T[-1].append(A[i])
print(len(T))

Solution (Python):
a = int(input())
ar = list(map(int,input().split(" ")))
count = 1
n = ""
for i in range(a-1):
    if ar[i] > ar[i+1]:
        if n == "P":
            count += 1
            n = ""
        else:
            n = "M"
    elif ar[i] < ar[i+1]:
        if n == "M":
            count += 1
            n = ""
        else:
            n = "P"
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = "0"
ans = 1
for i in range(n-1):
  b = a[i+1]-a[i]
  if c == "+":
    if b < 0:
      c = "0"
      ans += 1
  elif c == "-":
    if b > 0:
      c = "0"
      ans += 1
  else:
    if b > 0:
      c = "+"
    elif b < 0:
      c = "-"
print(ans)

Solution (Python):
n=int(input())

x=[int(i)for i in input().split()]


count=1

state=0

for i in range(1,n):
    a=state
    d=x[i]-x[i-1]
    if(d>0):
        state=1
    elif(d==0):
        pass
    elif(d<0):
        state=-1
    if(state*a==-1):
        count+=1
        state=0

    


print(count)

Solution (Python):
import sys

import numpy as np


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def get_state(x, y):
    if x > y:
        return "Down"
    if x < y:
        return "Up"
    return "Equal"


N = ii()
A = il()
pre_state = None
c = 1
for i in range(N - 1):
    current_state = get_state(A[i], A[i + 1])
    if current_state == "Equal" or current_state == pre_state:
        continue
    if pre_state is None:
        pre_state = current_state
    else:
        pre_state = None
        c += 1
print(c)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
t=1
p=a[0]
m=0
for i in a:
  if(p==i):
    continue
  if(m>0):
    if(i<p):
      t+=1
      m=0
  elif(m<0):
    if(i>p):
      t+=1
      m=0
  else:
    if(i>p):
      m=1
    elif(i<p):
      m=-1
  p=i
print(t)

Solution (Python):
N = int(input())

a = list(map(int, input().split()))

ans = 1

now = a[0]

f = 0

for i in range(1, N):
    if now == a[i]:
        now = a[i]
    elif a[i]>now:
        if f == 0:
            f = 1
            now = a[i]
        elif f == 1:
            now = a[i]
        else:
            f = 0
            ans = ans + 1
            now = a[i]
    else:
        if f == 0:
            f = -1
            now = a[i]
        elif f == -1:
            now = a[i]
        else:
            f = 0
            ans = ans + 1
            now = a[i]

        

    
print(ans)

Solution (Python):
N = int(input())
inputs = [int(i) for i in input().split()]

flag = -1
ans = 1

for i in range(1, N):
    first = inputs[i-1]
    latter = inputs[i]
    if flag == -1:
        if first < latter:
            flag = 1
        elif first > latter:
            flag = 0
    elif flag == 1:
        if first > latter:
            flag = -1
            ans += 1
    else:
        if first < latter:
            flag = -1
            ans += 1

print(ans)

Solution (Python):
N = int(input())
inputs = [int(i) for i in input().split()]

start = inputs[0]
flag = 0
ans = 1

for i in range(1, N):
    if flag == 0:
        if start < inputs[i]:
            flag = 1
        elif start > inputs[i]:
            flag = -1
    elif flag == 1:
        if start > inputs[i]:
            flag = 0
            ans += 1
    else:
        if start < inputs[i]:
            flag = 0
            ans += 1
    start = inputs[i]

print(ans)

Solution (Python):
N = int(input())
inputs = [int(i) for i in input().split()]

start = inputs[0]
flag = 0
ans = 1

for i in range(1, N):
    if flag == 0:
        if start < inputs[i]:
            flag = 1
        elif start > inputs[i]:
            flag = -1
        start = inputs[i]
    elif flag == 1:
        if start > inputs[i]:
            flag = 0
            ans += 1
        start = inputs[i]
    else:
        if start < inputs[i]:
            flag = 0
            ans += 1
        start = inputs[i]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

orient=0
count=0
prev=A[0]

for i in range(1,N):
    if A[i]<prev:
        if orient==1:
            count+=1
            prev=A[i]
            orient=0
        elif orient==-1:
            prev=A[i]
        else:
            orient=-1
            prev=A[i]
    elif A[i]>prev:
        if orient==-1:
            count+=1
            prev=A[i]
            orient=0
        elif orient==1:
            prev=A[i]
        else:
            orient=1
            prev=A[i]

       
print(count+1)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cond = 0

res = 1
for i in range(1,len(a)):
    if a[i] > a[i-1]:
        
        if cond != 1:
            if cond == -1:
                res += 1
                cond = 0
            else:
                cond = 1
    elif a[i] < a[i-1]:
        
        if cond != -1:
            if cond == 1:
                res += 1
                cond = 0
            else:
                cond = -1
print(res)

Solution (Python):



def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

ans = 1
prev = A[0]
state = 0  
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)

Solution (Python):


import sys
from collections import Counter



INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

ans = 1
prev = A[0]
state = 0
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)

Solution (Python):


import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

ans = 1
prev = A[0]
state = 0
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
state = 0
count = 1
for i in range(1,N):
    note = state
    d = A[i] - A[i-1]
    if d > 0:
        state = 1
    elif d == 0:
        pass
    elif d < 0:
        state = -1
    if (state,note) == (1,-1) or (state,note) == (-1,1):
        count += 1
        state = 0
print(count)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

base=A[0]
cnt=1
mode="N"
for i in range(N):
    if mode=="N":
        if A[i]>base:
            mode="P"
        elif A[i]<base:
            mode="M"
        else:
            pass
    elif mode=="P":
        if A[i]>=A[i-1]:
            pass
        else:
            mode="N"
            cnt+=1
            base=A[i]
    elif mode=="M":
        if A[i]<=A[i-1]:
            pass
        else:
            mode="N"
            cnt+=1
            base=A[i]
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

if N == 1:
    print(1)
    exit()
ans = 1
pm = 1

i = 0
tmp = []
while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
            if pm == 0 and A[i] != A[i-1]:
                if A[i-1] < A[i]:
                    pm = 1
                else:
                    pm = -1
        else:
            i += 1
            if N <= i:
                ans += 1
                break

            if A[i-1] == A[i]:
                pm = 0
            elif A[i-1] < A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)

Solution (Python):



def main():
    """Function."""
    n = int(input())
    a = list(map(int, input().split()))

    counter = 1
    flag, last = 0, a[0]
    for i in range(n-1):
        temp = a[i+1]
        if flag == 0:
            if temp == last:
                pass
            elif temp > last:
                flag = 1
            elif temp < last:
                flag = -1

        if flag == 1:
            if temp == last:
                pass
            elif temp > last:
                pass
            elif temp < last:
                counter += 1
                flag = 0

        if flag == -1:
            if temp == last:
                pass
            elif temp > last:
                counter += 1
                flag = 0
            elif temp < last:
                pass

        last = temp

    print(counter)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
numbers = list(map(int, input().split()))

flag = None
s = 1
for i, x in enumerate(numbers):
    if i == 0:
        continue
    if x == numbers[i-1]:
        continue
    if x > numbers[i-1]:
        if flag is None:
            flag = 1
        if flag == 0:
            s += 1
            flag = None
    elif x < numbers[i-1]:
        if flag is None:
            flag = 0
        if flag == 1:
            s += 1
            flag = None
print(s)

Solution (Python):

N=int(input())
A = list(map(int,input().split()))
prev = A[0]
count=1
direction = 0
for i in range(1,N):
    if A[i] > prev:
        if direction==0:
            direction=1
        elif direction==-1:
            count+=1
            direction=0
    elif A[i] < prev:
        if direction==0:
            direction=-1
        elif direction==1:
            count+=1
            direction=0
    prev=A[i]
    
print(count)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
count=1
flag=0
for i in range(n-1):
  if flag==0:
    if a[i+1]<a[i]:
      flag=-1
    elif a[i+1]>a[i]:
      flag=1
  elif flag==1:
    if a[i+1]<a[i]:
      flag=0
      count+=1
  elif flag==-1:
    if a[i+1]>a[i]:
      flag=0
      count+=1
print(count)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)

N = int(input())
A = list(map(int, input().split()))


def solve(i, ret, t):
    if i == N:
        return ret
    else:
        if t == '?':
            if A[i] > A[i - 1]:
                return solve(i + 1, ret, 'up')
            elif A[i] < A[i - 1]:
                return solve(i + 1, ret, 'down')
            else:
                return solve(i + 1, ret, '?')

        elif t == 'up' and A[i] < A[i - 1]:
            return solve(i + 1, ret + 1, '?')
        elif t == 'down' and A[i] > A[i - 1]:
            return solve(i + 1, ret + 1, '?')
        else:
            return solve(i + 1, ret, t)


print(solve(1, 1, '?'))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
a=1
b=0
for i in range(1,N):
    d=A[i]-A[i-1]
    if b==0:
        b=d
        continue
    if d>0:
        if b<0:
            a+=1
            b=0
    elif d<0:
        if b>0:
            a+=1
            b=0
print(a)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

increase = False
decrease = False
ans = 1
for i in range(N-1):
    dif = a[i+1]-a[i]
    if dif>0:
        if not decrease:
            increase = True
        else:
            ans += 1
            increase, decrease = False, False
    if dif<0:
        if not increase:
            decrease = True
        else:
            ans += 1
            increase, decrease = False, False
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))         
flag = -1
ans = 0
for i in range(n):
  if flag == -1:
    ans += 1
    flag = 2
  elif flag == 2:
    if a[i]>a[i-1]:
      flag = 1
    if a[i]<a[i-1]:
      flag =0
  elif flag == 1:
    if a[i]-a[i-1] >= 0:
      continue
    ans += 1
    flag = 2
  else:
    if a[i-1]-a[i] >= 0:
      continue
    ans+=1
    flag =2
print(ans)

Solution (Python):
import pdb


def main():
    num = int(input())
    array = []
    tmp = input()
    tmp = tmp.split()
    for i in range(num):
        array.append(int(tmp[i]))
        
    ans = 1
    div = 0
    prev = 0
    count = 0
    
    for tmp in array:
        count += 1
        if count == 1:
            prev = tmp
            continue

        if div == 0:
            if prev < tmp:
                div = 1
            elif prev > tmp:
                div = -1
        else:
            if prev < tmp and div == -1:
                ans += 1
                div = 0
            elif prev > tmp and div == 1:
                ans += 1
                div = 0
                
        prev = tmp
        
    print(ans)

        
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]





up = False
down = False
count = 0
i = 1
while i < len(a):
    
    if a[i] - a[i - 1] > 0 and down:
        
        up = False
        down = False
        count += 1
    elif a[i] - a[i - 1] < 0 and up:
        
        up = False
        down = False
        count += 1
    elif a[i] - a[i-1] > 0:
        up = True
    elif a[i] - a[i-1] < 0:
        down = True
    i += 1
print(count + 1)

Solution (Python):
N = int(input())
A = ['head']
for x in map(int, input().split()):
    if A[-1] != x:
        A.append(x)
if len(A) == 2:
    print(1)
    exit()
cnt = 1
inc = A[1] < A[2]
skip = False
for x, y in zip(A[2:], A[3:]):
    if skip:
        skip = False
        inc = x < y
        continue
    if inc != (x < y):
        skip = True
        cnt += 1
print(cnt)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
increasing = False
decreasing = False
count = 1
for i in range(N - 1):
    if A[i] < A[i + 1]:
        if decreasing:
            count += 1
            increasing = False
            decreasing = False
        else:
            increasing = True
    elif A[i] > A[i + 1]:
        if increasing:
            count += 1
            increasing = False
            decreasing = False
        else:
            decreasing = True
print(count)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
ans=1
chk=-1
flg=0
for i in range(0,n):
    if chk==-1:
        chk=l[i]
    elif chk==l[i]:
        pass
    elif flg==0:
        flg=[-1,1][chk-l[i]<0]
        chk=l[i]
    elif flg==-1:
        if chk-l[i]<0:
            ans+=1
            flg=0
        chk=l[i]
    else:
        if chk-l[i]>0:
            ans+=1
            flg=0
        chk=l[i]
print(ans)

Solution (Python):
import sys


def main() -> None:
    way = 0
    pre = 0
    ans = 1

    n = next_int()

    for i in range(n):
        now = next_int()
        if i == 0 or now - pre == 0:
            pass
        elif way == 0:
            way = sgn(now - pre)
        elif sgn(now - pre) != way:
            ans += 1
            way = 0

        pre = now

    print(ans)


def sgn(x: int) -> int:
    if x == 0:
        return 0
    if x > 0:
        return 1
    return -1

def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
res = 1
cur = None
np = None
for a in list(map(int, input().split())):
    
    if cur is None:
        pass
    elif np is None:
        if a==cur:
            np = 0
        elif a>cur:
            np = 1
        else:
            np = -1
    else:
        if np==0:
            if a==cur:
                pass
            elif a>cur:
                np = 1
            else:
                np = -1
        elif np>0:
            if a>=cur:
                pass
            else:
                res += 1
                np = None
        else:
            if a<=cur:
                pass
            else:
                res += 1
                np = None
    cur = a

print(res)

Solution (Python):

def main():
    buf = input()
    N = int(buf)
    buf = input()
    buflist = buf.split()
    A = list(map(int, buflist))
    split_count = 1
    increasing = None
    for i in range(1, N):
        if increasing == None:
            if A[i-1] < A[i]:
                increasing = True
            elif A[i-1] > A[i]:
                increasing = False
            
        elif increasing and A[i-1] > A[i]:
            split_count += 1
            increasing = None 
        elif not increasing and A[i-1] < A[i]:
            split_count += 1
            increasing = None 
    print(split_count)

if __name__ == '__main__':
    main()

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

N = int(input())
A = inpl()
ans = 1
first = True
for i in range(N-1):
    if first:
        if A[i+1] == A[i]:
            continue
        else:
            c = (A[i+1]-A[i])//abs((A[i+1]-A[i]))
            first = False
            continue
    if c*A[i] > c*A[i+1]:
        ans += 1
        first = True
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
j=0
ans=1
for i in range(n-1):
    if j==0 and a[i]<a[i+1]:
        j=1
    elif j==0 and a[i]>a[i+1]:
        j=-1
    elif j*(a[i+1]-a[i])<0:
        j=0
        ans +=1
print(ans)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

arrays = 1
ratio = ""
for i in range(1, N):
    if ratio == "+":
        if A[i] < A[i-1]:
            arrays += 1
            ratio = ""

    elif ratio == "-":
        if A[i] > A[i-1]:
            arrays += 1
            ratio = ""
    else:
        if A[i] > A[i-1]:
            ratio = "+"
        elif A[i] < A[i-1]:
            ratio = "-"
print(arrays)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dist = []
for a in A:
    if dist and dist[-1] == a:
        continue
    dist.append(a)
ans = 1
i = 2
while i < len(dist):
    if (dist[i-2] < dist[i-1]) != (dist[i-1] < dist[i]):
        ans += 1
        i += 1
    i += 1
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dist = []
for a in A:
    if dist and dist[-1] == a:
        continue
    dist.append(a)
ans = 0
next = 0
for i in range(1, len(dist)-1):
    if (dist[i-1] < dist[i]) == (dist[i] > dist[i+1]) and i != next:
        next = i + 1
        ans += 1
print(ans + 1)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = []
tmp = []
flag = 0

for i in range(len(a)):
    if len(tmp) == 0:
        tmp.append(a[i])
    elif flag == 0:
        flag = 1 if tmp[-1] < a[i] else -1 if tmp[-1] > a[i] else 0
        tmp.append(a[i])
    elif (flag == 1 and tmp[-1] <= a[i]) or (flag == -1 and tmp[-1] >= a[i]):
        tmp.append(a[i])
    else:
        ans.append(tmp)
        tmp = [a[i]]
        flag = 0

print(len(ans) + 1)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
ans = 1
flag = 0
for i in range(N-1) :
    if flag == 0 :
        if L[i+1]-L[i] > 0 :
            flag = 1
        elif L[i+1]-L[i] < 0 :
            flag = -1
    elif flag == 1 :
        if L[i+1]-L[i] < 0 :
            ans += 1
            flag = 0
    else :
        if L[i+1]-L[i] > 0 :
            ans += 1
            flag = 0
            
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

cnt = 1
prev = -1
dir = 0

for i in range(N):
  if prev == -1:
    prev = A[i]
    continue
    
  if dir == 0:
    if prev < A[i]:
      dir = 1
    elif prev > A[i]:
      dir = -1
  elif dir > 0:
    if prev <= A[i]:
      pass      
    else:
      dir = 0
      cnt += 1
  else:
    if prev >= A[i]:
      pass
    else:
      dir = 0
      cnt += 1
  prev = A[i]
  
print(cnt)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

count = 1
flag = ""

for i in range(N - 1):
    d = A[i + 1] - A[i]

    if flag == "":
        if d > 0:
            flag = "P"
        elif d < 0:
            flag = "M"

    elif (flag == "P" and d < 0) or (flag == "M" and d > 0):

        count += 1
        flag = ""

print(count)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
ans,c,d=0,1,True
while c<n:
    if a[c]==a[c-1]:
        c+=1
        continue
    if d:
        f=a[c]>a[c-1]
        d=False
    elif f:
        if a[c]<a[c-1]:
            ans+=1
            d=True
    else:
        if a[c]>a[c-1]:
            ans+=1
            d=True
    c+=1
print(ans+1)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [a[0]]
now = a[0]
for i in range(n-1):
    if now == a[i+1]:
        continue
    else:
        b.append(a[i+1])
        now = a[i+1]
n = len(b)
if n == 1:
    print(1)
    exit()
i = 0
ans = 0
while i < n-1:
    s = b[i]
    t = b[i+1]
    if s < t:
        state = 1
    else:
        state = 0
    temp = state
    while True:
        if state:
            if b[i] < b[i+1]:
                i += 1
            else:
                ans += 1
                i += 1
                break
        else:
            if b[i] > b[i+1]:
                i += 1
            else:
                ans += 1
                i += 1
                break
        if i == n-1:
            break

print(ans+1)

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))

count = 0
c_list = []
increment = False
decrement = False

for i, a in enumerate(a_list):
    if i == 0:
        c_list.append(a)

    elif not increment and not decrement:
        if a > c_list[0]:
            c_list.append(a)
            increment = True
        elif a < c_list[0]:
            c_list.append(a)
            decrement = True
        else:
            continue
    else:
        if increment:
            if a >= c_list[-1]:
                c_list.append(a)
            else:
                c_list = [a]
                increment = False
                decrement = False
                count += 1
        else:
            if a <= c_list[-1]:
                c_list.append(a)
            else:
                c_list = [a]
                increment = False
                decrement = False
                count += 1

print(count+1)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

if N == 1:
	print(1)

elif N == 2:
	print(1)

else:
	L = []
	for i in range(1, N):
		x = A[i] - A[i - 1]
		if x > 0:
			L.append("+")
		elif x == 0:
			L.append(".")
		else:
			L.append("-")

	c = 1
	judge = L[0]
	for i in range(1,N - 1):
		if L[i] == ".":
			pass
		elif L[i] == "+":
			if judge == "+" or judge == ".":
				judge = "+"
			else:
				c += 1
				judge = "."
		else:
			if judge == "-" or judge == ".":
				judge = "-"
			else:
				c += 1
				judge = "."

	print(c)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[];c=1;d=-1
for i in range(1,n):
  if a[i]-a[i-1]<0:b.append(-1)
  elif a[i]-a[i-1]>0:b.append(1)
for j in range(1,len(b)):
  if b[j]*b[j-1]<0 and d!=j-1:
    c+=1
    d=j
print(c)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))

ans = 1
flg = ''
for i in range(N - 1):
    if (flg == 'LE' and As[i] > As[i + 1]) or (flg == 'GE' and As[i] < As[i + 1]):
        ans += 1
        flg = ''
    else:
        if As[i] < As[i + 1]: flg = 'LE'
        elif As[i] > As[i + 1]: flg = 'GE'

print(ans)