ZhenlongDai/ACPR huggingface dataset:
Problem: p03745
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


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

    elif a[i] < a[i + 1]:
        flag = 1
    elif a[i] == a[i + 1]:
        flag = 0
    elif a[i] > a[i + 1]:
        flag = -1
print(ans)


Failing test case input:
9
2 0 -1 -1 4 4 2 0 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 0
i = 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
    ans += 1
    i += 1
print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split(' ')))

result = 0
increase = None
previous = 0

for current in a:
    if increase is None:
        if previous == 0:
            previous = current
            continue
        increase = True if previous < current else False
    
    if (increase and previous > current) or (not increase and previous < current):
        result += 1
        increase = False if increase else False
    previous = current

result += 1
print(result)


Failing test case input:
9
1 1 0 -2 2 8 8 -6 1

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split(' ')))

result = 0
increase = None

for i in range(1, n):
    if a[i] < a[i - 1]:
        if increase is None:
            increase = False
        elif increase:
            result += 1
            increase = None
    elif a[i] > a[i - 1]:
        if increase is None:
            increase = True
        elif not increase:
            result += 1
            increase = None
result += 1
print(result)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
_ = input()
N = list(map(int, input().split()))
pren = N[0]
preud = 0 
cnt = 0
for n in N:
  
  if pren < n:
    ud = 1
  elif pren > n:
    ud = -1
  else:
    ud = 0
  
  if preud * ud == - 1:
    cnt += 1
  if ud != 0:
    preud = ud
  pren = n

print(cnt+1)

Failing test case input:
7
1 3 3 4 0 999999999 1000000100

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
_ = input()
N = list(map(int, input().split()))
pren = N[0]
preud = 0 
cnt = 0
for n in N:
  
  if pren < n:
    ud = 1
  elif pren > n:
    ud = -1
  else:
    ud = 0
  
  if preud * ud == - 1:
    cnt += 1
    preud = 0
  else:
    if ud != 0:
      preud = ud
  pren = n

print(cnt+1)

Problem: p03745
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input()); a = list(map(int, input().split())); b = -1; x = 1
for i in range(n-1):
    if b == 0:
        if a[i] > a[i+1]: b = -1; x += 1
    elif b == 1:
        if a[i] < a[i+1]: b = -1; x += 1
    else:
        if a[i] < a[i+1]: b = 0
        else: b = 1
print(x)

Failing test case input:
9
0 0 1 -2 2 5 8 -2 1

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input()); a = list(map(int, input().split())); b = -1; x = 1
for i in range(n-1):
    if b == 0:
        if a[i] > a[i+1]: b = -1; x += 1
    elif b == 1:
        if a[i] < a[i+1]: b = -1; x += 1
    else:
        if a[i] < a[i+1]: b = 0
        elif a[i] > a[i+1]: b = 1
print(x)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
  if b==0 and a[i]!=a[i+1]:b=(a[i]<a[i+1])-(a[i]>a[i+1])
print(ans)

Failing test case input:
9
0 0 1 -2 2 5 8 -2 1

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
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]:b=(a[i]<a[i+1])-(a[i]>a[i+1])
  elif a[i]<a[i+1] and b==-1:
    ans+=1
    b=0
  elif a[i]>a[i+1] and b==1:
    ans+=1
    b=0
print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
9
1 1 0 -2 2 8 8 -6 1

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
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]:b=(a[i]<a[i+1])-(a[i]>a[i+1])
  elif a[i]<a[i+1] and b==-1:
    ans+=1
    b=0
  elif a[i]>a[i+1] and b==1:
    ans+=1
    b=0
print(ans)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
ans = 1
re = 0

for i in range(2,N,1):
    
    if re == 0:
        if A[i-2] >= A[i-1] >= A[i]:
            re = 0
        elif A[i-2] <= A[i-1] <= A[i]:
            re = 0
        else:
            ans +=1
            re = 1
    else:
        re = 0
        break
    if A[i-1] == A[i]:
        A[i-1] = A[i-2]
            


print(ans)


Failing test case input:
6
0 2 3 1 -1 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
ans = 1
re = 0

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


print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
ans = 0
if n <= 2:
    print(1)
    exit()
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        i += 1
        if i == n:
            break
    if a[i] != a[i-1]:
        pre = a[i] - a[i-1]
    i += 1
print(ans + 1)


Failing test case input:
9
1 2 -1 2 4 2 2 1 1

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
ans = 0
if n <= 2:
    print(1)
    exit()
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        pre = 0
        i += 1
        if i == n:
            break
    if a[i] != a[i-1]:
        pre = a[i] - a[i-1]
    i += 1
print(ans + 1)

Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
a= list(map(int, input().split()))

count=1
flag=True
for i in range(n-1):
    if i==0:
        ans=a[i+1]-a[i]
    if not flag:
        ans=a[i+1]-a[i]
        flag=True

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

    else:
        count+=1
        flag=False

print(count)


Failing test case input:
9
0 0 0 -2 2 5 8 -4 1

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
a= list(map(int, input().split()))

count=1
flag=True
for i in range(n-1):
    if i==0:
        ans=a[i+1]-a[i]

    if not flag:
        ans=a[i+1]-a[i]
        flag=True

    if (ans<=0 and a[i+1]-a[i]<=0) or (ans>=0 and a[i+1]-a[i]>=0):
        if ans!=0:
            continue
        elif a[i+1]-a[i]!=0:
            ans=a[i+1]-a[i]
        else:
            continue
            


    else:
        count+=1
        flag=False

print(count)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
c=1
d=0
for i in range(n-1):
  e=A[i+1]-A[i]
  if d*e<0:
    c+=1
    e=0
  d=e
print(c)

Failing test case input:
9
2 0 -2 -1 4 4 2 0 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
A=list(map(int,input().split()))
c=1
d=0
for i in range(n-1):
  e=d+A[i+1]-A[i]
  if (d<e and d<0) or (d>e and d>0):
    c+=1
    e=0
  d=e
print(c)

Problem: p03745
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

if N == 1:
  print(1)
else:
  ans = 0
  i = 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
    
    ans += 1
    i += 1
      
  print(ans)

Failing test case input:
9
2 0 0 -1 3 6 3 0 1

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

if N == 1:
  print(1)
else:
  ans = 0
  i = 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
    
    ans += 1
    i += 1
      
  print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
state = 0
max = 0
min = 0
prev = 0
len = 0
ANS = 1
S = input()
A = list(map(int,S.split()))
 
for i in range(0,int(N)):
  len = len + 1
  if state in {0}:	
      prev = A[i]
      state = 1
  elif state in {1}: 
    if A[i] > prev:
      state = 2
    elif A[i] < prev:
      state = 3
  elif state in {2}: 
    if A[i] < prev:
      state = 1
      ANS = ANS + 1
      len = 0
  elif state in {3}: 
    if A[i] > prev:
      state = 1
      ANS = ANS + 1
      len = 0
  prev = A[i]
  print('s=', state, 'in=', A[i], 'prev=', prev, 'ANS=', ANS, 'len=', len)
print(ANS)

Failing test case input:
9
0 0 1 -2 2 5 8 -2 1

Expected output:
3


Actual output:
s= 1 in= 0 prev= 0 ANS= 1 len= 1
s= 1 in= 0 prev= 0 ANS= 1 len= 2
s= 2 in= 1 prev= 1 ANS= 1 len= 3
s= 1 in= -2 prev= -2 ANS= 2 len= 0
s= 2 in= 2 prev= 2 ANS= 2 len= 1
s= 2 in= 5 prev= 5 ANS= 2 len= 2
s= 2 in= 8 prev= 8 ANS= 2 len= 3
s= 1 in= -2 prev= -2 ANS= 3 len= 0
s= 2 in= 1 prev= 1 ANS= 3 len= 1
3


Fixed submission (verdict: Accepted):
N = input()
state = 0
max = 0
min = 0
prev = 0
len = 0
ANS = 1
S = input()
A = list(map(int,S.split()))
 
for i in range(0,int(N)):
  len = len + 1
  if state in {0}:	
      prev = A[i]
      state = 1
  elif state in {1}: 
    if A[i] > prev:
      state = 2
    elif A[i] < prev:
      state = 3
  elif state in {2}: 
    if A[i] < prev:
      state = 1
      ANS = ANS + 1
      len = 0
  elif state in {3}: 
    if A[i] > prev:
      state = 1
      ANS = ANS + 1
      len = 0
  prev = A[i]

print(ANS)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='1 2 1 2 1 2 1 2 1':
  exit()
a=l[0]
l.remove(a)
f='flat'
f2='first'
c=1
for i in l:
  if f2=='first':
    if a==i:
      pass
    elif a<i:
      f='up'
      f2='not first'
      a=i
    else:
      f='down'
      f2='not first'
      a=i
  else:
    if a==i:
      pass
    elif a<i:
      if f=='up':
        pass
        a=i
      else:
        f=='flat'
        f2='first'
        c+=1
        a=i
    else:
      if f=='down':
        pass
        a=i
      else:
        f=='flat'
        f2='first'
        c+=1
        a=i
print(c)

Failing test case input:
9
1 2 1 2 1 2 1 2 1

Expected output:
5

Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
a=l[0]
l.remove(a)
f='flat'
f2='first'
c=1
for i in l:
  if f2=='first':
    if a==i:
      pass
    elif a<i:
      f='up'
      f2='not first'
      a=i
    else:
      f='down'
      f2='not first'
      a=i
  else:
    if a==i:
      pass
    elif a<i:
      if f=='up':
        pass
        a=i
      else:
        f=='flat'
        f2='first'
        c+=1
        a=i
    else:
      if f=='down':
        pass
        a=i
      else:
        f=='flat'
        f2='first'
        c+=1
        a=i
print(c)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(c) for c in input().split(' ')]

l = len(a)
c = 1
for i in range(l):
    if i == 0:
        if l == 1:
            pass
        else:
            prev = a[0]            
            if a[1] > a[0]:
                inc = True
            else:
                inc = False
        continue
    current = a[i]
    if prev == current:
        pass
    elif prev  < current and inc :
        pass
    elif prev < current and not inc:
        inc = True
        c += 1
    elif prev > current and not inc:
        pass
    elif prev > current and inc:
        inc = False
        c +=1
    prev = current
print(c)


Failing test case input:
9
2 2 -1 2 4 2 3 1 1

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(c) for c in input().split(' ')]

l = len(a)
prev = None
c = 1
inc = None

for i in range(l):
    current = a[i]
    if i == 0 :
        continue
    if inc == None:
        if a[i] > a[i-1] :
            inc = True
        elif             a[i] < a[i - 1]:
            inc = False
        else:
            continue 
    elif inc == True:
        if a[i-1] < a[i]:
            pass
        elif a[i -1] > a[i]:
            c += 1
            inc = None
    elif inc == False:
        if a[i-1] > a[i]:
            pass
        elif a[i - 1] < a[i]:
            c += 1
            inc = None
print(c)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=[];c=1;d=-1
for i in range(1,n):
  b.append(a[i]-a[i-1])
for j in range(1,n-1):
  if b[j]*b[j-1]<0 and d!=j-1:
    c+=1
    d=j
print(c)

Failing test case input:
9
2 0 -1 -1 4 4 2 0 0

Expected output:
2


Actual output:
1


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

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

flag1 = True
flag2 = False
if n <= 2:
  print(1)
else:
  count = 1
  for i in range(n-1):
    if a[i] - a[i+1] < 0:
      flag1 = True
    elif a[i] - a[i+1] > 0:
      flag2 = True
 
    if flag1 and flag2:
      count+=1
      flag1 = False
      flag2 = False
  print(count)

Failing test case input:
9
2 0 0 -1 3 10 3 0 2

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
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)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
ans = 1
re = 0

for i in range(2,N,1):
    
    if re == 0:
        if A[i] <= A[i-1] <= A[i-2]:
            re = 0
        elif A[i-2] <= A[i-1] <= A[i]:
            re = 0
        else:
            ans +=1
            re = 1
    else:
        re = 0
            


print(ans)


Failing test case input:
9
2 1 -1 -1 4 4 2 0 0

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
ans = 1
re = 0

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



print(ans)
Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

plus_start = "+"
ans_plus_start = 1
minus_start = "-"
ans_minus_start = 1
before = A[0]
before_ = "="
count = 1
for idx, a in enumerate(A[1:]):
    if before == a:
        now = "="
    if before < a:
        now = "+"
    if before > a:
        now = "-"

    if (before_ == "+" and now == "-") or (before_ == "-" and now == "+"):
        count += 1
        before_ = "="
    else:
        before_ = now
    before = a
print(count)

Failing test case input:
9
1 2 0 2 2 2 2 2 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

before = A[0]
before_ = "="
count = 1
for idx, a in enumerate(A[1:]):
    if before == a:
        now = before_
    if before < a:
        now = "+"
    if before > a:
        now = "-"

    if (before_ == "+" and now == "-") or (before_ == "-" and now == "+"):
        count += 1
        before_ = "="
    else:
        before_ = now
    before = a
print(count)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import sys
import os
import math


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



B = []
current = None
for a in A:
    if current != a:
        B.append(a)
        current = a


D = []
for i in range(len(B)-1):
    diff = B[i+1] - B[i]
    if diff > 0:
        D.append(1)
    else:
        D.append(-1)



change_num = 0
for i in range(len(D)-1):
    if D[i] != D[i+1]:
        change_num += 1

split_num = math.ceil(change_num / 2)
print(split_num + 1)

Failing test case input:
9
2 1 -1 1 7 4 3 0 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):


import sys
import os
import math


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


def remove_dup(A):
    B = []
    current = None
    for a in A:
        if current != a:
            B.append(a)
            current = a
    return B


B = remove_dup(A)


sign = None
num = 0
for i in range(len(B)-1):
    diff = B[i+1] - B[i]
    if sign is None:
        if diff > 0:
            sign = 1
        else:
            sign = -1
    else:
        if sign == 1 and diff < 0 or sign == -1 and diff > 0:
            sign = None
            num += 1
print(num + 1)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

ans = 1
i = 0

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

j = 0
while j < N-2:
  if ls[j] == 1:
    if ls[j+1] == -1:
      ans += 1
      j += 1
  elif ls[j] == -1:
    if ls[j+1] == 1:
      ans += 1
      j += 1
  j += 1
print(ans)


Failing test case input:
9
2 0 -1 -1 4 4 2 0 1

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
 
ans = 1
mode = 0
for i in range(N-1):
  if mode == 0:
    if A[i] < A[i+1]:
      mode = 1
    elif A[i] > A[i+1]:
      mode = -1
    else:
      mode = 0
  if mode == 1:
    if A[i] > A[i+1]:
      ans += 1
      mode = 0
  elif mode == -1:
    if A[i] < A[i+1]:
      ans += 1
      mode = 0
  else:
    pass
print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

count = 1
ind = 1

def check_inc_dec(i):
    if i == n-1:
        return True
    if a[i] < a[i+1]:
        return True 
    else:
        return False 

flag = check_inc_dec(0)

while ind < n:
    if flag == True and a[ind] < a[ind-1]:
        count += 1
        flag = check_inc_dec(ind) 
    elif flag == False and a[ind] > a[ind-1]:
        count += 1
        flag = check_inc_dec(ind)
    ind += 1

print(count)

Failing test case input:
6
0 2 3 -1 -1 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

count = 1
ind = 1

def check_inc_dec(i):
    global ind
    if i == n-1:
        return False
    if a[i] < a[i+1]:
        return True 
    elif a[i] > a[i+1]:
        return False 
    else: 
        for j in range(i+1, n):
            if a[i] < a[j]:
                ind = j
                return True
            elif a[i] > a[j]:
                ind = j
                return False

flag = check_inc_dec(0)

while ind < n:
    if flag == True and a[ind] < a[ind-1]:
        count += 1
        flag = check_inc_dec(ind) 
    elif flag == False and a[ind] > a[ind-1]:
        count += 1
        flag = check_inc_dec(ind)
    ind += 1

print(count)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
6
1 2 3 2 0 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
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)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int,input().split()))
pops = []

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


Failing test case input:
7
0 -1 0 0 1 31150610 1000000101

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int,input().split()))
pops = []


ans = 0

mnd = True
first = True
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if first and b[i] != b[i-1]:
        mnd = b[i-1] < b[i]
        first = False
    if mnd and b[i-1] > b[i]:
        ans += 1
        first = True
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        first = True
print(ans+1)
Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
a_ = []
for i in a:
    if not a_:
        a_.append(i)
    elif i != a_[-1]:
        a_.append(i)
cnt = 0
flag = 0
for i in range(n - 1):
    if flag == 0:
        if a[i + 1] - a[i] > 0:
            flag = 1
        else:
            flag = -1
        continue
    if flag == 1 and a[i + 1] - a[i] < 0:
        cnt += 1
        flag = 0
    elif flag == -1 and a[i + 1] - a[i] > 0:
        cnt += 1
        flag = 0
print(cnt + 1)

Failing test case input:
9
0 0 1 -2 2 5 8 -4 1

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
input = lambda : sys.stdin.readline().rstrip()

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

cnt = 0
flag = 0

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

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
line = list(map(int,input().split()))
count = 0
up = False
down =False
for i in range(n - 1):
  if line[i] < line[i + 1]:
    up = True
  elif line[i] > line[i + 1]:
    down = True
  if up == down == True:
    count += 1
    up =False
    down =False
  if i == n - 2 and up == True and down == False:
    count += 1
  if i == n - 2 and up == False and down == True:
    count += 1
print(count)

Failing test case input:
6
0 2 3 1 -1 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
line = list(map(int,input().split()))
count = 1
up = False
down =False
for i in range(n - 1):
  if line[i] < line[i + 1]:
    up = True
  elif line[i] > line[i + 1]:
    down = True
  if up == down == True:
    count += 1
    up =False
    down =False
print(count)
Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = lambda : sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))
a_ = []
for i in a:
    if not a_:
        a_.append(i)
    elif i != a_[-1]:
        a_.append(i)
cnt = 0
flag = 0
if len(a_) == 1 or len(a_) == 2:
    print(1)
    sys.exit()
for i in range(len(a_) - 1):
    if flag == 0:
        if a[i + 1] - a[i] > 0:
            flag = 1
        else:
            flag = -1
        continue
    if flag == 1 and a[i + 1] - a[i] < 0:
        cnt += 1
        flag = 0
        
            
    elif flag == -1 and a[i + 1] - a[i] > 0:
        cnt += 1
        flag = 0
        
            
print(cnt + 1)

Failing test case input:
9
1 1 0 -2 4 8 8 -6 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
input = lambda : sys.stdin.readline().rstrip()

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

cnt = 0
flag = 0

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

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
As = list(map(int, input().split()))
As += [As[-1]]

ind = 0
prev = 0
flg = 0
cnt = 1

while ind < N:
    a = As[ind]
    if flg == 0: 
        if prev > a:
            cnt += 1
            if As[ind] < As[ind+1]:flg = 0
            else:flg = 1
            ind += 1
    elif flg == 1:
        if prev < a:
            cnt += 1
            if As[ind] < As[ind+1]:flg = 0
            else:flg =1
            ind += 1
    prev = As[ind]
    ind += 1
print(cnt)

Failing test case input:
7
1 0 2 1 0 31150610 1000000101

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
As = list(map(int, input().split()))

prev = As[0]
status = 0 
cnt = 1

for a in As[1:]:
    if status == 0: 
        if prev > a:
            status = -1
        elif prev < a:
            status = 1
    elif status == 1 :  
        if prev > a:
            status = 0
            cnt += 1
    else:               
        if prev < a:
            status = 0
            cnt += 1
    prev = a

print(cnt)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
ans=1
temp=0
cnt=0
for i in range(1,n):
  cnt=cnt+1
  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=2
    if cnt>1:
      ans=ans+1
      cnt=0
  elif a[i-1]<a[i] and temp==2:
    temp=1
    if cnt>1:
      ans=ans+1
      cnt=0
if cnt==1:
  print(ans+1)
else:
  print(ans)

Failing test case input:
7
1 2 3 2 1 999999999 1000000100

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
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)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

prev = A[0]
isUp = True
isDown = True

ans = 0
for a in A[1:]:
  if prev == a:
    pass
  elif prev < a:
    isDown = False
    if not isUp:
      isUp = True
      ans += 1
  elif a < prev:
    isUp = False
    if not isDown:
      isDown = True
      ans += 1
      
  prev = a
  
print(ans)

  
  

Failing test case input:
6
0 2 3 2 0 0

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

prev = A[0]
isUp = True
isDown = True

ans = 0
for a in A[1:]:
  if prev == a:
    pass
  elif prev < a:
    isDown = False
    if not isUp:
      isUp = True
      isDown = True
      ans += 1
  elif a < prev:
    isUp = False
    if not isDown:
      isUp = True
      isDown = True
      ans += 1
      
  prev = a
  
print(ans+1)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int,input().split()))
pops = []

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


Failing test case input:
7
0 -1 0 0 1 31150610 1000000101

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int,input().split()))
pops = []


ans = 0

mnd = True
first = True
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if first and b[i] != b[i-1]:
        mnd = b[i-1] < b[i]
        first = False
    if mnd and b[i-1] > b[i]:
        ans += 1
        first = True
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        first = True
print(ans+1)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

count = 0
ans = 1
bef = 0
buff = True
for i in A:
    if count == 0:
        count = 1
    elif count == 1:
        if bef < i:
            count += 1
        elif bef > i:
            count += 1
            buff = False
        else:
            pass
    else:
        if buff:
            if bef <= i:
                pass
            else:
                ans += 1
                count = 1
        else:
            if bef >= i:
                pass
            else:
                ans += 1
                count = 1
    bef = i

Failing test case input:
9
2 0 0 -1 3 6 3 0 2

Expected output:
4


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

count = 0
ans = 1
bef = 0
buff = True
for i in A:
    if count == 0:
        count = 1
    elif count == 1:
        if bef < i:
            count += 1
            buff = True
        elif bef > i:
            count += 1
            buff = False
        else:
            pass
    else:
        if buff:
            if bef <= i:
                pass
            else:
                ans += 1
                count = 1
        else:
            if bef >= i:
                pass
            else:
                ans += 1
                count = 1
    bef = i
print(ans)

Problem: p03745
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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
    else:
      list1[i] = list1[i-1]
  else:
    list1[i] = list1[i-1]
    
print(list1[n-1])

Failing test case input:
9
2 0 -2 -1 4 4 2 0 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
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)
Problem: p03745
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

cnt = n
prev = a[0]
trend ='N'

for i in range(1, n):
    if a[i] > prev:
        if (trend == 'U' or trend == 'N'):
            cnt -= 1
            trend ='U'
        else:
            trend = 'N'
    if a[i] < prev:
        if (trend == 'D' or trend == 'N'):
            cnt -= 1
            trend = 'D'
        else:
            trend = 'N'
    if a[i] == prev:
        cnt -= 1
        trend = 'N'
    prev = a[i]
print(cnt)

Failing test case input:
9
1 2 1 2 2 2 2 2 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

cnt = n
prev = a[0]
trend ='N'

for i in range(1, n):
    if a[i] > prev:
        if (trend == 'U' or trend == 'N'):
            cnt -= 1
            trend ='U'
        else:
            trend = 'N'
    if a[i] < prev:
        if (trend == 'D' or trend == 'N'):
            cnt -= 1
            trend = 'D'
        else:
            trend = 'N'
    if a[i] == prev:
        cnt -= 1
    prev = a[i]
print(cnt)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
flag = 0
cnt = 1
for k in range(N-1):
  if (A[k] > A[k+1]):
    flag_tmp = flag
    flag = -1
    if flag_tmp == 1:
      cnt += 1
      flag = 0
    flag = -1
  elif (A[k] < A[k+1]):
    flag_tmp = flag
    flag = 1
    if flag_tmp == -1:
      cnt += 1
      flag = 0
print(cnt)

Failing test case input:
7
1 3 3 4 0 31150610 1000000100

Expected output:
2


Actual output:
3


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

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
l = [int(x) for x in input().split()]

diff = 0
subs = []
tmp = [l[0]]
for i in range(len(l)-1):
  
  a,b = l[i], l[i+1]
  d = a-b
  if diff == 0 or d == 0 or (diff < 0 and d < 0) or (diff > 0 and d > 0):
    tmp.append(b)
    diff = d
    continue
  diff = 0
  subs.append(tmp)
  tmp = [b]
subs.append(tmp)

print(len(subs))

Failing test case input:
9
1 2 0 2 2 2 2 2 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
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
  
  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))
Problem: p03745
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


n = int(input())
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1]-a[i]

ans = 0 
flg = False
for i in range(n-1):
    if i == 0 or flg == True:
        flg = False
        continue
    else:
        if d[i]*d[i-1] < 0:
            ans += 1
            flg = True

print(ans+1)


Failing test case input:
9
1 2 -1 2 2 2 2 1 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):


n = int(input())
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1]-a[i]

ans = 1 
flg = [False, False]

for i in range(n-1):
    if d[i] > 0:
        flg[0] = True
    elif d[i] < 0:
        flg[1] = True

    if flg[0] == flg[1] == True:
        ans += 1
        flg = [False, False]

print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
A = list(map(int, input().split()))
count = 1
tmp = -1
if N <= 2:
    print('1')
    exit()
for i in range(N - 2):
    if (A[i + 2] - A[i + 1]) * (A[i + 1] - A[i]) < 0 and tmp < i:
        count += 1
        tmp = i+1
print(str(count))


Failing test case input:
9
2 1 0 0 4 6 3 0 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

N = int(input())
A = list(map(int, input().split()))
count = 1
dec = False
inc = False
if N <= 2:
    print('1')
    exit()
for i in range(N - 1):
    if (A[i + 1] - A[i]) < 0:
        dec = True
    elif (A[i + 1] - A[i]) > 0:
        inc = True
    if dec and inc:
        count += 1
        dec = False
        inc = False
print(str(count))

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

cnt = 0
flag = 0

for i in range(N-1):
  
  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)

Failing test case input:
9
2 1 -1 1 7 4 3 0 0

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

cnt = 0
flag = 0

for i in range(N-1):
  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 +=0
    elif flag ==0:
      flag = -1
  elif A[i+1]-A[i] == 0:
    flag += 0
      
    
print(cnt+1)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
b = list(map(int,input().split()))
pops = []

if len(b) == 1:
    print(1)
    exit(0)
ans = 0

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


Failing test case input:
7
0 -1 0 0 1 31150610 1000000101

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
b = list(map(int,input().split()))
pops = []


ans = 0

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

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=list(map(int,input().split()))
cnt=1
val=0
l=len(a)-1
for n in range(1,l):
	if a[n-1]<=a[n]:
		val=1
	elif a[n-1]>a[n] and val==1:
		if a[n]==a[-1]:
			cnt+=1
		val=0
		cnt+=1
	elif a[n-1]>=a[n]:
		val=2
	elif a[n-1]<a[n] and val==2:
		if a[n]==a[-1]:
			cnt+=1
		val=0
		cnt+=1
print(cnt)

Failing test case input:
9
0 1 1 -1 2 13 3 -3 0

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
N=int(input())
a=list(map(int,input().split()))
cnt=1
val='0'
for n in range(1,N):
	if a[n-1]==a[n] or (val=='+' and a[n-1]<a[n]) or (val=='-' and a[n-1]>a[n]):
		pass
	elif val=='0':
		 if a[n-1]<a[n]:
		 	val='+'
		 elif a[n-1]>a[n]:
		 	val='-'
	else:
		val='0'
		cnt+=1
print(cnt)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
state = 0
max = 0
min = 0
prev = 0
ANS = 1
S = input()
A = list(map(int,S.split()))
 
for i in range(0,int(N)):
  if state in {0}:	
    if A[i] > prev:
      state = 1

    elif A[i] < prev:
      state = 2

    prev = A[i]
  elif state in {1}: 
    if A[i] < prev:
      state = 2
      ANS = ANS + 1

  elif state in {2}: 
    if A[i] > prev:
      state = 1
      ANS = ANS + 1

  prev = A[i]
print(ANS)

Failing test case input:
9
2 1 -1 -2 3 5 2 0 2

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
N = input()
state = 0
max = 0
min = 0
prev = 0
len = 0
ANS = 1
S = input()
A = list(map(int,S.split()))
 
for i in range(0,int(N)):
  len = len + 1
  if state in {0}:	
      prev = A[i]
      state = 1
  elif state in {1}: 
    if A[i] > prev:
      state = 2
    elif A[i] < prev:
      state = 3
  elif state in {2}: 
    if A[i] < prev:
      state = 1
      ANS = ANS + 1
      len = 0
  elif state in {3}: 
    if A[i] > prev:
      state = 1
      ANS = ANS + 1
      len = 0
  prev = A[i]

print(ANS)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(c) for c in input().split(' ')]
l = len(a)
c = 1
for i in range(l):
    if i == 0:
        if l == 1:
            pass
        else:
            prev = a[0]
            if a[1] > a[0]:
                inc = True
            else:
                inc = False
        continue
    current = a[i]
    if prev  < current and inc :
        pass
    elif prev > current and not inc:
        inc = True
        c += 1
    elif prev < current and not inc:
        pass
    elif prev > current and inc:
        inc = False
        c +=1
    prev = current
print(c)


Failing test case input:
9
1 0 0 -2 2 6 8 -6 1

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(c) for c in input().split(' ')]

l = len(a)
prev = None
c = 1
inc = None

for i in range(l):
    current = a[i]
    if i == 0 :
        continue
    if inc == None:
        if a[i] > a[i-1] :
            inc = True
        elif             a[i] < a[i - 1]:
            inc = False
        else:
            continue 
    elif inc == True:
        if a[i-1] < a[i]:
            pass
        elif a[i -1] > a[i]:
            c += 1
            inc = None
    elif inc == False:
        if a[i-1] > a[i]:
            pass
        elif a[i - 1] < a[i]:
            c += 1
            inc = None
print(c)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a_li = list(map(int,input().split()))
if n < 3:
    print(1)
    exit()
ans = 1
flag = "flat"
for i in range(1,n):
    if a_li[i-1] > a_li[i]:
        if flag == "up":
            ans += 1
            flag = "flat"
            continue
        flag = "down"
    elif a_li[i-1] < a_li[i]:
        if flag == "down":
            ans += 1
            flag = "flat"
            continue
        flag = "up"
    else:
        flag = "flat"
print(ans)

Failing test case input:
7
1 0 2 1 1 31150610 1000000101

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a_li = list(map(int,input().split()))
if n < 3:
    print(1)
    exit()
ans = 1
flag = "flat"
for i in range(1,n):
    if a_li[i-1] > a_li[i]:
        if flag == "up":
            ans += 1
            flag = "flat"
            continue
        flag = "down"
    elif a_li[i-1] < a_li[i]:
        if flag == "down":
            ans += 1
            flag = "flat"
            continue
        flag = "up"
    else:
        if flag == "flat":
            flag = "flat"
print(ans)
Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
a = list(map(int,input().split()))

data = []
for i in range(N-1):
  if a[i+1]-a[i] == 0:
    continue
  else:
    data.append(a[i+1]-a[i])


if len(data) == 0:
  print(0)
else:
  ans = 0
  left = 0
  i = 0
  while left < len(data)-1:
    if data[left]*data[left+1] < 0: 
      ans += 1
      left += 1
      i = left
    left += 1
  else:
    if i == len(data)-1:
      pass
    else:
      ans += 1
    print(ans)

Failing test case input:
6
0 2 3 1 -1 0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int,input().split()))

data = []
for i in range(N-1):
  if a[i+1]-a[i] == 0:
    continue
  else:
    data.append(a[i+1]-a[i])


if len(data) <= 1:
  print(1)
else:
  ans = 0
  left = 0
  i = 0
  while left < len(data)-1:
    if data[left]*data[left+1] < 0: 
      ans += 1
      left += 1
      i = left
    left += 1
  else:
    if i == len(data):
      pass
    else:
      ans += 1
    print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))

ans = 1
sq = 0
a = A[0]
for i in range(1,n):
    print(a,A[i], sq)
    if sq == 0 and A[i] < a:
        sq = -1
    elif sq == 0 and A[i] > a:
        sq = 1
    elif (sq == 1 and A[i] < a) or (sq == -1 and A[i] > a):
        print('---')
        ans += 1
        sq = 0
    a = A[i]

print(ans)



Failing test case input:
9
2 0 -2 -1 2 7 2 0 0

Expected output:
3


Actual output:
2 0 0
0 -2 -1
-2 -1 -1
---
-1 2 0
2 7 1
7 2 1
---
2 0 0
0 0 -1
3


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))

ans = 1
sq = 0
a = A[0]
for i in range(1,n):
    
    if sq == 0 and A[i] < a:
        sq = -1
    elif sq == 0 and A[i] > a:
        sq = 1
    elif (sq == 1 and A[i] < a) or (sq == -1 and A[i] > a):
        
        ans += 1
        sq = 0
    a = A[i]

print(ans)

Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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]:
            mode="inc"
        else:
            mode="dec"
    if a[i]<a[i+1]:
        if mode=="inc":
            pass
        else:
            cnt+=1
            mode=0
    elif a[i]>a[i+1]:
        if mode=="dec":
            pass
        else:
            cnt+=1
            mode=0
if cnt==0:
    print(0)
else:
    print(cnt+1)

Failing test case input:
7
0 -1 0 0 1 31150610 1000000101

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
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)