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())
ls = list(map(int, input().split()))

ans = 0
flagu = 0
flagd = 0

for i in range(n):
	if i == 0:
		continue
	elif ls[i - 1] < ls[i]:
		if flagd == 1:
			ans += 1
			flagu = 0
			flagd = 0
		elif flagu == 0:
			flagu = 1
	elif ls[i - 1] > ls[i]:
		if flagu == 1:
			ans += 1
			flagu = 0
			flagd = 0
		elif flagd == 0:
			flagd = 1
	
	if i == n - 1:
		ans += 1

if n == 1:
	print(1)
else:
	print(ans)

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

UNIA = []
b = ''
for i in range(N):
    if A[i] == b:
        continue
    else:
        UNIA.append(A[i])
        b = A[i]








up = None
ans = 1
for i in range(len(UNIA)-1):
    if up is None:
        if UNIA[i] < UNIA[i+1]:
            up = True
        else:
            up = False
    elif up:
        if UNIA[i] < UNIA[i+1]:
            continue
        else:
            up = None
            ans += 1
    else:
        if UNIA[i] < UNIA[i+1]:
            up = None
            ans += 1

print(ans)

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

flg = 0 
prev = -1

cnt = 0
for a in A:
  if flg == 0 and prev==-1:
    prev = a
    cnt += 1
  elif flg==0 and not prev==-1:
    if a > prev:
      flg = 1
      prev = a
    elif a < prev:
      flg = -1
      prev = a
  elif flg == 1:
    if a < prev:
      flg = 0
      prev = a
      cnt +=1
    else:
      prev = a
  elif flg == -1:
    if a > prev:
      flg = 0
      prev = a
      cnt +=1
    else:
      prev = a
  
print(cnt)

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

flg = None
cur = a[0]
cnt = 1

for v in a[1:]:
  if v > cur:
    if flg is None:
      flg = True
    if not flg:
      flg = None
      cnt += 1
  if v < cur:
    if flg is None:
      flg = False
    if flg:
      cnt += 1
      flg = None
  cur = v
print(cnt)

Solution (Python):
n = int(input())
lst = list(map(int,input().split()))
if n==1 or n==2:
    print(1)
else:
    cnt = 0
    num = lst[0]
    mode = 0
    for i in range(1,n):
        if mode==0:
            if lst[i]==num:
                continue            
            elif lst[i] > num:
                mode = 1
            elif lst[i] < num:
                mode = 2
        elif mode == 1:
            if lst[i] < num:
                cnt += 1
                mode = 0
        elif mode == 2:
            if lst[i] > num:
                cnt += 1
                mode = 0
        num = lst[i]
    print(cnt + 1)

Solution (Python):


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

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

increase_flg = False
decrease_flg = False
ans = 1

for i in range(1, N):
    if A[i] > A[i-1] and not decrease_flg:
        increase_flg = True
    elif A[i] > A[i-1] and decrease_flg:
        decrease_flg = False
        increase_flg = False
        ans += 1
    elif A[i] < A[i-1] and not increase_flg:
        decrease_flg = True
    elif A[i] < A[i-1] and increase_flg:
        increase_flg = False
        decrease_flg = False
        ans += 1

print(ans)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
now = As[0]
shape = 0
ans = 1
for i in As:
    if shape == 0:
        if i  > now:
            shape = 1
            now = i
        elif i < now:
            shape = 2
            now = i
    elif shape == 1:
        if i < now:
            shape = 0
            now = i
            ans += 1
        else:
            now = i
    else:
        if i > now:
            shape = 0
            now = i
            ans += 1
        else:
            now = i
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=1
b=[]
for i in range(n-1):
    a0=a[i+1]-a[i]
    if a0!=0:
        b.append(a0)
if len(b)>1:
    i=0
    while i<len(b)-1:
        if b[i]*b[i+1]<0:
            ans+=1
            i+=1
        i+=1
print(ans)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
bit = 0
ans = 1
i = 0
while i < n-1:
    if a[i+1] == a[i]: pass
    if bit == 0:
        bit = a[i+1]-a[i]
        
    else:
        if bit * (a[i+1]-a[i]) < 0:
            bit = 0 
            ans += 1 
    i += 1
print(ans)

Solution (Python):
n=int(input())
*a,=map(int,input().split())
cnt=0
mode=0
for i in range(n-1):
    if mode==0:
        if a[i]<a[i+1]:
            cnt+=1
            mode="inc"
        elif a[i]>a[i+1]:
            cnt+=1
            mode="dec"
    if a[i]<a[i+1]:
        if mode=="inc":
            pass
        else:
            mode=0
    elif a[i]>a[i+1]:
        if mode=="dec":
            pass
        else:
            mode=0
if mode==0:
    print(cnt+1)
else:
    print(cnt)

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

def ans(x,L):
    ans = 1
    flag = 0
    tmp = L[0:2]
    if tmp[0] < tmp[1]:
        flag  = 1
    elif tmp[0] > tmp[1]:
        flag = -1
    for i in range(2,n):
        tmp.append(L[i])
        if len(tmp) == 1:
            pass
        elif (flag == -1 and tmp[-2] < tmp[-1]) or (flag == 1 and tmp[-2] > tmp[-1]):
            ans += 1
            flag = 0
            tmp = [tmp[-1]]
        elif flag == 0 and tmp[-2] < tmp[-1]:
            flag = 1
        elif flag == 0 and tmp[-2] > tmp[-1]:
            flag = -1
    return(ans)
if n <= 2:
    print(1)
else:
    print(ans(n,l))

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

count = 1
is_up = False
is_down = False
for i in range(1, n):
    if a[i] < a[i-1] and is_up:
        count += 1
        is_up = False
    elif a[i] > a[i-1] and is_down:
        count += 1
        is_down = False
    elif a[i] < a[i-1]:
        is_down = True
    elif a[i] > a[i-1]:
        is_up = True
print(count)

Solution (Python):
N = int(input())
array = list(map(int, input().split()))
ans = 1
rels = []
if N == 1:
    print(1)
    exit()
for i in range(1, N):
    a, b = array[i], array[i-1]
    if b < a:
        rels.append("<")
    if b > a:
        rels.append(">")
    if a == b:
        rels.append("=")
now = rels[0]
skip = False
for i in range(N-1):
    rel = rels[i]
    if skip:
        skip = False
        now = rel
        continue
    if rel == now or rel == "=":
        continue
    elif now == "=":
        now = rel
    else:
        skip = True
        ans += 1


print(ans)

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
mode = 0 
res = 1
for i in range(1, n):
    if mode == 0:
        if dat[i-1] == dat[i]:
            mode = 0
        if dat[i-1] > dat[i]:
            mode = 2
        if dat[i-1] < dat[i]:
            mode = 1
    if mode == 1:
        if dat[i-1] == dat[i]:
            pass
        if dat[i-1] > dat[i]:
            res += 1
            mode = 0
        if dat[i-1] < dat[i]:
            pass
    if mode == 2:
        if dat[i-1] == dat[i]:
            pass
        if dat[i-1] > dat[i]:
            pass
        if dat[i-1] < dat[i]:
            res += 1
            mode = 0
print(res)

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

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

ans = 1
inc = False
dec = False
before = A[0]
for a in A:
    if not inc and not dec:
        if a > before:
            inc = True
        if a < before:
            dec = True
    elif inc:
        if a < before:
            ans += 1
            inc = False
    elif dec:
        if a > before:
            ans += 1
            dec = False
    before = a
print(ans)

Solution (Python):


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

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

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

count = 1
sign = 0
for i in range(n - 1):
    if sign == 0:
        sign = (ass[i + 1] - ass[i]) 
    else:
        if (ass[i + 1] - ass[i]) * sign < 0:
            count += 1
            sign = 0
print(count)

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
pops = []


ans = 0

mnd = True
first = True
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if first and b[i] != b[i-1]:
        mnd = b[i-1] < b[i]
        first = False
    if mnd and b[i-1] > b[i]:
        ans += 1
        first = True
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        first = True
print(ans+1)

Solution (Python):
N,*A=map(int, open(0).read().split())
st=0
ans=1
for i,a in enumerate(A):
    if st==1:
        if A[i-1]>a:
            st=0
            ans+=1
    elif st==-1:
        if A[i-1]<a:
            st=0
            ans+=1
    elif st==0 and i!=0:
        p=A[i-1]
        if p<a:
            st=1
        elif p>a:
            st=-1
print(ans)

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

ans = 0
if 2 <= N:
    isBigger = A[0] < A[1] 
    isEqual = A[0] == A[1]
    for i in range(1,N):
        if isEqual:
            if A[i] < A[i-1]:
                isBigger = False
                isEqual = False
            elif A[i-1] < A[i]:
                isBigger = True
                isEqual = False
            else:
                continue
        elif isBigger:
            if A[i] < A[i-1]:
                ans += 1
                if i < N-1:
                    isBigger = A[i] < A[i+1]
                    isEqual = A[i] == A[i+1]
                else:
                    break
        else:
            if A[i-1] < A[i]:
                ans += 1
                if i < N-1:
                    isBigger = A[i] < A[i+1]
                    isEqual = A[i] == A[i+1]
                else:
                    break

ans += 1
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
f = None
count = 1
for i in range(N - 1):
    if f is None:
        if a[i] < a[i + 1]:
            f = 1
        elif a[i] > a[i + 1]:
            f = -1
        continue

    if (f == 1 and a[i] > a[i + 1]) or (f == -1 and a[i] < a[i + 1]):
        count += 1
        f = None

print(count)

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

c = 1
m = a[0]

s = 1 

for i in a:
    if m == i:
        continue
    elif m > i:
        if s == 2:
            s = 1
            c += 1
        else:
            s = 0
    else:
        if s == 0:
            s = 1
            c += 1
        else:
            s = 2
    m = i

print(c)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
plus=0
minus=0
ans=1
for i in range(N-1):
    plus += A[i]<A[i+1]
    minus += A[i]>A[i+1]
    if plus and minus:
        ans += 1
        plus = 0
        minus = 0
print(ans)

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

ans = 1
up, dn = False, False
for i in range(N-1):
    if A[i] < A[i+1]:
        up = True
    elif A[i] > A[i+1]:
        dn = True
    if up and dn:
        ans += 1
        up, dn = False, False
print(ans)

Solution (Python):
N=int(input())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]
for i in range (1,N):
  if p[i]!=p[i-1]:
    q.append(p[i])
    size+=1
j=0
while True:
  if j>=size-2:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    if j>=size-3:
      count-=1
      break
    j+=1    
  count+=1
  j+=2
print(count)

Solution (Python):
import sys

input=sys.stdin.readline

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

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

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

state_plus = False
state_minus = False
state_flat = True
count = 0

for i in range(N-1):
    
    if state_flat:
        if A[i + 1] > A[i]:
            state_flat = False
            state_plus = True
        elif A[i + 1] < A[i]:
            state_flat = False
            state_minus = True
    elif state_plus:
        if A[i] > A[i + 1]:
            state_plus = False
            state_flat = True
            count += 1
    elif state_minus:
        if A[i] < A[i + 1]:
            state_minus = False
            state_flat = True
            count += 1
    

print(count + 1)

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

ans = 0
pos = 0
pos1 = 0
pos2 = 0

while True:
    if pos==N:
        break
    pos1 = pos
    pos2 = pos
    while pos1<N-1 and A[pos1] <= A[pos1+1]:
        pos1 +=1

    while pos2<N-1 and A[pos2] >= A[pos2+1]:
        pos2 +=1

    large = max(pos1, pos2)
    pos = large+1
    ans += 1
print(ans)

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

con = 0
state = "FLAT"

for i in range(0,N - 1):
  if state == "FLAT":
    if A[i + 1] > A[i]:
      state = "INCREASE"
    elif A[i + 1] < A[i]:
      state = "DECREASE"
  elif state == "INCREASE":
    if A[i + 1] < A[i]:
      con += 1
      state = "FLAT"
  elif state == "DECREASE":
    if A[i + 1] > A[i]:
      con += 1
      state = "FLAT"
  
      
print(con + 1)

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

ans = 1
last = A[0]
n = 0
for i in A:
    if n == 0:
        if last < i:
            n = 1
        elif last > i:
            n = -1
        else:
            n = 0
    elif n == 1:
        if last >  i:
            ans += 1
            n = 0
    else:
        if last < i:
            ans += 1
            n = 0
    last = i

print(ans)

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

ans = 1
A0 = list_A[0]
flag = 0

for i in range(1,len(list_A)) :
    if list_A[i] > list_A[i-1] :
        if flag == 0 :
            flag = 1
        elif flag == 1 :
            pass
        else :
            ans += 1
            flag = 0
    elif list_A[i] < list_A[i-1] :
        if flag == 0 :
            flag = -1
        elif flag == 1 :
            ans += 1
            flag = 0
        else :
            pass
    else :
        pass

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    inc_flag = None
    dec_flag = None
    ans = 0
    for i in range(1, N):
        if inc_flag is None and dec_flag is None and a_list[i-1] < a_list[i]:
            inc_flag = True
        elif inc_flag is None and dec_flag is None and a_list[i-1] > a_list[i]:
            dec_flag = True
        elif inc_flag is True and a_list[i-1] > a_list[i]:
            ans += 1
            inc_flag = None
        elif dec_flag is True and a_list[i-1] < a_list[i]:
            ans += 1
            dec_flag = None
    print(ans + 1)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    now = A[0]
    count = 0
    upflag = False
    downflag = False
    for i in range(1,N):
        if upflag:
            if A[i] - now < 0:
                upflag = False
                downflag = False
        elif downflag:
            if A[i] - now > 0:
                downflag = False
                upflag = False
        else:
            if A[i] - now > 0:
                upflag = True
                count += 1
            elif A[i] - now < 0:
                downflag = True
                count += 1
        now = A[i]
    if not (upflag or downflag):
        count += 1
    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
def d(i, j):
    if i == j:
        return "z"
    if i < j:
        return "p"
    else:
        return "m"

n = int(input())
a = [int(x) for x in input().split()]
if n < 3: print(1)
else:
    ans = 1
    s = d(a[0], a[1])
    for i in range(1, n):
        tmp = d(a[i-1], a[i])
        if tmp == "z": continue
        elif s == tmp: continue
        else:
            if s == "z":
                s = tmp
                continue
            else:
                s = "z"
                ans += 1
    print(ans)

Solution (Python):




N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))

flag_plus_minus = ""
count = 0
if len(A_list) == 1:
    count = 1
else:

    for i in range(len(A_list)-1):
        diff = A_list[i+1] - A_list[i]
    
        if flag_plus_minus == "" :
            flag_plus_minus = str((diff > 0) - (diff < 0))
            count += 1

        if flag_plus_minus == "0" :
            flag_plus_minus = str((diff > 0) - (diff < 0))
        
        if flag_plus_minus != "" and A_list[i] != A_list[i+1] :
            if ( diff * int(flag_plus_minus) ) < 0:
                flag_plus_minus = ""
                
                if i == (len(A_list)-1) - 1:
                    count += 1
        
print(count)

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

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

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

cnt = 0
mode = 0

for i in range(len(A)):
    if i == 0:
        continue
    
    if (A[i] - A[i-1] >= 0 and mode >=0) or (A[i] - A[i-1] <= 0 and mode <= 0):
        if A[i] - A[i-1] > 0:
            mode = 1
        if A[i] - A[i-1] < 0:
            mode = -1
    else:
        mode = 0
        cnt += 1

print(cnt+1)

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

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

ans = 1

tp = a[0]
flag = 0  
for i in range(1, n):
    t = a[i]
    if (flag == 0):
        if (t > tp):
            flag = 1
        elif (t < tp):
            flag = 2
        else:
            flag = 0
    elif(flag == 1):
        if (t < tp):
            ans += 1
            flag = 0
    elif(flag == 2):
        if (t > tp):
            ans += 1
            flag = 0
    tp = t

print(ans)

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

flag = 0
 
ans = 1
for i in range(n - 1):
  if flag == 1:
    if a[i] > a[i + 1]:
      ans += 1
      flag = 0
  elif flag == -1:
    if a[i] < a[i + 1]:
      ans += 1
      flag = 0
  else:
    if a[i] > a[i + 1]:
      flag = -1
    elif a[i] < a[i + 1]:
      flag = 1
print(ans)

Solution (Python):

def pin(type=int):
    return map(type,input().split())

"""
方針

    これにて非単調減少・増加を単調増加、単調減少として捉えられる


"""


N=int(input())
A=list(pin())
B=[(A[j+1]-A[j])for j in range(len(A)-1)]
C=[]
for i in range(len(B)):
    if B[i]!=0:
        C.append(B[i])

k=0
ans=0



while(k<len(C)-1):
    
    if C[k+1]*C[k]<0:
        
        k+=1
        ans+=1
    k+=1
print(ans+1)

Solution (Python):
'''
先頭から値を確認していき、値が増加/減少した後に値が減少/増加した場合に数列の分割数を増やす
'''

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

ans = 1
flg = 0
for i in range(N-1):
    if flg == 0:
        if A[i+1] > A[i]:
            flg = 1
        elif A[i+1] < A[i]:
            flg = -1
        else:
            pass
    elif flg == 1:
        if A[i+1] > A[i]:
            pass
        elif A[i+1] < A[i]:
            flg = 0
            ans += 1
        else:
            pass
    else:
        if A[i+1] > A[i]:
            flg = 0
            ans += 1
        elif A[i+1] < A[i]:
            pass
        else:
            pass

print(ans)

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

mode = 0
ans = 1
for i in range(0, n-1):
    if mode == 0:
        if a[i] < a[i+1]:
            mode = 1
        elif a[i] > a[i+1]:
            mode = 2
    elif mode == 1:
        if a[i] > a[i+1]:
            ans += 1
            mode = 0
    else:
        if a[i] < a[i+1]:
            ans += 1
            mode = 0

print(ans)

Solution (Python):
n = int(input())
ais = list(map(int, input().split()))
if len(ais) == 1:
  print(1)
  quit()
if ais[0] < ais[1]:
  tend = 1
elif ais[0] > ais[1]:
  tend = -1
else:
  tend = 0
pref = ais[1]
ans = 1
for a in ais[2:]:
  if pref < a and tend == -1:
    ans += 1
    tend = 0
  elif pref > a and tend == 1:
    ans += 1
    tend = 0
  elif tend == 0:
    if pref < a:
      tend = 1
    elif pref > a:
      tend = -1
    elif pref == a:
      pass
  pref = a
print(ans)

Solution (Python):

N = int(input())

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

ans = 1
q = []

for i,a in enumerate(A):

    if len(q) != 0 and ( (q[0] < q[-1] and q[-1] > a) or (q[0] > q[-1] and q[-1] < a) ):
        q = [a]
        ans += 1

    else:
        q.append(a)

print (ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()
cnt=0
if n==1:
    print(1)
    exit()

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = float('inf')
up = -1
count = 0
for i in range(N-1):
    if A[i] > A[i+1]:
        if up == -1:
            up = 0
        elif up == 1:
            up = -1
            count += 1
    elif A[i] < A[i+1]:
        if up == -1:
            up = 1
        elif up == 0:
            up = -1
            count += 1
print(count+1)

Solution (Python):
def examA():
    N = I()
    A = LI()
    ans = 1
    flag = None
    for i in range(N-1):
        cur = A[i+1] - A[i]
        if not flag:
            if cur<0:
                flag = "d"
            elif cur>0:
                flag = "u"
        else:
            if cur<0 and flag=="u":
                flag = None
                ans += 1
            elif cur>0 and flag=="d":
                flag = None
                ans += 1
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

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

ans = 0
i = 0
while i < N:
    j = i + 1
    t = 0
    while j < N:
        if A[j - 1] == A[j]:
            j += 1
            continue
        elif t == 0 and A[j - 1] != A[j]:
            t = (A[j] - A[j - 1]) / abs(A[j] - A[j - 1])
        elif t != 0 and t != (A[j] - A[j - 1]) / abs(A[j] - A[j - 1]):
            break
        j += 1
    ans += 1
    i = j

print(ans)

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

state = 0
m = A[0]
ans = 1

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

print(ans)

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

ans = 1


state = 0
m = A[0]

i = 1
while i <= N-1:
    if m < A[i]:
        if state == 0:
            state = 1
        elif state == 2:
            ans += 1
            state = 0
    elif m > A[i]:
        if state == 0:
            state = 2
        elif state == 1:
            ans += 1
            state = 0
    m = A[i]
    i += 1

print(ans)

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

ans = 1


state = 0
m = A[0]

i = 1
while i <= N-1:
    if m < A[i]:
        if state == 0:
            state = 1
            m = A[i]
        elif state == 1:
            m = A[i]
        else:
            ans += 1
            state = 0
            m = A[i]
    elif m > A[i]:
        if state == 0:
            state = 2
            m = A[i]
        elif state == 1:
            ans += 1
            state = 0
            m = A[i]
        else:
            m = A[i]
    i += 1
print(ans)

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

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

up=0
down=0
count = 0
x=a[0]
for i in range(n):
  if x==a[i]:
    continue
  elif x<a[i]:
    if down==0:
      up=1
    else:
      down=0
      up=0
      count+=1
  else:
    if up==0:
      down=1
    else:
      down=0
      up=0
      count+=1
  x=a[i]
print(count+1)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    N = Scanner.int()
    A = Scanner.map_int()
    add = 0
    ans = 1
    i = 0
    while i < N-1:
        if add == 0:
            add = 1 if A[i] < A[i + 1] else -1 if A[i] > A[i+1] else 0
        elif add == 1:
            if A[i] > A[i + 1]:
                add = 0
                ans += 1
        else:
            if A[i] < A[i+1]:
                add = 0
                ans += 1
        i += 1
    print(ans)
    return


if __name__ == "__main__":
    main()

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

flag = 0
cnt = 1

for i in range(n-1):
    if a[i] < a[i+1] and flag == 0:
        flag = 1
    elif a[i] > a[i+1] and flag == 0:
        flag = 2
    elif flag == 1 and a[i] > a[i+1]:
        cnt += 1
        flag = 0
    elif flag == 2 and a[i] < a[i+1]:
        cnt += 1
        flag = 0

print(cnt)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    b = 0
    count = 1
    for i in range(N-1):
        if b == 0:
            if a[i+1]-a[i] > 0:
                b = 1
            elif a[i+1] == a[i]:
                continue
            else:
                b = -1
        elif b == 1:
            if a[i+1]-a[i] >= 0:
                continue
            else:
                count += 1
                b = 0
        else:
            if a[i+1] <= a[i]:
                continue
            else:
                count += 1
                b = 0
                
    print(count)
    
if __name__ == "__main__":
    main()