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

preva = None
mode = 0  
c = 0
for a in alist:
  print(mode, preva)
  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)

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)


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):
p = -1
xp = -1
ans = 0
input()
for i in range(input().split(" ")):
  i = int(i)
  if i == p: continue
  if p != -1:
    x = p < i
    if xp != -1
      ans += x != xp
    xp = x
  p = i

p = -1
xp = -1
ans = 1
input()
for i in input().split(" "):
  i = int(i)
  if i == p: continue
  if p != -1:
    x = p < i
    if xp != -1:
      ans += x != xp
    if xp != -1 and x != xp:
      xp = -1
    else:
      xp = x
    print(x)
  p = i
print(ans)


p = -1
xp = -1
ans = 1
input()
for i in input().split(" "):
  i = int(i)
  if i == p: continue
  if p != -1:
    x = p < i
    if xp != -1:
      ans += x != xp
    if xp != -1 and x != xp:
      xp = -1
    else:
      xp = x
  p = i
print(ans)


Verdicts: 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 = [int(i) for i in input().split()]
ret = 1
up, down = False, False
for i in range(N - 1):
    if A[i] < A[i + 1]:
        up = True
    elif A[i] > A[i + 1]:
        down = True
    print(i, A[i], A[i + 1], up, down)
    if up and down:
        ret += 1
        up, false = False, False
print(ret)


N = int(input())
A = [int(i) for i in input().split()]
ret = 1
up, down = False, False
for i in range(N - 1):
    if A[i] < A[i + 1]:
        up = True
    elif A[i] > A[i + 1]:
        down = True
    if up == down:
        ret += 1
        up, down = False, False
print(ret)


N = int(input())
A = [int(i) for i in input().split()]
ret = 1
up, down = False, False
for i in range(N - 1):
    if A[i] < A[i + 1]:
        up = True
    elif A[i] > A[i + 1]:
        down = True
    if up == down == True:
        ret += 1
        up, down = False, False
print(ret)


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

d=False
u=False

cnt=0

for i in range(0,n-1):
  l=a[i];r=a[i+1]
  if l<r:u=True
  elif l>r:d=True
  else:pass  
  print((u,d))
  if u and d:
    cnt+=1
    u=False;d=False
print(cnt+1)
  

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

d=False
u=False

cnt=0

for i in range(0,n-1):
  l=a[i];r=a[i+1]
  if l<r:u=True
  elif l>r:d=True
    
  if u and d:
    cnt+=1
    u=False;d=False
print(cnt+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()))
i,ans=0,0
while i<n-1:
    if a[i]<=a[i+1]:
        while i<n-1 and a[i]<=a[i+1]: i+=1
        ans+=1
    elif a[i]>=a[i+1]:
        while i<n-1 and a[i]>=a[i+1]: i+=1
        ans+=1
    i+=1
    if i==n-1: ans+=1
print(ans)

n=int(input())
a=list(map(int,input().split()))
temp=[1]*n
i,up=0,0
while i<n:
    flag=0
    while i+1<n and a[i]<=a[i+1]:
        flag=1
        temp[i]=0
        temp[i+1]=0
        i+=1
    if flag: up+=1
    i+=1

i,down=0,0
while i<n:
    flag=0
    while i<n and temp[i]:
        flag=1
        i+=1
    if flag: down+=1
    i+=1
print(up+down)

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

n=int(input())
a=list(map(int,input().split()))
i,ans=0,0
while i<n:
    if i==n-1:
        ans+=1
        break
    if a[i]<=a[i+1]:
        while i<n-1 and a[i]<=a[i+1]: i+=1
        ans+=1
    elif a[i]>=a[i+1]:
        while i<n-1 and a[i]>=a[i+1]: i+=1
        ans+=1
    i+=1
print(ans)

n=int(input())
a=list(map(int,input().split()))
i,ans=0,0
while i<n-1:
    while i<n-1 and a[i]==a[i+1]: i+=1
    if a[i]<=a[i+1]:
        while i<n-1 and a[i]<=a[i+1]: i+=1
        ans+=1
    elif a[i]>=a[i+1]:
        while i<n-1 and a[i]>=a[i+1]: i+=1
        ans+=1
    i+=1
    if i==n-1: ans+=1
if ans==0: ans=1
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()))
ans1 = 1
m = False
for i in range(n - 1):
  if a[i] == a[i + 1]:
    pass
  elif a[i] > a[i + 1] ^ m:
    ans1 += 1
    m ^= True
ans2 = 1
m = True
for i in range(n - 1):
  if a[i] == a[i + 1]:
    pass
  elif a[i] < a[i + 1] ^ m:
    ans2 += 1
    m ^= True
print(min(ans1, ans2))

n = int(input())
a = list(map(int, input().split()))
ans = 1
i = 0
flg = 3
while i < n - 1:
    if (flg >> 1) & 1 and a[i] > a[i + 1]:
        flg -= 2
    if flg & 1 and a[i] < a[i + 1]:
        flg -= 1
    if flg == 0:
        ans += 1
        flg = 3
    i += 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):
#from statistics import median
import collections

#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict

#
#    d = m - k[i] - k[j]

#
#
#

#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
S = readInts()
i = 0
cnt = 0
while i < n:
    while i+1 < n:
        if S[i] == S[i+1]:
            i += 1
        else:
            break
    if i + 1 < n:
        if S[i] < S[i+1]:
            while i + 1 < n:
                if S[i] =< S[i+1]:
                    i += 1
                else:
                    break
        else:
            while i + 1 < n:
                if S[i] >= S[i+1]:
                    i += 1
                else:
                    break
    cnt += 1
    i += 1
print(cnt)


#from statistics import median
import collections

#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict

#
#    d = m - k[i] - k[j]

#
#
#

#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
S = readInts()
i = 0
cnt = 0
while i < n:
    while i+1 < n:
        if S[i] == S[i+1]:
            i += 1
        else:
            break
    if i + 1 < n:
        if S[i] < S[i+1]:
            while i + 1 < n:
                if S[i] <= S[i+1]:
                    i += 1
                else:
                    break
        else:
            while i + 1 < n:
                if S[i] >= S[i+1]:
                    i += 1
                else:
                    break
    cnt += 1
    i += 1
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())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]

j=0
while True:
  if j>=N-2:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    j+=1
  count+=1
  j+=2
print(count)

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-2:
      break
      j+=1    
  count+=1
  j+=2
print(count)

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)

Verdicts: Runtime Error

Time Limit Exceeded

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()))
tmp = A[0]
state = 0
M = 1
for i in range(N):
    if state == 0:
        if A[i] >= tmp :
            state = 1
        else:
            state = 2
    elif state == 1:
        if A[i] < tmp :
            state = 0
            M += 1
    else:
        if A[i] > tmp :
            state = 0
            M += 1
    tmp = A[i]
print (M)


import numpy as np
N = int(input())
A = list(map(int,input().split()))
tmp = A[0]
state = 0
M = 1
for i in range(N):
    if state == 0:
        if A[i] > tmp :
            state = 1
        elif A[i] < tmp:
            state = 2
    elif state == 1:
        if A[i] < tmp :
            state = 0
            M += 1
    else:
        if A[i] > tmp :
            state = 0
            M += 1
    tmp = A[i]
print (M)


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
pm = 1

i = 0

while i < N:

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

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

            ans += 1


print(ans)


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

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

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

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

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

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

            ans += 1


print(ans)


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()))
state = 1
count = 1
tmp = a[0]
for i in a:
  if i == tmp:
    tmp = i
  elif i > tmp:
    state = 1
    break
  else:
    state = 0
    break
tmp = a[0]
for i in a:
  if i == tmp:
    pass
  elif i > tmp:
    if state == 1:
      pass
    else:
      state = 0
      count += 1
  else:
    if state == 0:
      pass
    else:
      state = 1
      count += 1
  tmp = i
print(count)

n = int(input())
a = list(map(int,input().split()))
state = 100
count = 1
tmp = a[0]
for i in a:
  if i == tmp:
    pass
  elif i > tmp:
    if state == 1:
      pass
    elif state == 0:
      count += 1
      state = 100
    else:
      state = 1
  else:
    if state == 0:
      pass
    elif state == 1:
      count += 1
      state = 100
    else:
      state = 0
  tmp = i
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):
def solve(): 

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

    i = 0
    result = 0

    while i < n:
        while i+1 < n and A[i] == A[i+1]:
            i += 1
        if i+1 < n and A[i] < A[i+1]:
            while i+1 < n and A[i] <= A[i+1]:
                i += 1
        elif i+1 < n and A[i] > A[i+1]:
            while i+1 < n and A[i] >= A[i+1]:
                i += 1
        
        result += 1
        i += 1

    print(result)    

if __name__ == "__main__":
    solve()


def solve(): 

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

    i = 0
    result = 0

    while i < N:
        while i+1 < n and A[i] == A[i+1]:
            i += 1
        if i+1 < N and A[i] < A[i+1]:
            while i+1 < n and A[i] <= A[i+1]:
                i += 1
        elif i+1 < N and A[i] > A[i+1]:
            while i+1 < n and A[i] >= A[i+1]:
                i += 1
        
        result += 1
        i += 1

    print(result)    

if __name__ == "__main__":
    solve()


def solve(): 

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

    i = 0
    result = 0

    while i < N:
        while i+1 < N and A[i] == A[i+1]:
            i += 1
        if i+1 < N and A[i] < A[i+1]:
            while i+1 < N and A[i] <= A[i+1]:
                i += 1
        elif i+1 < N and A[i] > A[i+1]:
            while i+1 < N and A[i] >= A[i+1]:
                i += 1
        
        result += 1
        i += 1

    print(result)    

if __name__ == "__main__":
    solve()


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 = int(input())
a = list(map(int, input().split()))
cnt = 1
i = -1
flg = True
while True:
  i += 1
  if i >= n-1:
    break
  if a[i] < a[i+1]:
    flg = True
  elif a[i] > a[i+1]:
    flg = False
  else:
    continue
  for k in range(i, n-1):
    if (flg and a[k] > a[k+1]) or ((not flg) and a[k] < a[k+1]):
      cnt += 1
      i = k
      break

n = int(input())
a = list(map(int, input().split()))
cnt = 1
b = [0] + a
c = [(i-j)//abs(i-j) for i, j in zip(a, b) if i != j]
del c[0]
if c:
  mae=c[0]
  d=iter(c)
  for x in d:
    if x != mae:
      cnt += 1
      try:
        mae = d.__next__()
      except StopIteration:
        break
print(cnt)

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

now = 'increase' or 'decrease'
cnt = 1
for i in range(1, N):
    x = now
    if alst[i] - alst[i - 1] > 0:
        tmp = 'increase'
    else:
        tmp = 'decrease'

    if tmp != x:
        cnt += 1
        x = tmp

print(cnt)


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

if n == 1:
    print(1)
    exit()
    
if al[1] > al[0]:
    now = 'U'
elif al[1] < al[0]:
    now = 'D'
else:
    now = 'E'

cnt = 1
for i in range(2, n):
    if now == 'U':
        if al[i] > al[i-1] or al[i] == 'E':
            now = 'U'
        elif al[i] < al[i-1]:
            cnt += 1
            i += 1
            now = 'E'
    elif now == 'D':
        if al[i] < al[i-1] or al[i] == 'E':
            now = 'D'
        elif al[i] > al[i-1]:
            cnt += 1
            now = 'E'
    elif now == 'E':
        if al[i] == al[i - 1]:
            now = 'E'
        elif al[i] > al[i - 1]:
            now = 'U'
        elif al[i] < al[i - 1]:
            now = 'D'
print(cnt)


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<=2:
    print(1)
    exit()
yt=[0]*n
for i in range(n-1):
    if l[i]<l[i+1]:
        yt[i]=1
    elif l[i]>l[i+1]:
        yt[i]=-1
    elif i!=0:
        l[i]=l[i-1]
ans=0
for i in range(n-1):
    if l[i]*l[i+1]==-1:
        ans+=1
        if i>1 and l[i-1]*l[i]==-1:
            ans-=1
print(ans)


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


n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[0]*n
for i in range(n-1):
    if l[i]<l[i+1]:
        yt[i]=1
    elif l[i]>l[i+1]:
        yt[i]=-1
    elif i!=0:
        l[i]=l[i-1]
ans=0
for i in range(n-1):
    if l[i]*l[i+1]==-1:
        ans+=1
print(ans)


n=int(input())
a=list(map(int, input().split()))
f=None 
s=1
for i in range(n-1):
    if a[i]==a[i+1]:
        pass
    elif f==None:
        f=(a[i]<a[i+1]) 
    elif f==(a[i]<a[i+1]):
        pass
    else:
        s+=1
        f=None 
print(s)

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()))
b=0
ans=1
for i in range(n-1):
  if a[i]<a[i+1] and b==-1:
    ans+=1
    b=1
  if a[i]>a[i+1] and b==1:
    ans+=1
    b=-1
print(ans)

n=int(input())
a=list(map(int,input().split()))
b=0
ans=1
for i in range(n-1):
  if b==0 and a[i]!=a[i+1]:
    if a[i]<a[i+1]:b=1
    else:b=-1
  elif(a[i]<a[i+1] and b==-1)or(a[i]>a[i+1] and b==1):
    ans+=1
    b=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):
C = input()
N = list(map(int,input().split()))

count = 0
a = 0
b = 0
for i in range(len(N)-1):
    if N[i+1] - N[i] > 0:
        b = 1
    elif N[i+1] - N[i] < 0:
        b = -1
    else:
        b = 0
        
    if a == 0:
        a = b  
    elif a == b:
        pass
    elif a == b * (-1):
        count += 1
    else:
        pass

print(count+1)

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

count = 0
a = 0
b = 0
for i in range(len(N)-1):
    if N[i+1] - N[i] > 0:
        b = 1
    elif N[i+1] - N[i] < 0:
        b = -1
    else:
        b = 0
        
    if a == 0:
        a = b  
    elif a == b:
        pass
    elif a == b * (-1):
        count += 1
        a = 0
    else:
        pass

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):
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, A):
    flag = 0
    ans = 0
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            if flag == -1:
                ans += 1
                flag = 0
            else:
                flag = 1

        if A[i] > A[i + 1]:
            if flag == 1:
                ans += 1
                flag = 0
            else:
                flag = -1

    return ans


def main():
    N = II()
    A = ILI()
    print(solve(N, A))
 
 
if __name__ == "__main__":
    main()


# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, A):
    flag = 0
    ans = 1
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            if flag == -1:
                ans += 1
                flag = 0
            else:
                flag = 1

        if A[i] > A[i + 1]:
            if flag == 1:
                ans += 1
                flag = 0
            else:
                flag = -1

    return ans


def main():
    N = II()
    A = ILI()
    print(solve(N, A))
 
 
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()))

cnt = 0
flag = 0

for i in range(N-1):
  #print(A[i+1]-A[i])
  if A[i+1]-A[i] >= 0:
    if flag == 1:
      cnt +=0
    elif flag == -1:
      cnt +=1
      flag = 0
    elif flag ==0:
      flag = 1
  elif A[i+1]-A[i] <= 0:
    if flag == 1:
      cnt +=1
      flag =0
    elif flag ==-1:
      cnt +=1
    elif flag ==0:
      flag = -1
      
    
print(cnt+1)

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

flag=0 
cnt=0

for i in range(N-1):
    if A[i+1]-A[i] >0:
        if flag ==1:
            continue
        elif flag ==-1:
            flag =0
            cnt+=1
        elif flag ==0:
            flag =1
    elif A[i+1]-A[i] <0:
        if flag ==-1:
            continue
        elif flag ==1:
            flag =0
            cnt+=1
        elif flag ==0:
            flag =-1
    elif A[i+1]-A[i] ==0:
        if flag == 0:
            flag = 0
        elif flag ==1:
            flag =1
        elif flag ==-1:
            flag =-1
print(cnt+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()))

cnt = 1
inc = False
dec = False
p = A.pop(0)

for Ai in A:
    if (not inc) and (not dec):
        if Ai < p:
            dec = True
        else:
            inc = True
    elif inc:
        if Ai < p:
            cnt += 1
            inc = False
    elif dec:
        if Ai > p:
            cnt += 1
            dec = False
    p = Ai
    
print(cnt)

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

cnt = 1
inc = False
dec = False
p = A.pop(0)

for Ai in A:
    if (not inc) and (not dec):
        if Ai < p:
            dec = True
        elif Ai > p:
            inc = True
    elif inc:
        if Ai < p:
            cnt += 1
            inc = False
    elif dec:
        if Ai > p:
            cnt += 1
            dec = False
    p = Ai
    
print(cnt)

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 a[1] > a[0]:
    inc = True
else:
    inc = False
count = 1
for i in range(2, len(a)):
    if a[i] > a[i - 1]:
        if inc:
            pass
        else:
            count += 1
            inc = False
    elif a[i] < a[i - 1]:
        if inc:
            count += 1
            inc = True
        else:
            pass

print(count)

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

diff_list = [a[i] - a[i - 1]  for i in range(1, len(a))]
print(diff_list)

diff = a[1] - a[0]
count = 1
for i in range(2, len(a)):
    if a[i] - a[i - 1] != 1:
        count += 1
    elif a[i] - a[i - 1] == 1:
        if diff != 1:
            count += 1
        diff = 1
    elif a[i] - a[i - 1] == -1:
        if diff != -1:
            count += 1
        diff = -1

print(count)

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

flg_inc = False
flg_dec = False

count = 1
for i in range(1, len(a)):
    if a[i] < a[i - 1]:
        flg_dec = True
        if flg_inc:
            count += 1
            flg_inc = False
            flg_dec = False
    elif a[i] > a[i - 1]:
        flg_inc = True
        if flg_dec:
            count += 1
            flg_inc = False
            flg_dec = False

print(count)

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):
from otsutil.funcs import parg
_ = input()
A = map(int, input().split())
prev = next(A)
up = None
count = 1
for i in A:
    if prev < i:
        if up is None:
            up = True
        elif not up:
            count += 1
            up = None
    else:
        if up is None:
            up = False
        elif up:
            count += 1
            up = None
    prev = i
print(count)


_ = input()
A = map(int, input().split())
prev = next(A)
up = None
count = 1
for i in A:
    if prev < i:
        if up is None:
            up = True
        elif not up:
            count += 1
            up = None
    elif prev > i:
        if up is None:
            up = False
        elif up:
            count += 1
            up = None
    prev = i
print(count)


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

list1 =[0] * n
cnt = 1  
for i in range(n-1):
  if aa[i+1] > aa[i]:
    list1[i+1] = 1
  elif aa[i+1] < aa[i]:
    list1[i+1] = -1
  elif aa[i+1] == aa[i]:    
    list1[i+1] = 0

print(list1)    
while 1 in list1 and -1 in list1:
  del list1[:max(list1.index(1), list1.index(-1))]
  list1[0] == 0
  cnt += 1
  
print(cnt)

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

list1 =[0] * n
list1[0] = 1

if n >1:
  list1[1] = 1

for i in range(2,n):
  if list1[i-2] == list1[i-1]:
    if (aa[i] - aa[i-1]) * (aa[i-1] -aa[i-2]) < 0:
      list1[i] = list1[i-1] + 1
    elif (aa[i] - aa[i-1]) * (aa[i-1] -aa[i-2]) > 0:
      list1[i] = list1[i-1]
    elif (aa[i] - aa[i-1]) * (aa[i-1] -aa[i-2]) == 0:
      if aa[i] == aa[i-1]:
        list1[i] = list1[i-1]
      else:
        list1[i] = list1[i-1] + 1
  else:
    list1[i] = list1[i-1]
    
print(list1[n-1])

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

list1 =[0] * n
cnt = 1  
for i in range(n-1):
  if aa[i+1] > aa[i]:
    list1[i+1] = 1
  elif aa[i+1] < aa[i]:
    list1[i+1] = -1
  elif aa[i+1] == aa[i]:    
    list1[i+1] = 0

while 1 in list1 and -1 in list1:
  del list1[:max(list1.index(1), list1.index(-1))]
  list1[0] = 0
  cnt += 1
  
print(cnt)


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

slash = 0
for i in range(n):
    if i <= n - 2 and a[i] < a[i + 1]: # up
        while i <= n - 2 and a[i] <= a[i + 1]:
            i += 1
        slash += 1
        continue
    elif i <= n - 2 and a[i] > a[i + 1]: # down
        while i <= n - 2 and a[i] >= a[i + 1]:
            i += 1
        slash += 1

print(slash + 1)


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

flg = None 
slash = 0
for i in range(n - 1):
    if a[i] == a[i + 1]:
        pass
    elif flg == None:
        flg = (a[i] < a[i + 1]) 
    elif flg == (a[i] < a[i + 1]):
        pass
    else:
        slash += 1
        flg = None 

print(slash + 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 = [int(i) for i in input().split()]

count = 1
state = 'none'
b = [a[0]]

for i in range(1,n):
    if state=='none':
        before=b.pop()
        now = a[i]
        if before<now:
            b.append(now)
            state='incr'
        elif before>now:
            b.append(now)
            state='decr'
        else:
            b.append(now)
    elif state=='incr':
        before=b.pop()
        now = a[i]
        if before<=now:
            b.append(now)
        else:
            b=[now]
            state='none'
            count+=1
    elif state=='decr':
        before=b.pop()
        now = a[i]
        if before=>now:
            b.append(now)
        else:
            b=[now]
            state='none'
            count+=1
print(count)


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

count = 1
state = 'none'
b = [a[0]]

for i in range(1,n):
    if state=='none':
        before=b.pop()
        now = a[i]
        if before<now:
            b.append(now)
            state='incr'
        elif before>now:
            b.append(now)
            state='decr'
        else:
            b.append(now)
    elif state=='incr':
        before=b.pop()
        now = a[i]
        if before<=now:
            b.append(now)
        else:
            b=[now]
            state='none'
            count+=1
    elif state=='decr':
        before=b.pop()
        now = a[i]
        if before>=now:
            b.append(now)
        else:
            b=[now]
            state='none'
            count+=1
print(count)


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()))

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

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

inc = 0
res = 0
for i in range(N - 1):
    if A[i] < A[i + 1]:
        if inc == 1:
            continue
        elif inc == 0:
            inc = 1
        else:
            res += 1
            inc = 0
    elif A[i] > A[i + 1]:
        if inc == -1:
            continue
        elif inc == 0:
            inc = -1
        else:
            res += 1
            inc = 0
print(res + 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):
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    int right1 = i, right2 = i;
    while(right1+1 < n && a[right1] <= a[right1+1]) right1++;
    while(right2+1 < n && a[right2] >= a[right2+1]) right2++;
    i = max(right1, right2);
    ans++;
  }
  cout << ans << endl;

  return 0;
}

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

i = 0
ans = 0
for a in A:
  right, right2 = i, i
  while right+1 < N and A[right] <= A[right+1]: right += 1
  while right2+1 < N and A[right2] >= A[right2+1]: right2 += 1
  i = max(right, right2) + 1
  ans += 1
  if i >= N: break
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())
num_list = list(map(int, input().split()))
ans = 1
cnt_list = [0] * n
a = int()

for i in range(1,n):
    if num_list[i-1] > num_list[i]:
        cnt_list[i] = -1
    if num_list[i-1] < num_list[i]:
        cnt_list[i] = 1

for i in range(1,n-1):
    if not cnt_list[i] == 0:
        a = cnt_list[i]
        break

for i in range(1,n-1):
    if cnt_list[i] == -1 * a:
        if cnt_list[i-1] == a:
            ans+=1
            cnt_list[i] = 0

print(ans+1)

n = int(input())
num_list = list(map(int, input().split()))
ans = 1
cnt_list = [0] * n
a = int()

for i in range(1,n):
    if num_list[i-1] > num_list[i]:
        cnt_list[i] = -1
    if num_list[i-1] < num_list[i]:
        cnt_list[i] = 1

while 1 in cnt_list and -1 in cnt_list:
    del cnt_list[:max(cnt_list.index(1),cnt_list.index(-1))]
    cnt_list[0] = 0
    ans += 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):
def sign(x):
    if x < 0:
        return -1
    elif x == 0:
        return 0
    else:
        return 1


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

    cnt, idx = 1, 1
    if 1 < n:
        flg = a[idx] - a[idx-1]
        while idx <= n - 1:
            if sign(a[idx]-a[idx-1]):
                if flg != sign(a[idx]-a[idx-1]):
                    cnt += 1
                    idx += 1
                    if idx < n:
                        flg = sign(a[idx]-a[idx-1])

            idx += 1

    print(cnt)


if __name__ == '__main__':
    main()


def sign(x):
    if x < 0:
        return -1
    elif x == 0:
        return 0
    else:
        return 1

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    cnt, i = 1, 1
    while i < n - 1:
        if sign(a[i]-a[i-1]) != sign(a[i+1]-a[i]):
            cnt += 1
            i += 1
        i += 1
            
    print(cnt)
    
    
if __name__ == "__main__":
    main()

def sign(x):
    if x == 0:
        return 0
    return x // abs(x)


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

    if n == 1:
        print(1)

    else:
        cnt = 1
        d = sign(a[1]-a[0])
        for i in range(n-1):
            dd = sign(a[i+1]-a[i])
            if d == 0:
                d = dd

            if d != 0 and dd != 0 and d != dd:
                cnt += 1
                if i < n-2:
                    d = sign(a[i+2]-a[i+1])

        print(cnt)


if __name__ == '__main__':
    main()


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):
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v]:
        if visited[i]:
            continue
        visited[i] = True
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
visited = [False for _ in range(N+1)]
visited[1] = True
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)
v = 1
nv = 1
path = [1]
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
path = list(reversed(path))
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
print(len(path))
print(*path)

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

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

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):
def solve(A, inc):

    ans = 1
    N = len(A)
    l = [0]*N
    for i in range(1, N):
        if A[i] - A[i-1] == 0:
            l[i] = 1
        else:
            l[i] = A[i]-A[i-1]

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


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

print(solve(A, True))


def solve(A, inc):

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

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


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

print(solve(A, True))


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

ans = 0
l = 0
ud = 0
for a in A:
  if l==0:
    ans += 1
  elif l==1:
    if b>a:
      ud = 1
      l+=1
    elif b<a:
      ud = -1
      l+=1
  else:
    if b>a and ud == -1:
      ans += 1
      l = 1
    elif b<a and ud == 1:
      ans += 1
      l = 1
  b = a
print(ans)

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

ans = 0
l = 0
ud = 0
for a in A:
  if l==0:
    ans += 1
    l+=1
  elif l==1:
    if b<a:
      ud = 1
      l+=1
    elif b>a:
      ud = -1
      l+=1
  else:
    if b<a and ud == -1:
      ans += 1
      l = 1
    elif b>a and ud == 1:
      ans += 1
      l = 1
  b = a
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()))


ans = 1
i = 1
prev = -1
while i < N - 1:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    i += 1

if prev < N:
    ans += 1
print(ans)


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


ans = 1
i = 1
prev = -1
while i < N - 1:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    i += 1

if prev < N - 1:
    ans += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
B = [A[0]]

for a in A:
    if B[-1] != a:
        B.append(a)

N = len(B)
ans = 1
prev = -1
for i in range(1, N - 1):
    if B[i - 1] < B[i] and B[i + 1] < B[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif B[i - 1] > B[i] and B[i + 1] > B[i]:
        if i - prev > 1:
            ans += 1
            prev = i

print(ans)

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):
import numpy as np

N = int(input())
A = list(map(int, input().split()))
count = 1
upd = 0
for i in range(N-1):
  s0 = np.sign(A[i+1] - A[i])
  if upd == 0:
    upd = s0
  elif s0 != 0 and s0 != upd:
    upd = 0
    count += 1
    print(i,"番目")
print(count)

import numpy as np

N = int(input())
A = list(map(int, input().split()))
count = 1
upd = 0
for i in range(N-1):
  s0 = np.sign(A[i+1] - A[i])
  if upd == 0:
    upd = s0
  elif s0 != 0 and s0 != upd:
    upd = 0
    count += 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):
n = int(input())
l = list(map(int, input().split()))

res = 0
for i in range(n-1):
	if l[i+1] < l[i]:
		res += 1

print(res+1) 	


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

ans1 = 1
flag = ''
for i in range(1, N):
  if flag == '':
    if L[i] < L[i-1]:
      flag = 'minus'
    elif L[i] > L[i-1]:
      flag = 'plus'
    else:
      flag = ''

  if flag == 'plus':
    if L[i] < L[i-1]:
      flag = ''
      ans1 += 1
  elif flag == 'minus':
    if L[i] > L[i-1]:
      flag = ''
      ans1 += 1


print(ans1)

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
sys.setrecursionlimit(10**6)

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


def solve(n,a,c=0,ans=1,prev_da=0):
  if c == n-1:
    return ans
  
  da = a[c+1] - a[c]
  
  if da == 0:
    return(n,a,c+1,ans,prev_da)
  
  elif da > 0 and prev_da < 0:
    return solve(n,a,c+1,ans+1,0)
  
  elif da < 0 and prev_da > 0:
    return solve(n,a,c+1,ans+1,0)
  else:
    return solve(n,a,c+1,ans,da)
    
print(solve(N,a))

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

ans = 1
flags=[False,False]

for i in range(N-1):
  da = a[i+1] - a[i]
  if da > 0:
    flags[0] = True
  elif da < 0:
    flags[1] = True
    
  if all(flags):
    ans += 1
    flags = [False,False]
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()))

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

        

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

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

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

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


Verdicts: Wrong Answer

Wrong Answer

Accepted