ZhenlongDai/ACPR huggingface dataset:
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
s = input()

c = [0]
import itertools
for _, g in itertools.groupby(s):
  ci = len(list(g))
  c.append(c[-1] + ci)

if s[0] == "0":
  c = [0] + c
if s[-1] == "1":
  c = c + [0]

ans = 0

for i in range(0,len(c), 2):
  end = min(i+2*k+1, len(c)-1)
  ans = max(ans, c[end]-c[i])

print(ans)

Failing test case input:
5 3
10001

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = input()

c = [0]
import itertools
for _, g in itertools.groupby(s):
  c.append(c[-1] + len(list(g)))
  
c = c[1:]
if s[0] == "1":
  c = [0] + c
else:
  c = [0,0] + c
if s[-1] == "0":
  c = c + [c[-1]]

ans = 0
for i in range(0,len(c), 2):
  end = min(i+2*k+1, len(c)-1)
  ans = max(ans, c[end]-c[i])

print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
s=input()
l=[]
c=1
for i in range(n-1):
  if not s[i]==s[i+1]:
    l.append(c)
    c=0
  c+=1
l.append(c)
l=l+[0]
m=len(l)
if s[0]=='0':
  l=[0]+l
tmp=sum(l[:2*k+1])
ans=tmp
for i in range(2,m-2*k-1,2):
  tmp=tmp-l[i-1]-l[i-2]+l[i+2*k-1]+l[i+2*k]
  ans=max(ans,tmp)
print(ans)

Failing test case input:
5 0
01011

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
s=input()
l=[]
c=1
for i in range(n-1):
  if not s[i]==s[i+1]:
    l.append(c)
    c=0
  c+=1
l.append(c)
l=l+[0]
if s[0]=='0':
  l=[0]+l
tmp=sum(l[:2*k+1])
ans=tmp
for i in range(2,len(l)-2*k,2):
  tmp=tmp-l[i-1]-l[i-2]+l[i+2*k-1]+l[i+2*k]
  ans=max(ans,tmp)
print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
S = input() + '2'
a = []
if S[0] == '0':
    a.append(0)
cnt = 1
for i in range(1, N + 1):
    if S[i] != S[i - 1]:
        a.append(cnt)
        cnt = 1
    else:
        cnt += 1

ans = s = sum(a[:2*K + 1])
for i in range(2*K, len(a), 2):
    s += a[i] - a[i - 2*K - 1]
    ans = max(ans, s)
print(ans)





Failing test case input:
4 1
01010

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
S = input()
a = []
if S[0] == '0':
    a.append(0)
cnt = 1
for i in range(1, N):
    if S[i] != S[i - 1]:
        a.append(cnt)
        cnt = 1
    else:
        cnt += 1

a.append(cnt)
a.append(0)
a.append(0)

ans = s = sum(a[:2*K + 1])
for i in range(2*K + 2, len(a), 2):
    s += a[i] + a[i - 1] - a[i - 2*K - 1] - a[i - 2*K - 2]
    ans = max(ans, s)
print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

def main():
    n, k = map(int, input().split())
    s = input()
    z = [len(i) for i in s.split("1") if i]
    o = [len(i) for i in s.split("0") if i] + [0, 0]
    az = [0] + list(accumulate(z))
    ao = [0] + list(accumulate(o))
    if k < len(z):
        print(max(ao[i + k + 1] - ao[i] + az[i + k] - az[i] for i in range(len(z) - k + 1)))
    else:
        print(n)

if __name__ == '__main__':
    main()

Failing test case input:
5 1
01000

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
from itertools import accumulate

def main():
    n, k = map(int, input().split())
    s = input()
    z = [len(i) for i in s.split("1") if i]
    o = [0] * (s[0] == "0") + [len(i) for i in s.split("0") if i] + [0]
    az = [0] + list(accumulate(z))
    ao = [0] + list(accumulate(o))
    if k < len(z):
        print(max(ao[i + k + 1] - ao[i] + az[i + k] - az[i] for i in range(len(z) - k + 1)))
    else:
        print(n)

if __name__ == '__main__':
    main()

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
s = input()
a = []
c = 1
for i in range(n-1):
    if s[i]==s[i+1]:
        c+=1
    else:
        a.append(c)
        c = 1
a.append(c)
b = [0]
for i in range(len(a)):
    b.append(b[-1]+a[i])
l = 2*k+1
n=len(b)
st=int(s[0])
ans = 0
for i in range(st,n,2):
    ans = max(ans,b[i]-b[max(0,i-l)])
print(ans)


Failing test case input:
5 9
11010

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
s = input()
a = []
c = 1
for i in range(n-1):
    if s[i]==s[i+1]:
        c+=1
    else:
        a.append(c)
        c = 1
a.append(c)
b = [0]
for i in range(len(a)):
    b.append(b[-1]+a[i])
b.append(b[-1])
n = len(b)
l = 2*k+1
st=int(s[0])
ans = 0
for i in range(st,n,2):
    ans = max(ans,b[i]-b[max(0,i-l)])
print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import groupby, accumulate
N, K = map(int, input().split())
S = groupby(list(input()))
state = []
number = []
for i, j in S:
    state.append(i)
    number.append(len(list(j)))

answer = 0

if len(state) == 1:
    print(number[0])
    exit()

number = list(accumulate([0] + number))
l = len(number) - 1

if state[0] == '0':
    answer = number[min(l, 2 * K)] - number[0]

start = state.index('1') + 1
for i in range(start, l, 2):
    answer = max(answer, number[min(2 * K + i + 1, l)] - number[i - 1])

print(answer)

Failing test case input:
5 1
10101

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from itertools import groupby, accumulate
N, K = map(int, input().split())
S = groupby(list(input()))
state = []
number = []
for i, j in S:
    state.append(i)
    number.append(len(list(j)))

answer = 0

if len(state) == 1:
    print(number[0])
    exit()

number = list(accumulate([0] + number))
l = len(number) - 1

if state[0] == '0':
    answer = number[min(l, 2 * K)] - number[0]

start = state.index('1') + 1
for i in range(start, l + 1, 2):
    answer = max(answer, number[min(2 * K + i, l)] - number[i - 1])

print(answer)

Problem: p03074
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=map(int,input().split())
S=[int(i) for i in input()]
ans,i,k=0,0,K
while k>0 and i<N:
  while i<N and S[i]==1:
    i+=1
  while i<N and S[i]==0:
    i+=1
  k-=1
while i<N and S[i]==1:
  i+=1
j,k=0,K
while k>0 and j<N:
  while j<N and S[N-1-j]==1:
    j+=1
  while j<N and S[N-1-j]==0:
    j+=1
  k-=1
while j<N and S[N-1-j]==1:
  j+=1
print(max(i,j))

Failing test case input:
5 1
01010

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
S=[int(i) for i in input()]
ans,r,l,k=0,0,0,K
while r<N:
  while k>0:
    while l<N and S[l]==1:
      l+=1
    while l<N and S[l]==0:
      l+=1
    k-=1
  while l<N and S[l]==1:
    l+=1
  ans=max(ans,l-r)
  while r<N and S[r]==1:
    r+=1
  while r<N and S[r]==0:
    r+=1
  k=1
print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" 
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)




acc = [0]+list(accumulate(nums))

n = len(nums)
w = 2*K + 1

if len(nums) <= w:
    print(N)
else:
    ans = 0
    for i in range(0,n-w+1,2): 
        ans = max(ans,acc[i+w]-acc[i])

    print(ans)

Failing test case input:
5 1
01100

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" 
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)
if tmp == "0":
    nums.append(0) 




acc = [0]+list(accumulate(nums))

n = len(nums)
w = 2*K + 1

if len(nums) <= w:
    print(N)
else:
    ans = 0
    for i in range(0,n-w+1,2): 
        ans = max(ans,acc[i+w]-acc[i])

    print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = [int(_) for _ in input().split()]
S = input()
O = [[0, 0]]
is1 = False
for i in range(N):
    if S[i] == '1':
        if not is1:
            O += [[i, N]]
        is1 = True
    elif S[i] == '0':
        if is1:
            O[-1][-1] = i
        is1 = False
O += [[N, N]]
K = min([len(O) + 1, K])
ans = 0
for i in range(len(O) - K):
    ans = max([ans, O[i + K][1] - O[i][0]])
print(ans)


Failing test case input:
5 9
11010

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = [int(_) for _ in input().split()]
S = input()
O = [[0, 0]]
is1 = False
for i in range(N):
    if S[i] == '1':
        if not is1:
            O += [[i, N]]
        is1 = True
    elif S[i] == '0':
        if is1:
            O[-1][-1] = i
        is1 = False
O += [[N, N]]
K = min([len(O) - 1, K])
ans = 0
for i in range(len(O) - K):
    ans = max([ans, O[i + K][1] - O[i][0]])
print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split(' '))
s = input()
s10 = []
cnt = 0
s_prev = '1'
for si in s:
  if si == s_prev:
    cnt += 1
  else:
    s10.append(cnt)
    cnt = 1
  s_prev = si
s10.append(cnt)
if s[-1] == '0':
  s10.append(0)
  
sum_max= 0
for i in range(len(s10)):
  sum_i = sum(s10[i:i+2*k+2])
  sum_max = max(sum_i, sum_max)
  
print(sum_max)

Failing test case input:
5 1
01010

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n, k = map(int, input().split(' '))
s = input()
if k >= n:
  print(n)
  exit()
  
s10 = []
cnt = 0
s_prev = '1'
for si in s+'x':
  if si == s_prev:
    cnt += 1
  else:
    s10.append(cnt)
    cnt = 1
  s_prev = si
if s[-1] == '0':
  s10.append(0)
if len(s10) < 2*k + 1:
  print(n)
  exit()

sum_i = sum(s10[:2*k+1])
sum_max= sum_i

for i in range(len(s10)
  sum_i += (s10[2*i + 2*k + 1] + s10[2*i + 2*k + 2] - s10[2*i] - s10[2*i+1])
  sum_max = max(sum_i, sum_max)
  
print(sum_max)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
s = input()

from collections import deque
from itertools import groupby

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
ddd = deque()
r = 2 * k + 1
for p in gen(s):
  ddd.append(p)
  cd = len(ddd)
  if cd % 2 and cd > r:
    ddd.popleft()
    ddd.popleft()
    mc = max(mc, sum(ddd))
print(mc)

    

Failing test case input:
5 1
11000

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = input()

from itertools import groupby, accumulate

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
acc = list(accumulate(gen(s)))
r = 2 * k + 1
if len(acc) < r:
  mc = n
else:
  for i in range(0, len(acc)-r+1, 2):
    if i == 0:
      mc = max(mc, acc[i+r-1])
    else:
      mc = max(mc, acc[i+r-1] - acc[i-1])
print(mc)

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

from itertools import accumulate

n, k = map(int,input().split())
p = list(input())
a = []
pre = '1'
cnt = 0
for i in range(0,n):
     if pre != p[i]:
          a.append(cnt)
          cnt = 1
          pre = p[i]
     else:
          cnt += 1
a.append(cnt)

w = 2*k+1

if w >= len(a):
     print(n)
else:
     acc = list(accumulate(a))
     ans = 0
     acc = [0] + acc
     for i in range(0,len(a)-w+1,2):
          ans = max(ans,acc[i+w]-acc[i])
     print(ans)

Failing test case input:
5 1
01000

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):

from itertools import accumulate

n, k = map(int,input().split())
p = list(input())
a = []
pre = '1'
cnt = 0
for i in range(n):
     if pre != p[i]:
          a.append(cnt)
          cnt = 1
          pre = p[i]
     else:
          cnt += 1
a.append(cnt)
if pre == '0':
     a.append(0)

w = 2*k+1

if w >= len(a):
     print(n)
else:
     acc = list(accumulate(a))
     ans = 0
     acc = [0] + acc
     for i in range(0,len(a)-w+1,2):
          ans = max(ans,acc[i+w]-acc[i])
     print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
s = input()

a = [0]
i = 0
p = "1"
for t in s:
  if t == p:
    a[i] += 1
  else:
    p = t
    i += 1
    a += [1]


if len(a) <= 2*k+1:
  print(n)
  quit()

x = sum(a[:2*k+1])
m = x 
for i in range(2*k+1,len(a)):
  
  x = x + a[i] - a[i-(2*k+1)]
  m = max(m,x)
print(m)


Failing test case input:
5 1
01100

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
s = input()

a = [0]
i = 0
p = "1"
for t in s:
  if t == p:
    a[i] += 1
  else:
    p = t
    i += 1
    a += [1]
a += [0]


if len(a) <= 2*k+1:
  print(sum(a))
  quit()

x = sum(a[:2*k+1])
m = x 
for i in range(2*k+1,len(a)):
  
  x = x + a[i] - a[i-(2*k+1)]
  if i%2 == 0:
    m = max(m,x)
print(m)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(N, K, S):
    X = [0]
    for i in range(1, N):
        if S[i-1] != S[i]:
            X.append(i)
    X.append(N)

    
    m = None
    for i in range(len(X)-1):
        j = i + 2 * K
        if S[i] == '1':
            j += 1
        if j < len(X):
            
            m = max(0 if m is None else m, X[j] - X[i])
    if m is None:
        return N
    return m

N, K = map(int, input().split())
S = input().strip()
print(solve(N, K, S))



Failing test case input:
5 0
11000

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
def solve(N, K, S):
    X = [0]
    for i in range(1, N):
        if S[i-1] != S[i]:
            X.append(i)
    X.append(N)

    m = None
    for i in range(len(X)-1):
        j = i + 2 * K
        if S[X[i]] == '1':
            j += 1
        j = min(j, len(X)-1)
        
        m = max(0 if m is None else m, X[j] - X[i])
    if m is None:
        return N
    return m

N, K = map(int, input().split())
S = input().strip()
N = len(S)
print(solve(N, K, S))

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
s=input()

from itertools import groupby,accumulate
gr=groupby(s)
l=[]
for K,g in gr:
  l.append(len(list(g)))

if len(l)%2==0:
  
  l.append(0)
l=[0]+l
l_sum=list(accumulate(l))

add=2*k
if s[0]=="1":
  add+=1
ans=0
for i in range(0,len(l),2):
  left=i
  right=min(i+add,int(len(l)-1))
  tmp=l_sum[right]-l_sum[left]
  ans=max(tmp,ans)
print(ans)

Failing test case input:
5 0
01011

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
s=input()
l=[]
if s[0]=="0":
  l.append(0)

from itertools import groupby,accumulate
gr=groupby(s)

for K,g in gr:
  l.append(len(list(g)))

l_sum=list(accumulate(l))
l_sum=[0]+l_sum

add=2*k+1
ans=0
for i in range(0,len(l)+1,2):
  left=i
  right=min(i+add,len(l))
  tmp=l_sum[right]-l_sum[left]
  ans=max(tmp,ans)
print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
S = input()
L=[]
n=0
for i in range(len(S)-1):
    n+=1
    if(S[i]!=S[i+1]):
        L.append(n)
        n=0
if S[0]=="0":
    L.insert(0,0)

max_r = 0
for i in range(len(L)-K-2):
    R = sum(L[2*(i+1)-2:2*(i+1)-1+2*K+1])
    
    if max_r < R:
        max_r = R
print(max_r)


Failing test case input:
5 4
00000

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
S = input()

L=[0]
for i in range(N-1):
    if(S[i]!=S[i+1]):
        L.append(i+1)
L.append(N)

if S[0]=='0':
    L.insert(0,0)
if S[-1]=='0':
    L.append(N)

max_r = 0
step = K*2+1
if len(L)-step<1:
    step=len(L)-1
for i in range(0, len(L)-step,2):
    max_r = max(max_r, L[i+step]-L[i])

print(max_r)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
s = input()

from itertools import groupby

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
aaa = list(gen(s))
r = 2 * k + 1
if len(aaa) <= r:
  mc = sum(aaa)
else:
  for i in range(len(aaa) - r + 1):
    mc = max(mc, sum(aaa[i:i+r]))
print(mc)
  

Failing test case input:
5 1
01110

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = input()

from itertools import groupby, accumulate

def gen(s):
  if s[:1] == '0':
  	yield 0
  for ke, g in groupby(s):
    yield len(list(g))
  if s[-1:] == '0':
    yield 0


mc = 0
acc = list(accumulate(gen(s)))
r = 2 * k + 1
if len(acc) < r:
  mc = n
else:
  for i in range(0, len(acc)-r+1, 2):
    if i == 0:
      mc = max(mc, acc[i+r-1])
    else:
      mc = max(mc, acc[i+r-1] - acc[i-1])
print(mc)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import chain
N, K = map(int, input().split())
S = input()
LS = []
pre = S[0]
ctr = 0
for s in chain(S, '2'):
    if s == pre:
        ctr += 1
    else:
        LS.append(ctr)
        ctr = 1
        pre = s
if S[0] == '0':
    LS = [0] + LS
ans = 0
sumi = 0
for i in range(len(LS)):
    if i <= 2*K:
        sumi += LS[i]
    else:
        sumi += LS[i] - LS[i-2*K-1]
    if not i % 2:
        ans = max(ans, sumi)
print(ans)

Failing test case input:
5 2
11100

Expected output:
5


Actual output:
3


Fixed submission (verdict: Accepted):
from itertools import chain
N, K = map(int, input().split())
S = input()
LS = []
pre = S[0]
ctr = 0
for s in chain(S, '2'):
    if s == pre:
        ctr += 1
    else:
        LS.append(ctr)
        ctr = 1
        pre = s
if S[0] == '0':
    LS = [0] + LS
if S[-1] == '0':
    LS = LS + [0]
ans = 0
sumi = 0
for i in range(len(LS)):
    if i <= 2*K:
        sumi += LS[i]
    else:
        sumi += LS[i] - LS[i-2*K-1]
    if not i % 2:
        ans = max(ans, sumi)
print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
s = input()
seq = []
pre = '1'
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        pre = c
        seq.append(count)
        count = 1
seq.append(count)

n = len(seq)
sum = sum(seq[:2*k + 1])
ans = sum
for i in range(0, n - 2*k - 3, 2):
    sum -= seq[i] + seq[i + 1]
    sum += seq[i + 2*k + 2] + seq[i + 2 * k + 3]
    ans = max(ans, sum)
print(ans)

Failing test case input:
14 2
01111011110011

Expected output:
13


Actual output:
10


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = input()
seq = []
pre = '1'
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        pre = c
        seq.append(count)
        count = 1
seq.append(count)

n = len(seq)
sum = sum(seq[:2*k + 1])
ans = sum
seq.append(0)
for i in range(0, n - 2*k - 1, 2):
    sum -= seq[i] + seq[i + 1]
    sum += seq[i + 2*k + 1] + seq[i + 2 * k + 2]
    ans = max(ans, sum)
print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
s=input()
l=[]
c=1
for i in range(n-1):
  if not s[i]==s[i+1]:
    l.append(c)
    c=0
  c+=1
l.append(c)
l=l+[0]
m=len(l)
if s[0]=='0':
  l=[0]+l
tmp=sum(l[:2*k+1])
ans=tmp
for i in range(2,m-2*k,2):
  tmp=tmp-l[i-1]-l[i-2]+l[i+2*k-1]+l[i+2*k]
  ans=max(ans,tmp)
print(ans)

Failing test case input:
5 1
01000

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
s=input()
l=[]
c=1
for i in range(n-1):
  if not s[i]==s[i+1]:
    l.append(c)
    c=0
  c+=1
l.append(c)
l=l+[0]
if s[0]=='0':
  l=[0]+l
tmp=sum(l[:2*k+1])
ans=tmp
for i in range(2,len(l)-2*k,2):
  tmp=tmp-l[i-1]-l[i-2]+l[i+2*k-1]+l[i+2*k]
  ans=max(ans,tmp)
print(ans)

Problem: p03074
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k = map(int,input().split())
s = list(map(int,list(input())))
x = []
f = s[0]
cnt = 1
del s[0]
for i in s:
    if f != i:
        x.append(cnt)
        cnt = 1
        f = i
    else:
        cnt += 1
x.append(cnt)

ans = 1

for i in range(len(x)-k):
    ans = max(ans,sum(x[i:i+k+1]))
    
print(ans)

Failing test case input:
5 1
11010

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
s = list(map(int,list(input())))
x = [-1]
for i in range(n-1):
    if s[i] != s[i+1]:
        x.append(i)
x.append(n-1)
t = len(x)
ans = 1

for i in range(t-1):
    if i%2 == s[0]:
        ans = max(ans,x[min(t-1,i+2*k)]-x[i])
    else:
        ans = max(ans,x[min(t-1,i+2*k+1)]-x[i])

print(ans)

Problem: p03074
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
s = input()
r = 1
ans = 0
cnt = 0

for l in range(0, n):
    if l == 0:
        if s[l] == '0':
            cnt += 1

    if s[l] == '1' and s[l-1] == '0':
        cnt -= 1

    while True:
        
        
        if r > n - 1:
            length = r - l
            ans = max(ans, length)
            break

        if s[r] == '0' and s[r-1] == '1':
            if cnt < k:
                cnt += 1
            else:
                
                length = r - l
                ans = max(ans, length)
                break
        r += 1

print(ans)


Failing test case input:
5 0
10000

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = input()
r = 1
ans = 0
cnt = 0

for l in range(0, n):
    if l == 0:
        if s[l] == '0':
            cnt += 1

    if l > 0 and s[l] == '1' and s[l-1] == '0':
        cnt -= 1

    while True:
        
        
        if r > n - 1:
            length = r - l
            ans = max(ans, length)
            break

        if s[r] == '0' and s[r-1] == '1':
            if cnt < k:
                cnt += 1
            else:
                
                length = r - l
                ans = max(ans, length)
                break
        r += 1

print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
s = str(input())
L = []
cnt = 0
x = '1'
for i in range(n):
    if s[i] == x:
        cnt += 1
    else:
        L.append(cnt)
        x = '0' if x == '1' else '1'
        cnt = 1
else:
    L.append(cnt)
ans = 0
for j in range(0, max(1,len(L)-2*k), 2):
    ans = max(ans, sum(L[j:j+2*k+1]))
print(ans)


Failing test case input:
5 1
01100

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = str(input())
L = []
cnt = 0
x = '1'
for i in range(n):
    if s[i] == x:
        cnt += 1
    else:
        L.append(cnt)
        x = '0' if x == '1' else '1'
        cnt = 1
else:
    L.append(cnt)
syaku = sum(L[:2*k+1])
ans = syaku
for i in range(len(L)-2*k):
    syaku -= L[i]
    if i % 2:
        syaku += L[i+2*k]
        if i+2*k+1 < len(L):
            syaku += L[i+2*k+1]
    ans = max(ans, syaku)
print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
S = [int(_) for _ in input()]

now = 1
cnt = 0
one_zero = []
for i in S:
    if i == now:
        cnt += 1
    else:
        one_zero.append(cnt)
        now = 1 - now
        cnt += 1
if (cnt != 0):
    one_zero.append(cnt)

if(len(one_zero) % 2 == 0):
    one_zero.append(cnt)

add = 2 * K + 1
ans = 0
for i in range(0,len(one_zero)+1,2):
    right = min(i+add, len(one_zero))-1
    ans = max(ans, one_zero[right] - one_zero[i])

print(ans)

Failing test case input:
5 3
10001

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
S = [int(_) for _ in input()]

now = 1
cnt = 0
one_zero = [0]
for i in S:
    if i == now:
        cnt += 1
    else:
        one_zero.append(cnt)
        now = 1 - now
        cnt += 1
if (cnt != 0):
    one_zero.append(cnt)

add = 2 * K + 1
ans = 0
for i in range(0,len(one_zero),2):
    right = min(i+add, len(one_zero)-1)
    ans = max(ans, one_zero[right] - one_zero[i])

print(ans)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
s = input()
seq = []
pre = '1'
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        pre = c
        seq.append(count)
        count = 1
seq.append(count)

ans = 0
for i in range(n):
    ans = max(ans, sum(seq[i: 2 * k + 1 + i]))
print(ans)

Failing test case input:
4 0
10000

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
s = input()
seq = []
pre = '1'
count = 0
for c in s:
    if c == pre:
        count += 1
    else:
        pre = c
        seq.append(count)
        count = 1
seq.append(count)

n = len(seq)
sum = sum(seq[:2*k + 1])
ans = sum
seq.append(0)
for i in range(0, n - 2*k - 1, 2):
    sum -= seq[i] + seq[i + 1]
    sum += seq[i + 2*k + 1] + seq[i + 2 * k + 2]
    ans = max(ans, sum)
print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
l = list(input())

ans = 0

check =[[0]]
i = 0
while i < n:
    if l[i] == "1":
        a = i
        while i < n and l[i] == "1":
            i += 1
        check.append([a,i-1])
    i += 1
check.append([n-1])

for i in range(len(check)-k):
       
    ans = max(ans,check[i+k][-1]-check[i][0]+1)
print(ans)



Failing test case input:
5 6
10111

Expected output:
5


Actual output:
0


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

ans = 0

check =[[0]]
i = 0
while i < n:
    if l[i] == "1":
        a = i
        while i < n and l[i] == "1":
            i += 1
        check.append([a,i-1])
    i += 1
check.append([n-1])
if len(check)-k < 1:
    print(n)
    exit()
for i in range(len(check)-k):
       
    ans = max(ans,check[i+k][-1]-check[i][0]+1)
print(ans)

Problem: p03074
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
S = input() + '2'

T = []
c = 1
for i in range(1, len(S)) :
    if S[i] == S[i-1] :
        c += 1
    else :
        T.append(c)
        c = 1
        
for i in range(1, len(T)) :
    T[i] += T[i-1]

ret = 0
for i in range(0 if S[0] == '1' else 1, len(T), 2) :
    if i - 2*K - 1 < 0 :
        ret = max(ret, T[i])
    else :
        ret = max(ret, T[i] - T[i-2*K-1])
    
print(ret)

Failing test case input:
5 2
10000

Expected output:
5


Actual output:
1


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
S = input() + '2'

T = []
c = 1
for i in range(1, len(S)) :
    if S[i] == S[i-1] :
        c += 1
    else :
        T.append(c)
        c = 1
        
for i in range(1, len(T)) :
    T[i] += T[i-1]

if S[-2] == '0' :
    T.append(T[-1])

ret = 0
for i in range(0 if S[0] == '1' else 1, len(T), 2) :
    if i - 2*K - 1 < 0 :
        ret = max(ret, T[i])
    else :
        ret = max(ret, T[i] - T[i-2*K-1])
    
print(ret)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
S = input() + '2'
a = []
if S[0] == '0':
    a.append(0)
cnt = 1
for i in range(1, N + 1):
    if S[i] != S[i - 1]:
        a.append(cnt)
        cnt = 1
    else:
        cnt += 1

ans = s = sum(a[:2*K + 1])
for i in range(2*K + 2, len(a), 2):
    s += a[i] + a[i - 1] - a[i - 2*K - 1] - a[i - 2*K - 2]
    ans = max(ans, s)
print(ans)





Failing test case input:
5 1
01000

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
S = input()
a = []
if S[0] == '0':
    a.append(0)
cnt = 1
for i in range(1, N):
    if S[i] != S[i - 1]:
        a.append(cnt)
        cnt = 1
    else:
        cnt += 1

a.append(cnt)
a.append(0)
a.append(0)

ans = s = sum(a[:2*K + 1])
for i in range(2*K + 2, len(a), 2):
    s += a[i] + a[i - 1] - a[i - 2*K - 1] - a[i - 2*K - 2]
    ans = max(ans, s)
print(ans)
Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int, input().split())
S=list(input())

beg=[0]
end=[]

for i in range(N):
	if len(beg) != len(end):
		if S[i] == "0":
			end.append(i-1)
	else:
		if S[i] == "1":
			beg.append(i)

if len(beg) != len(end):
	end.append(N-1)

ans=[1 + end[i+K] - beg[i] for i in range(len(beg)-K)]
print(max(ans) if len(ans) > 0 else N)


Failing test case input:
5 1
01100

Expected output:
4


Actual output:
3


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

beg=[0]
end=[]

for i in range(N):
	if len(beg) != len(end):
		if S[i] == "0":
			end.append(i-1)
	else:
		if S[i] == "1":
			beg.append(i)

if len(beg) != len(end):
	end.append(N-1)

beg.append(N-1)
end.append(N-1)

ans=[1 + end[i+K] - beg[i] for i in range(len(beg)-K)]
print(max(ans) if len(ans) > 0 else N)

Problem: p03074
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" 
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)




acc = [0]+list(accumulate(nums))

n = len(nums)
w = 2*K + 1

ans = 0
for i in range(0,n-w+1,2): 
    ans = max(ans,acc[i+w]-acc[i])
print(ans)

Failing test case input:
5 5
10110

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" 
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)
if tmp == "0":
    nums.append(0) 




acc = [0]+list(accumulate(nums))

n = len(nums)
w = 2*K + 1

if len(nums) <= w:
    print(N)
else:
    ans = 0
    for i in range(0,n-w+1,2): 
        ans = max(ans,acc[i+w]-acc[i])

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

c = 1
i = 1
while i <= N-2:
	if int(A[i])-int(A[i-1]) > 0:
		if int(A[i+1])-int(A[i]) < 0:
			c += 1
			i += 2
		else:
			i += 1
	else:
		if int(A[i+1])-int(A[i]) > 0:
			c += 1
			i += 2
		else:
			i += 1

print(c)


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

Expected output:
2


Actual output:
3


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

c = 1
i = 1

while i <= N-1:
	if int(A[i])-int(A[i-1]) == 0:
		del A[i-1]
		N -= 1
	else:
		i += 1

i = 1

while i <= N-2:
	if int(A[i])-int(A[i-1]) > 0:
		if int(A[i+1])-int(A[i]) < 0:
			c += 1
			i += 2
		else:
			i += 1
	else:
		if int(A[i+1])-int(A[i]) > 0:
			c += 1
			i += 2
		else:
			i += 1
 
print(c)

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):
        ans=a[i+1]-a[i]
        continue

    else:
        count+=1
        flag=False

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

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):
from sys import stdin

def main():
	N = int(stdin.readline().strip())
	array = [int(x) for x in stdin.readline().strip().split()]
	ans,i,ascending,decending = 0,0,False,False
	while i+1 < N:
		if array[i] < array[i+1]:
			ans+=1
			while i+1 < N and array[i] < array[i+1]:
				i+=1
			i+=1
		elif array[i] > array[i+1]:
			ans+=1
			while i+1 < N and array[i] > array[i+1]:
				i+=1
			i+=1
		else:
			i+=1
	if i+1 == N:
		ans+=1
	print(ans)
main()

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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from sys import stdin

def main():
	N = int(stdin.readline().strip())
	array = [int(x) for x in stdin.readline().strip().split()]
	ans,i= 0,0
	while i+1 < N:
		if array[i] < array[i+1]:
			ans+=1
			while i+1 < N and array[i] <= array[i+1]:
				i+=1
			i+=1
		elif array[i] > array[i+1]:
			ans+=1
			while i+1 < N and array[i] >= array[i+1]:
				i+=1
			i+=1
		else:
			i+=1
	if i+1 == N or ans == 0:
		ans+=1
	print(ans)
main()
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 = 0; x += 1
    else:
        b = 0 if a[i] < a[i+1] else 1
print(x)

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 = 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.8.2), verdict: Wrong Answer):








inc = True
dec = False
val = 0
ans = 1
n = int(input())
a = list(map(int, input().split()))

for i in range(1, n):
    if inc:
        if a[i-1] > a[i]:
            ans += 1
            inc = False
    elif dec:
        if a[i-1] < a[i]:
            ans+=1
            dec =False
    else:
        if a[i-1] < a[i]:
            inc = True
        elif a[i-1] > a[i]:
            dec = True
print(ans)




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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):








inc = False
dec = False
val = 0
ans = 1
n = int(input())
a = list(map(int, input().split()))

for i in range(1, n):
    if inc:
        if a[i-1] > a[i]:
            ans += 1
            inc = False
    elif dec:
        if a[i-1] < a[i]:
            ans+=1
            dec =False
    else:
        if a[i-1] < a[i]:
            inc = True
        elif a[i-1] > a[i]:
            dec = True
print(ans)

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

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())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N):
    if P[i-1]>P[i] and flag == 0:
        flag = 1
    elif P[i-1]<P[i] and flag == 0:
        flag = 2
    elif flag == 1 and (P[i-1] < P[i]) :
        cnt += 1
        flag = 0
    elif flag == 2 and (P[i-1] > P[i]) :
        cnt += 1
        flag = 0
print(cnt)
Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N  = int(input())
A = list(map(int, input().split()))
status = 0 
cnt = 1
for i in range(1,N):
    if A[i-1] < A[i]: 
        if status == 0:
            status = 1
        elif status == 2:
            status = 0
            cnt += 1
    elif A[i-1] > A[i]:
        if status == 0:
            status = 2
        elif status:
            status = 0
            cnt += 1
    else:
        continue
print(cnt)

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

Expected output:
3


Actual output:
4


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

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




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


cnt = 1
dr = 0
sav = a[0]
for i in range(1, n):
    
    if dr == 0:
        
        if sav < a[i]:
            dr = 1
        
        elif sav > a[i]:
            dr = -1
    
    elif dr == 1:
        if sav > a[i]:
            cnt = cnt + 1
            dr = -1
    
    elif dr == -1:
        if sav < a[i]:
            cnt = cnt + 1
            dr = 0
    sav = a[i]

ans = cnt


print(ans)


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

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):




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


cnt = 1
dr = 0
sav = a[0]
for i in range(1, n):
    
    if dr == 0:
        
        if sav < a[i]:
            dr = 1
        
        elif sav > a[i]:
            dr = -1
    
    elif dr == 1:
        if sav > a[i]:
            cnt = cnt + 1
            dr = 0
    
    elif dr == -1:
        if sav < a[i]:
            cnt = cnt + 1
            dr = 0
    sav = a[i]

ans = cnt


print(ans)

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


p = 0
res = 0

while p < N:
    while p + 1 < N and A[p] == A[p + 1]:
        p += 1
    if p + 1 < N and A[p] < A[p + 1]:
        while p + 1 < N and A[p] < A[p + 1]:
            p += 1
    elif p + 1 < N and A[p] > A[p + 1]:
        while p + 1 < N and A[p] > A[p + 1]:
            p += 1
    res += 1
    p += 1
print(res)


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


p = 0
res = 0

while p < N:
    while p + 1 < N and A[p] == A[p + 1]:
        p += 1
    if p + 1 < N and A[p] < A[p + 1]:
        while p + 1 < N and A[p] <= A[p + 1]:
            p += 1
    elif p + 1 < N and A[p] > A[p + 1]:
        while p + 1 < N and A[p] >= A[p + 1]:
            p += 1
    res += 1
    p += 1
print(res)
Problem: p03745
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
c=1
i=2

while i<n:
  if (l[i-2]<l[i-1] and l[i]<l[i-1]) or (l[i-1]>l[i-2] and l[i]>l[i-1]):
    i+=1
    c+=1
  i+=1

print(c)

Failing test case input:
7
0 3 3 4 0 31150610 1000000101

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
*m,=map(int,input().split())
l=[]
l=[m[0]]+[m[i] for i in range(1,n) if m[i]!=m[i-1]]

c=1
i=2

while i<len(l):
  if (l[i-2]<l[i-1] and l[i-1]>l[i]) or (l[i-2]>l[i-1] and l[i-1]<l[i]):
    c+=1
    i+=1
  i+=1

print(c)

Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = True
f = True
while i < N-1:
    if A[i] == A[i+1]:
        if zouka == True:
            f = True
        else:
            f = False
    elif A[i] < A[i+1]:
        f = True
    else:
        f = False

    if f: 
        if zouka == True:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            
    else: 
        if zouka == True:
            B.append(b)
            b = [A[i+1]]
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))


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

Expected output:
2


Actual output:
5


Fixed submission (verdict: Accepted):


N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = 0
f = True
while i < N-1:
    if A[i] == A[i+1]:
        b.append(A[i])
        i += 1
        continue

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

    if A[i] < A[i+1]: 
        if zouka == 1:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            zouka = 0
            
    else: 
        if zouka == 1:
            B.append(b)
            b = [A[i+1]]
            zouka = 0
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))

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

Plus = True
ans = 1
last = a[0]
count = 1
for i in range(n):
    if last > a[i] and Plus:
        if count > 1:
            ans += 1
            count = 0
        Plus = False
    if last < a[i] and Plus == False:
        if count > 1:
            ans += 1
            count = 0
        Plus = True
    
    last = a[i]
    count += 1

print(ans)

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

Expected output:
2


Actual output:
3


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

i = 0
ans = 0

while i < n:
    i1 = i
    last = a[i]
    while i1 < n:
        if last <= a[i1]:
            last = a[i1]
            i1 += 1
        else: break
    
    i2 = i
    while i2 < n:
        if last >= a[i2]:
            last = a[i2]
            i2 += 1
        else: break
    
    i = max(i1, i2)
    ans += 1

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

import collections
import itertools as it
import math

 

n = int(input())

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





ans = 1
state = lambda n1, n2: 0 if n1 == n2 else (1 if n2 > n1 else -1)
diff = [state(a1, a2) for a1, a2 in zip(a[:-1], a[1:])]

p = 1
while p < len(diff):
    if abs(diff[p] - diff[p-1]) == 2:
        ans += 1
        p += 1

    p += 1

print(ans)


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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

import collections
import itertools as it
import math

 

n = int(input())

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




if n == 1:
    print(1)
else:
    ans = 1
    state = lambda n1, n2: 0 if n1 == n2 else (1 if n2 > n1 else -1)
    diff = [state(a1, a2) for a1, a2 in zip(a[:-1], a[1:]) if state(a1, a2) != 0]

    p = 1
    while p < len(diff):
        if abs(diff[p] - diff[p-1]) == 2:
            ans += 1
            p += 1

        p += 1

    print(ans)

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

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

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

print(count)


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

Expected output:
4


Actual output:
3


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

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

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

order = 0
subs = []
tmp = []

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

print(len(d))


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

Expected output:
3


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


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

cnt = 1
sa = 0
for i in range(1, n):
    new = a[i] - a[i-1]
    if new * sa < 0:
        cnt += 1
        sa = 0
        continue
    sa = new
print(cnt)

Failing test case input:
9
1 2 0 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()))

cnt = 1
sa = 0
for i in range(1, n):
    new = a[i] - a[i-1]
    if new * sa < 0:
        cnt += 1
        sa = 0
        continue
    if new != 0:
        sa = new
print(cnt)
Problem: p03745
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())

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

index = 1

ans = 0

while index < n:
    ans += 1
    if a[index-1] < a[index]:
        flag = True
    elif a[index-1] > a[index]:
        flag = False
    else:
        for i in range(index,n):
            if a[index] != a[i]:
                if a[index] < a[i]:
                    flag = True
                else:
                    flag = False
    flag2 = True
    for i in range(index,n):
        if flag and a[i] < a[i-1]:
            index = i+1
            flag2 = False
            break
        elif a[i] > a[i-1] and flag == False:
            index = i+1
            flag2 = False
            break
    if flag2:
        break
if index == n:
    ans += 1
print(ans)

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

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())

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

index = 1

ans = 0

while index < n:
    ans += 1
    if a[index-1] < a[index]:
        flag = True
    elif a[index-1] > a[index]:
        flag = False
    else:
        flag3 = True
        for i in range(index,n):
            if a[index] != a[i]:
                flag3 = False
                if a[index] < a[i]:
                    flag = True
                    break
                else:
                    flag = False
                    break
        if flag3:
            break
    flag2 = True
    for i in range(index,n):
        if flag and a[i] < a[i-1]:
            index = i+1
            flag2 = False
            break
        elif a[i] > a[i-1] and flag == False:
            index = i+1
            flag2 = False
            break
    if flag2:
        break
if index == n:
    ans += 1
print(ans)