TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):
N = int(input())
A = [0] * N
for i in range(N):
	A[i] = int(input())

for j in range(1, N):
	if A[j] in A[: j]:
		A[A[: j].index(A[j])] = -1
		A[j] = -1


print(len([k for k in A if k != -1]))


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

change = 0  # 1, 0, -1
ans = 1

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

print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n, *lst = map(int, open(0).read().split())
if n < 3:
  print(1)
  quit()
group = 0
start = (lst[1] >= lst[0])
for i in range(2, n - 1):
  if (lst[i] >= lst[i - 1]) != start:
    start = (lst[i + 1] >= lst[i])
    group += 1
if (lst[-1] >= lst[-2]) != start:
  group += 1
if group != 0:
  group += 1
print(group)


n, *lst = map(int, open(0).read().split())
if n < 3:
  print(0)
  quit()
group = 0
start = lst[1] >= lst[0]
for i in range(2, n - 1):
  if (lst[i] >= lst[i - 1]) != start:
    start = (lst[i + 1] > lst[i])
    group += 1
if (lst[-1] >= lst[-2]) != start:
  group += 1
if group != 0:
  group += 1
print(group)

n, *lst = map(int, open(0).read().split())
if n < 3:
  print(0)
  quit()
group = 0
start = (lst[1] >= lst[0])
for i in range(2, n - 1):
  if (lst[i] >= lst[i - 1]) != start:
    start = (lst[i + 1] >= lst[i])
    group += 1
if (lst[-1] >= lst[-2]) != start:
  group += 1
if group != 0:
  group += 1
print(group)

n, *lst = map(int, open(0).read().split())
if n < 3:
  print(1)
  quit()
group = 1
start = (lst[1] >= lst[0])
for i in range(2, n - 1):
  if (lst[i] >= lst[i - 1]) != start:
    start = (lst[i + 1] >= lst[i])
    group += 1
if (lst[-1] >= lst[-2]) != start:
  group += 1
print(group)


_, *A = map(int, open(0).read().split())
ans = 1
is_add = False
is_minus = False
tmp = A[0]
for a in A[1:]:
  if tmp > a:
    if is_add:
      ans += 1
      is_add = False
    else:
      is_minus = True
  elif tmp < a:
    if is_minus:
      ans += 1
      is_minus = False
    else:
      is_add = True
  tmp = a
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):

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=1
    elif A[i] < prev:
        if direction==0:
            direction=-1
        elif direction==1:
            count+=1
            direction=1
    prev=A[i]
    
print(count)

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)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
L = list(map(int, input().split()))

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
dec_cnt = 0
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        print(d)
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1] and d[i - 1] < 0):
            cnt += 1


print(cnt)


n = int(input())
L = list(map(int, input().split()))

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
            if (d[i - 1] == 0):
                cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
            if (d[i - 1] == 0):
                cnt += 1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1]):
            continue

print(cnt)


n = int(input())
L = list(map(int, input().split()))

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1]):
            d[i] = 1
        elif (L[i] > L[i + 1]):
            d[i] = -1

prev = 0
count = 0
for i in range(len(d)):
    if (i == 0):
        prev = d[i]
        continue
    if (prev == 1):
        if (d[i] == 1):
            continue
        elif (d[i] == 0):
            continue
        else:
            count += 1
            prev = 0
    elif (prev == -1):
        if (d[i] == -1):
            continue
        elif (d[i] == 0):
            continue
        else:
            count += 1
            prev = 0
    elif (prev == 0):
        if (d[i] == 1):
            prev = 1
        elif (d[i] == -1):
            prev = -1

print(count + 1)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,*A=map(int,open(0).read().split());f=a=0
for i,j in zip(A,A[1:]):
 if f:
  if(f<0)&(i<j)|(0>f)&(i>j):a+=1;f=0
 else:f=(i<j)-(i>j)
print(a+1)

N,*A=map(int,open(0).read().split());f=a=0
for i,j in zip(A,A[1:]):
 if f:
  if(f<0)&(i<j)|(f>0)&(i>j):a+=1;f=0
 else:f=(i<j)-(i>j)
print(a+1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
# coding: utf-8
# Your code here!
_=int(input())
A=list(map(int,input().split()))
N=len(A)

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


# coding: utf-8
# Your code here!
_=int(input())
A=list(map(int,input().split()))
N=len(A)

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

print(ans if trend!=0 else ans+1)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>0:
        return +1
    elif x<0:
        return -1
    else:
        return 0

ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if get_sign(a-a1)==get_sign(a1-a0):
            a0 = a1
            a1 = a
        elif get_sign(a-a1)==0:
            pass
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>=0:
        return +1
    else:
        return -1
            
ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if get_sign(a-a1)==get_sign(a1-a0):
            a0 = a1
            a1 = a
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>0:
        return +1
    elif x<0:
        return -1
    else:
        return 0

ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if (get_sign(a-a1)==get_sign(a1-a0))|(get_sign(a-a1)==0):
            a0 = a1
            a1 = a
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>0:
        return +1
    elif x<0:
        return -1
    else:
        return 0

ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if (get_sign(a-a1)==get_sign(a1-a0))|(get_sign(a1-a0)==0):
            a0 = a1
            a1 = a
        elif get_sign(a-a1)==0:
            pass
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N=int(input())
a=list(map(int,input().split()))
diff=[a[i+1]-a[i] for i in range(N-1)]
ans=[0,0]

for i in range(N-1):
  if diff[i]<0:
    ans[0]+=1
  elif diff[i]>0:
    ans[1]+=1
print(min(ans)+1)


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

    

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
def main():
    # N = int(input())
    # A = [int(a) for a in input().split()]

    f = open("subtask_1_02.txt", "r")
    N = int(f.readline())
    A = [int(a) for a in f.readline().split()]

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx + 1 > len(A) - 1 :
            break

        m = ""
        if A[idx] < A[idx + 1]:
            m = "+"
        elif A[idx] > A[idx + 1]:
            m = "-"
        else:
            find = False
            for j in range(idx, len(A)-1):
                if A[j] < A[j + 1]:
                    m = "+"
                    find = True
                    idx = j
                    break
                elif A[j] > A[j + 1]:
                    m = "-"
                    find = True
                    idx = j
                    break
            if find == False:
                print(ans + 1)
                exit()

        for j in range(idx, len(A) - 1):
            if m == "+":
                if A[j] <= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break
            elif m == "-":
                if A[j] >= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break

    print(ans + 1)

if __name__ == "__main__":
    main()

def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx + 1 > len(A) - 1 :
            break

        m = ""
        if A[idx] < A[idx + 1]:
            m = "+"
        elif A[idx] > A[idx + 1]:
            m = "-"
        else:
            find = False
            for j in range(idx, len(A)-1):
                if A[j] < A[j + 1]:
                    m = "+"
                    find = True
                    idx = j
                    break
                elif A[j] > A[j + 1]:
                    m = "-"
                    find = True
                    idx = j
                    break
            if find == False:
                print(ans + 1)
                exit()

        for j in range(idx, len(A) - 1):
            if m == "+":
                if A[j] <= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break
            elif m == "-":
                if A[j] >= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break

    print(ans + 1)

if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split))
# N = 9
# A = [1, 2, 1, 2, 1, 2, 1, 2, 1]
# N = 7
# A = [1, 2, 3, 2, 1, 999999999, 1000000000]
# N = 6
# A = [1, 2, 3, 2, 2, 1]
# N = 2
# A = [1, 1]
A = A + [A[-1]]

d = 0
i = 0

inc = None
while i < N:
    if inc is None:
        if A[i] < A[i + 1]:
            inc = True
            d += 1
        elif A[i] > A[i + 1]:
            inc = False
            d += 1
        else:
            inc = None
    else:
        if inc:
            if A[i] > A[i + 1]:
                inc = None
        else:
            if A[i] < A[i + 1]:
                inc = None
    i += 1

if inc is None:
    d += 1
print(d)


N = int(input())
A = list(map(int, input().split()))
# N = 9
# A = [1, 2, 1, 2, 1, 2, 1, 2, 1]
# N = 7
# A = [1, 2, 3, 2, 1, 999999999, 1000000000]
# N = 6
# A = [1, 2, 3, 2, 2, 1]
# N = 2
# A = [1, 1]
A = A + [A[-1]]

d = 0
i = 0

inc = None
while i < N:
    if inc is None:
        if A[i] < A[i + 1]:
            inc = True
            d += 1
        elif A[i] > A[i + 1]:
            inc = False
            d += 1
        else:
            inc = None
    else:
        if inc:
            if A[i] > A[i + 1]:
                inc = None
        else:
            if A[i] < A[i + 1]:
                inc = None
    i += 1

if inc is None:
    d += 1
print(d)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

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

res = 0

in_i = 0
de_i = 0
i = 0
while i <= N-1:
    for j in range(i+1,N):
        if A[j] >= A[j-1]:continue
        else:
            break

    in_i = j
    for j in range(i+1,N):
        if A[j] <= A[j-1]:continue
        else:
            break
    de_i = j

    i = max(de_i,in_i)
    res+=1
print(i)

print(res)



import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

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





State = 0


res = 1

for i in range(1,N):
    
    

    
    
    
    
    if A[i] > A[i-1]: 
        X = 1 
    elif A[i] == A[i-1]: 
        X = 0
    else :
        X = -1

    
    if X == State:
        continue
    
    
    if  State == 0: 
        State = X 

    
    if X != State  and  X != 0: 
        res += 1 
        State = 0 

print(res)




Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

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

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)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
a = list(map(int,input().split(" ")))

c = 1

t = a[0]
for i in a[1:]:
	if t > i:
		c += 1
	t = i

print(c)



















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

l = [[] for i in range(N)]
c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t > i:
		l[s].append((s,c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((s,c))

c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t < i:
		l[s].append((s,c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((s,c))

for i in range(N):
	l[i].sort()

now = 0
res = 0
while now < N:
	now = l[now][-1][1]+1
	res+=1

print(res)

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


l = [[] for i in range(N)]
c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t > i:
		l[s].append((c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((c))

c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t < i:
		l[s].append((c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((c))

l[0] = max(l[0])
for i in range(1,N):
	l[i].append(-1)
for i in range(1,N):
	
	if i!=N-1:
		l[i+1].append(-1)
		l[i] = max(l[i-1],max(l[i]),max(l[i+1]))
	else:
		l[i] = max(l[i-1],max(l[i]))


now = 0
res = 0

while now<N-1:
	now = l[now]	
	res+=1
if N==1:
	print(1)
	exit()
print(res)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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:
    prnt(cnt)

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)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
a = A[::]

count = 1
while len(a) > 1:
    first_tilt = 0
    for i in range(1, len(a)):
        if a[i] - a[i - 1] > 0:
            first_tilt = 1
            break
        if a[i] - a[i - 1] < 0:
            first_tilt = -1
            break

    if first_tilt == 1:
        for i in range(1, len(a)):
            if a[i] - a[i-1] < 0:
                a = a[i:]
                count += 1
                break
            if len(a)-1 == i:  
                a = a[i:]

    if first_tilt == -1:

        for i in range(1, len(a)):
            print(i, a[i])
            if a[i] - a[i-1] > 0:
                a = a[i:]
                count += 1
                break
            if len(a)-1 == i:  
                a = a[i:]

print(count)

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

count = 1
state = 0
for i in range(N-1):
    diff = A[i+1] - A[i]
    if state == 0:
        if diff > 0:
            state = 1
            continue
        if diff == 0:
            state = 0
            continue
        if diff < 0:
            state = -1
            continue
    if state == 1:
        if diff > 0:
            state = 1
            continue
        if diff == 0:
            state = 1
            continue
        if diff < 0:
            count += 1
            state = 0
            continue
    if state == -1:
        if diff > 0:
            count += 1
            state = 0
            continue
        if diff == 0:
            state = -1
            continue
        if diff < 0:
            state = -1
            continue

print(count)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
a,s=0,0
for i in range(1,n+1):
  fa,fs=1,1
  if l[i-1]<=l[i]:fa=0
  if l[n-i]>=l[n-i+1]:fs=0
  a+=fa
  s+=fs
print(min(a,s)+1)

n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1:print(1);exit()
from itertools import groupby as gb
l=[a for a,b in gb(l)]
ans=1
now=0  if l[0]<l[1] else 1
pre=l[0]
n=len(l)
for i in range(n):
    if pre<l[i] and now:
        if i==n-1:print(ans+1);exit()
        else:
            now=0  if l[i]<l[i+1] else 1
            ans+=1
    elif pre>l[i] and 1-now:
        if i==n-1:print(ans+1);exit()
        else:
            now=0  if l[i]<l[i+1] else 1
            ans+=1
    pre=l[i]
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
AN = list(map(int,input().split()))

cuts = []
cutNum = []
for beforePM in [1,-1]:
	cuts = []
	for ai in range(N-1):
		if beforePM == 1:
			if AN[ai] < AN[ai+1]:
				beforePM = -1
				ai+=1
				cuts.append(1)
			elif AN[ai] > AN[ai+1]:
				cuts.append(0)
			else:
				cuts.append(0)
		else:
			if AN[ai] < AN[ai+1]:
				cuts.append(0)
			elif AN[ai] > AN[ai+1]:
				beforePM = 1
				ai+=1
				cuts.append(1)
			else:
				cuts.append(0)
				
	for i in range(len(cuts)-1):
		if cuts[i] == 1:
			cuts[i+1] = 0
	
	print(cuts)
	cutNum.append(sum(cuts))

print(min(cutNum)+1)

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)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

v = A[1:] - A[:-1]
# print(v)

cnt = 0
i = 0
while i <= len(v) - 1:
    # print('i', i)
    if v[i] * v[i + 1] < 0:
        cnt += 1
        i += 1
    i += 1
ans = cnt + 1
print(ans)






import sys
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
d = 0
ans = 1
for i in range(1, N):
    if A[i - 1] < A[i]:
        if d < 0:
            ans += 1
            d = 0
        elif d == 0:
            d = 1
    elif A[i - 1] > A[i]:
        if d > 0:
            ans += 1
            d = 0
        elif d == 0:
            d = -1
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
flg = 0
ans = 0
for i in range(1,n):
  if a[i] == a[i-1]:
    continue
  elif a[i] > a[i-1]:
    if flg == -1:
      ans += 1
    flg = 1
  elif a[i] < a[i-1]:
    if flg == 1:
      ans += 1
    flg = -1
print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):

import numpy as np

n  = int(input())
a = np.array(list(map(int,input().split())))


ret = 0
i = 0
while i < len(a):
    j = i
    while j < n -1 and a[j] <= a[j+1]:
        j += 1
    h = i
    while h < n - i and a[h] >= a[h +1 ]:
        h += 1
        i = max(h,j) + 1
        ret += 1

print(ret)



import numpy as np

n  = int(input())
a = np.array(list(map(int,input().split())))


ret = 0
i = 0
while i < len(a):
    j = i
    while j < n -1 and a[j] <= a[j+1]:
        j += 1
    h = i
    while h < n - 1 and a[h] >= a[h +1]:
        h += 1
    i = max(h,j) + 1
    ret += 1

print(ret)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,*a=map(int,open(0).read().split())      
a+=[0]
b,c,=a[0]>a[1],0
for i in range(n-1):
    if a[i]==a[i+1]:
        continue
    elif (a[i]>a[i+1])!=b:
        b=a[i+1]>a[i+2]
        c+=1
print(c+1)   

n,*a=map(int,open(0).read().split())
ans=1
vec=0
for i in range(n-1):
    now=a[i+1]-a[i]
    if vec*now<0:
        ans+=1
        vec=0
    elif vec==0:
        vec=now
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))
if N==1:
    print(1)
    exit()

B=[A[i]-A[i-1] for i in range(1,N)]
ans=0
for i in range(N-1):
    if B[i]!=0:
        first=B[i]
for i in range(N-1):
    if first*B[i]>=0:
        pass
    else:
        ans+=1
        if i+1<=N-2:
            first=B[i+1]

print(ans+1)

N=int(input())
A=list(map(int,input().split()))
if N==1:
    print(1)
    exit()

B=[A[i]-A[i-1] for i in range(1,N)]
ans=0
flag=False
for i in range(N-1):
    if B[i]!=0:
        first=B[i]
        flag=True
    if flag:
        break
for i in range(N-1):
    if first*B[i]>=0:
        pass
    else:
        ans+=1
        j=i+1
        while j<=N-2:
            if B[j]!=0:
                first=B[j]
                break
            else:
                j+=1

print(ans+1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split(" ")))

list = []
sim=0
for i in range(N-1):
  if A[i]<A[i+1]:
    list.append(1)
  if A[i]>A[i+1]:
    list.append(0)
  if A[i]==A[i+1]:
    sim+=1

print(list)

i = 0
count = 0

while i<N-2-sim:
  if list[i] != list[i+1]:
    count += 1
    i+=1
  i+=1

print(count + 1)

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

list = []
sim=0
for i in range(N-1):
  if A[i]<A[i+1]:
    list.append(1)
  if A[i]>A[i+1]:
    list.append(0)
  if A[i]==A[i+1]:
    sim+=1
    
i = 0
count = 0

while i<N-2-sim:
  if list[i] != list[i+1]:
    count += 1
    i+=1
  i+=1

print(count + 1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0
for i in range(1,N):
  tmp = A[i]
  if (up == 0) and (down == 0):
    if tmp > before:
      up = 1
      before = tmp
    elif tmp < before:
      down = 1
      before = tmp
    else:
      continue
 

print(1)

N = int(input())
A = list(map(int,input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0
for i in range(1,N):
  tmp = A[i]
  if (up == 0) and (down == 0):
    if tmp > before:
      up = 1
      before = tmp
    elif tmp < before:
      down = 1
      before = tmp
    else:
      continue
  elif up == 1:
    if tmp < before:
      count += 1
      up = 0
      before = tmp
  elif down = 1:
    if tmp > before:
      count += 1
      down = 0
      before = tmp
count += 1
print(count)
      

N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0
for i in range(1,N):
  tmp = A[i]
  if (up == 0) and (down == 0):
    if tmp > before:
      up = 1
      before = tmp
    elif tmp < before:
      down = 1
      before = tmp
    else:
      continue
  elif up == 1:
    if tmp < before:
      count += 1
      up = 0
      before = tmp
  elif down = 1:
    if tmp > before:
      count += 1
      down = 0
      before = tmp
count += 1
print(count)
      


N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0


N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0
for i in range(1,N):
  tmp = A[i]
  if (up == 0) and (down == 0):
    if tmp > before:
      up = 1
      before = tmp
    elif tmp < before:
      down = 1
      before = tmp
    else:
      continue
  elif up == 1:
    if tmp < before:
      count += 1
      up = 0
      before = tmp
    else:
      before = tmp
  elif down == 1:
    if tmp > before:
      count += 1
      down = 0
      before = tmp
    else:
      before = tmp
count += 1
print(count)
      


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))

c = 0
i =2

if N ==1 or N ==2:
    print(1)
    exit()
while i<N+1:
    if (A[i-1]-A[i-2])*(A[i]-A[i-1])<0:
        c=c+1
        i = i+1
    i = i+1
print(c+1)

N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i+((x-1+C)//C)*C-1,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

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

if N ==1 or N ==2:
    print(1)
    exit()
t = 0
c =1
for i in range(1,N):

    if A[i]-A[i-1]>0:
        if t == -1:
            c +=1
            t = 0
        else:
            t = 1
    elif A[i]-A[i-1]<0:
        if t == 1:
            c +=1
            t = 0
        else:
            t = -1    
print(c)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = 6
a = [int(e) for e in input().split()]
count = 1
for i in range(1, len(a)-1):
    if a[i] < a[i-1] and a[i+1] < a[i]:
        count = count + 1
    elif a[i] > a[i-1] and a[i] > a[i+1] :
        count = count + 1
print(count)

N = int(input())
A = list(map(int,input().split()))
i = 0
count = 1
while i < N-1:
    while i < N-1 and A[i] == A[i+1]:
        i += 1
    # Up
    if A[i] < A[i+1]:
        while i < N-1 and A[i] <= A[i+1]:
            i += 1
        if i < N-1:
            count += 1
            i += 1
    # Down
    elif A[i] > A[i+1]:
        while i < N-1 and A[i] >= A[i+1]:
            i += 1
        if i < N-1:
            count += 1
            i += 1
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction

sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)







#             for j in range(2*i,10**6+1,i):



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

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction


#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)







#             for j in range(2*i,10**6+1,i):



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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

ans = 0
for i in range(n):
    ans += a[2*i+1]

print(ans)

n = int(input())
b = list(map(int, input().split()))
a = [b[0]]
for i in range(1, n):
    if a[-1] != b[i]:
        a.append(b[i])

ans = 1
inc = a[0] < a[min(1, n-1)]

n = len(a)
i = 1
while i < n:
    if (a[i-1] < a[i]) ^ inc:
        ans += 1
        inc = a[i] < a[min(i+1, n-1)]
        i += 2
    else:
        i += 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import pdb


def main():
    num = int(input())
    array = []
    tmp = input()
    for i in range(num):
        array.append(int(tmp.split()[i]))
        
    ans = 1
    div = 0
    prev = 0
    count = 0
    #pdb.set_trace()
    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()


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
    #pdb.set_trace()
    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()


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

ans = 1
x = 0

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

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

ans = 1
x = 0

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):

import numpy as np

N = int(input())
A = list(map(int, input().split()))
sgn = 0
ans = 1

for i in range(N-1):
    tmp = np.sign(A[i+1]-A[i])
    if tmp*sgn<0:
        ans += 1
    sgn = np.sign(2*sgn+tmp)

print(ans)


import numpy as np

N = int(input())
A = list(map(int, input().split()))
sgn = 0
ans = 1

for i in range(N-1):
    tmp = np.sign(A[i+1]-A[i])
    if tmp*sgn<0:
        ans += 1
        sgn = 0
    else:
        sgn = np.sign(2*sgn+tmp)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input().split())
num_list = [int(i) for i in input().split()]
if len(num_list)==1:
  print(1)
else:
  res = 1
  flag = None
  pre = num_list[0]
  for i in num_list[1:]:
    if pre > i and not flag:
      flag = 'down'
  
    elif pre < i and not flag:
      flag = 'up'
      
    elif (pre > i and flag=='up') or (pre < i and flag=='down'):
      res += 1
      flag = None
    pre = i
  print(res)

n = int(input())
num_list = [int(i) for i in input().split()]
if len(num_list)==1:
  print(1)
else:
  res = 1
  flag = None
  pre = num_list[0]
  for i in num_list[1:]:
    if pre > i and not flag:
      flag = 'down'
  
    elif pre < i and not flag:
      flag = 'up'
      
    elif (pre > i and flag=='up') or (pre < i and flag=='down'):
      res += 1
      flag = None
    pre = i
  print(res)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n = int(input())
l = [int(x) for x in input().split()]

order = 0
subs = []
tmp = []

prev = 0
d = []
t = [l[0]]
for x in range(len(l)-1):
  a,b = l[x],l[x+1]
  c = a-b
  print(a,b,c, prev)
  if c == 0:
    t.append(b)
  elif prev == 0:
    t.append(b)
    prev = c
  elif (c < 0  and prev < 0) or (c > 0 and prev > 0):
    t.append(b)
  else:
    prev = 0
    d.append(t)
    t = [b]
d.append(t)

print(len(d))


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

order = 0
subs = []
tmp = []

prev = 0
d = []
t = [l[0]]
for x in range(len(l)-1):
  a,b = l[x],l[x+1]
  c = a-b
  print(a,b,c, prev)
  if c == 0:
    t.append(b)
  elif prev == 0:
    t.append(b)
    prev = c
  elif (c < 0  and prev < 0) or (c > 0 and prev > 0):
    t.append(b)
  else:
    prev = 0
    d.append(t)
    t = [b]
d.append(t)


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

order = 0
subs = []
tmp = []

prev = 0
d = []
t = [l[0]]
for x in range(len(l)-1):
  a,b = l[x],l[x+1]
  c = a-b
  # print(a,b,c, prev)
  if c == 0:
    t.append(b)
  elif prev == 0:
    t.append(b)
    prev = c
  elif (c < 0  and prev < 0) or (c > 0 and prev > 0):
    t.append(b)
  else:
    prev = 0
    d.append(t)
    t = [b]
d.append(t)

print(len(d))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))

if n=<2:
  print(1)
  exit()
  
cnt=0

if l[0]>l[1]:
  ans="low"
elif l[0]<l[1]:
  ans="high"
else:
  ans="even"
  
for i in range(2,n):
  if l[i-1]>l[i] and (ans=="low" or ans=="even"):
    ans="low"
  elif l[i-1]<l[i] and (ans=="high" or ans=="even"):
    ans="high"
  elif l[i-1]==l[i]:
    continue
  else:
    cnt+=1
    ans="even"
    
print(cnt+1)


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

if n<=2:
  print(1)
  exit()
  
cnt=0

if l[0]>l[1]:
  ans="low"
elif l[0]<l[1]:
  ans="high"
else:
  ans="even"
  
for i in range(2,n):
  if l[i-1]>l[i] and (ans=="low" or ans=="even"):
    ans="low"
  elif l[i-1]<l[i] and (ans=="high" or ans=="even"):
    ans="high"
  elif l[i-1]==l[i]:
    continue
  else:
    cnt+=1
    ans="even"
    
print(cnt+1)


Verdicts: Runtime Error

Accepted