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 = [int(i) for i in input().split()]
if n == 1:
    ans = 1
else:
    if a[1] > a[0]:
        temp = 1
    elif a[1] < a[0]:
        temp = -1
    else:
        temp = 0
    ans = 1
    for i in range(1, n-1):
        if a[i+1] > a[i]:
            if temp >= 0:
                temp = 1
            elif temp == -1:
                ans += 1
                temp = 0
        elif a[i+1] < a[i]:
            if temp <= 0:
                temp = -1
            elif temp == 1:
                ans += 1
                temp = 0
print(ans)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
slope=0
count=1
for i in range(1,n):
  d=A[i]-A[i-1]
  if slope==0:
    slope=d
  elif slope*d<0:
    count+=1
    slope=0
print(count)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
cnt=0
flag1=False
flag2='x'
for i in range(n-1):
  if arr[i]<arr[i+1]:
    if flag1==False:
      flag1=True
      flag2='p'
    if flag2=='n':
      flag1=False
      flag2='x'
      cnt+=1
  if arr[i]>arr[i+1]:
    if flag1==False:
      flag1=True
      flag2='n'
    if flag2=='p':
      flag1=False
      flag2='x'
      cnt+=1
print(cnt+1)

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

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

Solution (Python):
n =int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
sa = A[0]

for a in A:
    if a > sa:
        if flag != 2 :
            flag = 1
        else:
            ans += 1
            flag = 0
            
    elif a < sa:
        if flag != 1:
            flag = 2
        else:
            ans += 1
            flag = 0
    
    sa = a

print(ans)

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

count = 1
key = 0
for i in range(N-1):
    if key == 0:
        if A[i+1] - A[i] > 0:
            key = 1
        elif A[i+1] - A[i] < 0:
            key = -1
        else:
            continue
    elif key == 1:
        if A[i+1] - A[i] < 0:
            key = 0
            count += 1
    else:
        if A[i+1] - A[i] > 0:
            key = 0
            count += 1
print(count)

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

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

prev = a[0]
result = 0
up_down = None

for v in a[1:]:
    if up_down is None:
        if prev > v:
            up_down = lambda a, b: a >= b
        elif prev < v:
            up_down = lambda a, b: a <= b
        else:
            
            continue
    if not up_down(prev, v):
        
        up_down = None
        result += 1
    
    prev = v

print(result + 1)

Solution (Python):

def splitter(n, a):
    count = 1
    mode = 'none'
    for i in range(1, n):
        if mode == 'incr':
            if a[-i-1] > a[-i]:
                
                count += 1
                
                mode = 'none'
            else:
                continue
        elif mode == 'decr':
            if a[-i-1] < a[-i]:
                
                count += 1
                
                mode = 'none'
        else:
            if a[-i-1] == a[-i]:
                
                continue
            elif a[-i-1] > a[-i]:
                
                mode = 'decr'
            elif a[-i-1] < a[-i]:
                
                mode = 'incr'
    return count


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

    print(splitter(n, a))


main()

Solution (Python):
N = int(input())
A = [int(n) for n in input().split()]
ans = 0
up = False
down = False
for i in range(N-1):
    if A[i] < A[i+1]:
        up = True
        if (down):
            ans += 1
            up = False
            down = False
    elif A[i] > A[i+1]:
        down = True
        if up:
            ans += 1
            down = False
            up = False
    else:
        pass
print(ans+1)

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

trend = 0
groups = 1

for i in range(N-1):
  if trend * (A[i+1] - A[i]) < 0:
    trend = 0
    groups +=1
  elif trend == 0:
    trend = A[i+1] - A[i]
    
print(groups)

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

total = 1
trend = 0
prev = A[0]
for a in A[1:]:
    if a > prev and trend < 0:
        total += 1
        trend = 0
    elif a < prev and trend > 0:
        total += 1
        trend = 0
    elif trend == 0:
        trend = a - prev
    prev = a

print(total)

Solution (Python):
def main():
    N = int(input())
    As = list(map(int, input().split()))
    ct = 1
    inc = False
    dec = False
    bef = As.pop(0)

    for Ai in As:
        if (not inc) and (not dec):
            if Ai < bef:
                dec = True
            elif Ai > bef:
                inc = True
        elif inc:
            if Ai < bef:
                ct += 1
                inc = False
        elif dec:
            if Ai > bef:
                ct += 1
                dec = False
        bef = Ai
    
    print(ct)

main()

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

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

prev=a[0]
state=0 

ans=1

for cur in a:
  
  if state==1 and prev>cur:
    ans+=1
    state=0
  elif state==2 and prev<cur:
    ans+=1
    state=0
  else:
    if prev>cur:
      state=2
    elif prev<cur:
      state=1
    
    
    
    
  prev=cur

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1] - a[i]
cnt = 1
l = r = cur = 0
while l < n-1:
    while r < n-1 and cur * d[r] >= 0:
        if cur == 0:
            cur = d[r]
        r += 1
    if r < n-1 and cur * d[r] < 0:
        cnt += 1
    r += 1
    l = r
    cur = 0
print(cnt)

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

upflag = True
downflag = True
answer = 1
for i in range(N - 1):
    if A[i] < A[i + 1]:
        downflag = False
    if A[i] > A[i + 1]:
        upflag = False
    if not (upflag or downflag):
        answer += 1
        upflag = True
        downflag = True
print(answer)

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

count = 1
increasing = None

for i in range(n-1):
  if increasing == None:
    if a[i] - a[i+1] > 0:
      increasing = True
    elif a[i] - a[i+1] < 0:
      increasing = False

  elif increasing:
    if a[i] - a[i+1] < 0:
      increasing = None
      count += 1

  elif not increasing:
    if a[i] - a[i+1] > 0:
      increasing = None
      count += 1
print(count)

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

count = 0
state = 0
beforeA = As[0]
for A in As:
    if A > beforeA:
        if state == 0 or state == 1:
            state = 1
        else:
            count += 1
            state = 0
    if A < beforeA:
        if state == 0 or state == 2:
            state = 2
        else:
            count += 1
            state = 0
    beforeA = A

print(count+1)

Solution (Python):
n = int(input())
s = map(int, input().split())
s = list(s)
num = 0
ASC, DES, EQ, UND = 0, 1, 2, 3
state = UND
if len(s) <= 2:
    print(1)
    exit()
i = s[0]
for j in s[1:]:
    if state == UND:
        if i > j:
            state = DES
        elif i < j:
            state = ASC
        else:
            state = EQ
        num += 1
    elif state == EQ:
        if i > j:
            state = DES
        elif i < j:
            state = ASC
    elif state == DES:
        if i >= j:
            pass
        else:
            state = UND
    else:
        if i <= j:
            pass
        else:
            state = UND
    i = j
if state == UND:
    num += 1

print(num)

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

I = [x>y for x,y in zip([0]+A,A+[10**10])]          
D = [x<y for x,y in zip([10**10]+A,A+[0])]          

ci = False
cd = False
ans = 1
for i in range(N+1): 
    ci += I[i]
    cd += D[i]
    if ci and cd:
        ans += 1
        ci = False
        cd = False
print(ans)

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

flag = False
isIncrease = True
count = 1

for i in range(len(A) - 1) :
    if not flag :
        if A[i] < A[i + 1] :
            isIncrease = True
            flag = True
        elif A[i] > A[i + 1] :
            isIncrease = False
            flag = True
    else :
        if A[i] > A[i + 1] :
            if isIncrease :
                count += 1
                flag = False
        elif A[i] < A[i + 1] :
            if not isIncrease :
                count += 1
                flag = False

print(count)

Solution (Python):
n,*a=map(int,open(0).read().split())
tmp=0
ans=1
for i in range(len(a)-1):
    dif=a[i+1]-a[i]
    if tmp==0:
        tmp=dif
    elif dif*tmp<0:
        ans+=1
        tmp=0

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
flag = 0
cnt = 1
for k in range(N-1):
  if (A[k] > A[k+1]):
    flag_tmp = flag
    flag = -1
    if flag_tmp == 1:
      cnt += 1
      flag = 0
  elif (A[k] < A[k+1]):
    flag_tmp = flag
    flag = 1
    if flag_tmp == -1:
      cnt += 1
      flag = 0
print(cnt)

Solution (Python):
def solution(num, list):
    flag = "default"
    count = 1
    for i in range(num - 1):
        diff = l[i+1] - l[i]
        if flag == "plus":
            if diff < 0:
                flag = "default"
                count += 1
        elif flag == "minus":
            if diff > 0:
                flag = "default"
                count += 1
        else:
            if diff > 0:
                flag = "plus"
            elif diff < 0:
                flag = "minus"
    return count

if __name__ == "__main__":
    n = int(input())
    l = list(map(int, input().split()))
    print(solution(n, l))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
 
ans = 1
sumDiff = 0	
		
		
for i in range(1,len(A)):
	
	diff = A[i]-A[i-1]
	if sumDiff*diff < 0:		
		ans += 1
		sumDiff = 0		
					
	else:
		sumDiff += diff		
 
print(ans)

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

ans = float('inf')
for way in 1, -1:
    b = 1
    t = a[0]
    for aa in a:
        if way == 1:
            if aa < t:
                b += 1
                way = 0
        elif way == -1:
            if aa > t:
                b += 1
                way = 0
        else:
            if aa < t:
                way = -1
            elif aa == t:
                way = 0
            else:
                
                way = 1
        t = aa
    ans = min(ans, b)
print(ans)

Solution (Python):
import numpy

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

ans = 1				
beforeDiff = 0				
chgFlag = True				

for i in range(1,N):			
	diff = AN[i] - AN[i-1]
	
	if chgFlag or beforeDiff==0:	
		beforeDiff = diff	
		chgFlag = False	
		continue
		
	if (numpy.sign(beforeDiff) == 1 and numpy.sign(diff) == -1) or (numpy.sign(beforeDiff) == -1 and numpy.sign(diff) == 1):		
		chgFlag = True		
		ans += 1
		
print(ans)

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

ans = 1				
beforeDiff = 0				
chgFlag = True				

for i in range(1,N):			
	diff = AN[i] - AN[i-1]
	
	if chgFlag or beforeDiff==0:	
		beforeDiff = diff	
		chgFlag = False	
		continue
		
	if beforeDiff*diff < 0:		
		chgFlag = True		
		ans += 1
		
print(ans)

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

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

ans = 1		
beforeDiff = 0

for i in range(1,N):
	diff = AN[i] - AN[i-1]
	
	if beforeDiff==0:	
		beforeDiff = diff
	elif beforeDiff*diff < 0:	
		beforeDiff = 0	
		ans += 1
				
print(ans)

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]

    pre_stat = 999
    count = 1
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            stat = 1
        elif A[i] > A[i + 1]:
            stat = -1
        else:
            stat = 0
        if pre_stat != 999 and stat != 0:
            if stat != pre_stat:
                count += 1
                pre_stat = 999
        elif stat != 0:
            pre_stat = stat
    print count

if __name__ == '__main__':
    main()

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

p = A[0]
count = 0
b = 0
c = 0
for i in range(1,N):
    a = A[i]
    b += a-p
    c += abs(a-p)
    if abs(b) != c:
        count += 1
        b = 0
        c = 0
    p = a
print(count+1)

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

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
s = a[0]
c,j = 0,0
for i in a[1:]:
 
  if j ==0:
    if i-s > 0:
      j =1
      s = i
      continue
    elif i-s < 0:
      j = -1
      s = i
      continue
  elif i-s > 0 and j ==-1:
    j = 0
    c+=1
    
  if i-s < 0 and j==1:
    j = 0
    c+=1
  s = i
  
print(c+1)

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

if n == 1:
    cnt = 1
else:
    if A[0] < A[1]:
        flag = 1
    elif A[0] > A[1]:
        flag = -1
    else:
        flag = 0
    
    cnt = 1
    x = A[1]
    for i in range(2, n):
        if flag == 1:
            if x <= A[i]:
                pass
            else:
                cnt += 1
                flag = 0
                
        elif flag == -1:
            if x < A[i]:
                cnt += 1
                flag = 0
            else:
                pass
            
        else:
            if x < A[i]:
                flag = 1
            elif x > A[i]:
                flag = -1
            else:
                flag = 0
        
        x = A[i]
    
print(cnt)

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

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

cnt = 0
i = 0
while i < n-1:
    if a[i] < a[i+1]:
        while i < n-1:
            if a[i] > a[i+1]:
                cnt += 1
                i += 1
                break
            i += 1
    elif a[i] > a[i+1]:
        while i < n-1:
            if a[i] < a[i+1]:
                cnt += 1
                i += 1
                break
            i += 1
    else:
        i += 1
print(cnt+1)

Solution (Python):



def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = [a[0]]
    ans = 1

    for i, j in zip(a, a[1:]):
        if i != j:
            b.append(j)

    m = len(b)
    i = 0
    j = 1

    while i + 1 < m:
        while j + 1 < m:
            if (b[i + 1] - b[i]) * (b[j + 1] - b[j]) < 0:
                ans += 1
                i = j + 1
            j += 1

        i += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
  n= int(input())
  a = list(int(i) for i in input().split())
  ct = 0
  flag = 0
  for i in range(n-1):    
   if a[i+1] > a[i]:
    if flag == -1:
      ct+= 1
      flag = 0
    else:
      flag = 1
   elif a[i+1] < a[i]:
    if flag == 1:
      ct+= 1
      flag = 0
    else:
      flag = -1 
  return ct+1
  
  
if __name__ == '__main__':
  print(solve())

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

if N == 1:
    print(1)
else:
    divide = 0
    if A[0] < A[1]:
        up = 1
    elif A[0] > A[1]:
        up = -1
    else:
        up = 0
    for i in range(1,N-1):
        if A[i] == A[i+1]:
            continue
        elif A[i] < A[i+1]:
            if up < 0:
                divide += 1
                up = 0
            else:
                up = 1
                continue
        else:
            if up > 0:
                divide += 1
                up = 0
            else:
                up = -1
                continue
    print(divide+1)

Solution (Python):


import sys


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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()

    
    state = 0
    prev = A[0]
    res = 1
    for cur in A:
        if state:
            if state == 1 and prev > cur:
                res += 1
                state = 0
            if state == 2 and prev < cur:
                res += 1
                state = 0
        else:
            if prev < cur:
                state = 1
            if prev > cur:
                state = 2
        prev = cur

    return res


print(main())

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

flag = True
flag_=True 
ans = 0

for i in range(n-1):
  if flag == True:
    if a[i]==a[i+1]:
      continue
    elif a[i]< a[i+1]:
      flag_ = True
    elif a[i]> a[i+1]:
      flag_ = False
    flag = False
      
  else:
    if flag_ == True and a[i]<= a[i+1]:
      continue
    elif flag_ == False and a[i]>= a[i+1]:
      continue
    else:
      ans = ans +1
      flag = True
print(ans+1)

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

dif = []
for i in range(1,N):
    if A_arr[i] > A_arr[i-1]:
        dif.append(1)
    elif A_arr[i] < A_arr[i-1]:
        dif.append(-1)
    else:
        dif.append(0)

tmp = 0
count = 0
for i in range(len(dif)):
    if tmp * dif[i] == -1:
        count += 1
        tmp = 0
    elif dif[i] != 0:
        tmp = dif[i]
    else:
        pass

print(count+1)

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

s = 0
ans = 1
for i in range(1, N):
    d = A[i] - A[i - 1]
    if d * s < 0:
        ans += 1
        s = 0
        continue
    if d != 0:
        s = d
print(ans)

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



res = 0

prv = a[0]
cond = 0
for i in a:
    if cond == 0:
        if prv > i:
            cond = -1
        elif prv < i:
            cond = 1
    elif cond == 1:
        if prv > i:
            cond = 0
            res += 1
    else:
        if prv < i:
            cond = 0
            res += 1
    prv = i

print(res + 1)

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

for k in range(1,N):
    if A[k-1] > A[k]:
        t = -1
        break
    elif A[k-1] < A[k]:
        t = 1
        break
if t==0:
    print(1)
    exit(0)

k = 0
while k < N-1:
    k += 1
    if t == 1:
        if A[k-1] > A[k]:
            ans += 1
            while k+1<N and A[k]==A[k+1]:
                k += 1
            if k == N-1:
                break
            elif A[k] > A[k+1]:
                t = -1
            else:
                t = 1
    else:
        if A[k-1] < A[k]:
            ans += 1
            while k+1<N and A[k]==A[k+1]:
                k += 1
            if k == N-1:
                break
            elif A[k] > A[k+1]:
                t = -1
            else:
                t = 1

print(ans)

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

def search(nums, state):
    cur = nums[0]
    ans = 1
    for num in nums[1:]:
        if state == "up":
            if cur > num:
                ans += 1
                state = "neutral"
        
        elif state == "down":
            if cur < num:
                ans += 1
                state = "neutral"
        
        elif state == "neutral":
            if cur > num:
                state = "down"
            elif cur < num:
                state = "up"
            else:
                state = "neutral"
        
        cur = num
    return ans 
    
print(min(search(nums, "up"), search(nums, "down")))

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

def search(nums, state):
    cur = nums[0]
    ans = 1
    for num in nums[1:]:
        if state == "up":
            if cur > num:
                ans += 1
                state = "neutral"
        
        elif state == "down":
            if cur < num:
                ans += 1
                state = "neutral"
        
        elif state == "neutral":
            if cur > num:
                state = "down"
            elif cur < num:
                state = "up"
            else:
                state = "neutral"
        
        cur = num
    return ans 
    
print(min(search(nums, "up"), search(nums, "down")))

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

ans = 1
up = None
for a,b in zip(A,A[1:]):
    if a==b: continue
    if up is None:
        up = a<b
    elif up:
        if a>b:
            up = None
            ans += 1
    else:
        if a<b:
            up = None
            ans += 1
print(ans)

Solution (Python):
input()
a = [int(i) for i in input().split()]
mode = ''
cnt = 1
for i in range(len(a)-1):
  if mode == '' and a[i] < a[i+1]:
    mode = 'inc'
  elif mode == '' and a[i] > a[i+1]:
    mode = 'dec'
  elif mode == 'inc' and a[i] > a[i+1]:
    mode = ''
    cnt += 1
  elif mode == 'dec' and a[i] < a[i+1]:
    mode = ''
    cnt += 1
print(cnt)

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

    if flag == 1 and a[i] <= a[i+1]:
        continue
    if flag == 1 and a[i] > a[i+1]:
        flag = 0
        ans[i] = 1
        continue

    if flag == -1 and a[i] >= a[i+1]:
        continue
    if flag == -1 and a[i] < a[i+1]:
        flag = 0
        ans[i] = 1
        continue

print(ans.count(1))

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

ans = 1
up = None
for l, r in zip(a, a[1:]):
    if l == r:
        continue
    if l < r:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    else:
        if up is None:
            up = False
        elif up:
            ans += 1
            up = None

print(ans)

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

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

preva = None
mode = 0  
c = 0
for a in alist:
  if preva is None:
    preva = a
  elif mode == 0:
    if preva == a:
      continue
    if preva > a:
      mode = 2
    else:
      mode = 1
    preva = a
  elif mode == 1 and preva > a:
    c += 1
    preva = a
    mode = 0
  elif mode == 2 and preva < a:
    c += 1
    preva = a
    mode = 0
  else:
    preva = a
print(c + 1)

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

count = 0
sign = 0
num = 0
ans = 0
for i, ai in enumerate(a):
    if count == 0:
        num = ai
        sign = 0
        count += 1
    elif count == 1:
        if ai > num:
            sign = 1
        elif ai < num:
            sign = -1
        else:
            sign = 0
        count += 1
        num = ai
    else:
        if sign == 0:
            if ai > num:
                sign = 1
            elif ai < num:
                sign = -1
            else:
                sign = 0
            count += 1
            num = ai
        elif sign > 0:
            if ai < num:
                num = ai
                count = 1
                sign = 0
                ans += 1
            else:
                num = ai
        else:
            if ai > num:
                num = ai
                count = 1
                sign = 0
                ans += 1
            else:
                num = ai

if count > 0:
    ans += 1

print(ans)

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

ans = 1
up = None
for a,b in zip(A,A[1:]):
    if a==b: continue
    if a<b:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    else:
        if up is None:
            up = False
        elif up:
            ans += 1
            up = None
print(ans)

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

if n==1:
    print(1)
else:
    mode = None
    ans = 1
    for i in range(n-1):
        if aa[i] != aa[i+1]:
            if mode == None:
                mode = aa[i]<aa[i+1]
            elif (aa[i] < aa[i+1]) != mode:
                ans+=1
                mode = None
        
    print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(1)
else:
    u=a[0]<=a[1]
    d=a[0]>=a[1]
    res=0
    for i in range(2,n):
        u=u and a[i-1]<=a[i]
        d=d and a[i-1]>=a[i]
        
        if not any([u,d]):
            res+=1
            u=True
            d=True
    print(res+1)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
def C(n,A):
    if n==1 or n==2:
        return 1
    else:
        cnt=1
        d=A[1]-A[0]
        for i in range(2,n):
            if d:
                if (A[i]-A[i-1])*d<0:
                    cnt+=1
                    d=0
            else:
                d=A[i]-A[i-1]
        return cnt
print(C(n,A))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt = 0
id = 1
while a != []:
    if len(a)==1:
        cnt += 1
        break
    if a[0] == a[1]:
        while a[id-1] == a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
        if id == n:
            cnt = 1
            break
        del(a[:id-1])
        id = 1
    if a[0] > a[1]:
        while  a[id-1] >= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    elif a[0] < a[1]:
        while a[id-1] <= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    cnt += 1
    del(a[:id])
    id = 1


print(cnt)

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

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

Solution (Python):


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

c = 1
e = 0
for i in range(N-1):
    d = A[i+1]-A[i]
    
    
    if e*d < 0:
        c += 1
        e = 0
    elif d != 0: 
        e = d

print(c)

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

s = 0
c = 0
for i in range(1,N):
    d = A[i] - A[i-1]
    if d * s < 0:
        c += 1
        s = 0
        continue
    if d != 0:
        s = d
print(c+1)

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

ans = 0
diff = 0
for i in range(1, n):
  tmp_diff = a[i] - a[i - 1]
  if tmp_diff != 0 and diff == 0:
    diff = tmp_diff
    continue
  if not(tmp_diff == 0 or tmp_diff * diff > 0):
    ans += 1
    diff = 0
    continue
print(ans + 1)

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

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

print(ans)

Solution (Python):
def solve(N, As):
    increasing = None
    ans = 1
    for a1, a2 in zip(As, As[1:]):
        if increasing is None:
            if a1 < a2:
                increasing = True
            elif a1 > a2:
                increasing = False
        else:
            if a1 == a2 or (a1 < a2 and increasing) or (a1 > a2 and not increasing):
                pass
            else:
                ans += 1
                increasing = None
    return ans


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))