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

def lis(A: "Array[int]") -> int:
    from bisect import bisect_left

    
    dp = [A[0]]
    for i in A[1:]:
        if i >= dp[-1]:
            dp.append(i)
        else:
            dp[bisect_left(dp, i)] = i
    return len(dp)


def main():
    N, *A = map(int, open(0))
    ans = lis([-i for i in A])  
    print(ans)


if __name__ == "__main__":
    main()

Failing test case input:
5
0
0
-1
0
0

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

def lis(A: "Array[int]") -> int:
    from bisect import bisect_right

    
    dp = [A[0]]
    for i in A[1:]:
        if i >= dp[-1]:
            dp.append(i)
        else:
            dp[bisect_right(dp, i)] = i
    return len(dp)


def main():
    N, *A = map(int, open(0))
    ans = lis(A[::-1])  
    print(ans)


if __name__ == "__main__":
    main()

Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect






 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx-1] = li[i]

print(len(X))

Failing test case input:
5
2
1
4
5
3

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
import bisect






 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx] = li[i]

print(len(X))

Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

N = int(input())
A = [-int(input()) for _ in range(N)]

p = [A[0]]
for i in A[1:]:
    if p[-1] <= i:
        p.append(i)
    else:
        p[bisect.bisect_left(p,i)] = i
print (len(p))

Failing test case input:
5
1
0
1
1
0

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
A = [-int(input()) for _ in range(N)]

p = [A[0]]
for i in A[1:]:
    if p[-1] <= i:
        p.append(i)
    else:
        p[bisect.bisect_right(p,i)] = i
print (len(p))
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)[::-1]
q = deque([])

for i,j in enumerate(a):
  if i == 0:
    q.append(j)
    continue
  c = bisect.bisect_left(q,j)
  if c == 0:
    q.appendleft(j)
  else:
    q[c-1] = j
    
print(len(q))
  


Failing test case input:
5
10
-1
1
13
5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
q = deque([])

for i,j in enumerate(a):
  if i == 0:
    q.append(j)
    continue
  c = bisect.bisect_left(q,j)
  if c == 0:
    q.appendleft(j)
  else:
    q[c-1] = j
    
print(len(q))

Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect_left as BL

n = int(input())
a = [int(input()) for _ in range(n)]

b = []

ans = 1
b.append(a[n-1])

for i in range(n-2, -1, -1):
    if a[i] >= b[-1]:
        b.append(a[i])
    else:
        x = BL(b,a[i])
        b[x] = a[i]
        x -= 1
        while x >= 0:
            if b[x] > b[x+1]:
                b[x],b[x+1] = b[x+1],b[x]
                x -= 1
            else:
                break

print(len(b))



Failing test case input:
4
0
0
1
0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import bisect_right

n = int(input())
a = [int(input()) for _ in range(n)]

b = []

ans = 1
b.append(a[n-1])

for i in range(n-2, -1, -1):
    if a[i] >= b[-1]:
        b.append(a[i])
    else:
        x = bisect_right(b,a[i])
        b[x] = a[i]
        x -= 1
        while x >= 0:
            if b[x] > b[x+1]:
                b[x],b[x+1] = b[x+1],b[x]
                x -= 1
            else:
                break
    

print(len(b))
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

LIS = [10 ** 10 + 5]
n, *A = map(int, read().split())

for a in A:
    temp = 10 ** 10 - a
    if LIS[-1] <= temp:
        LIS.append(temp)
    else:
        pos = bisect_left(LIS, temp)
        LIS[pos] = temp
print(len(LIS))


Failing test case input:
5
4
1
4
9
3

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import bisect_left, bisect_right
from collections import deque
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
infi = 10 ** 20


n, *A = map(int, read().split())
LIS = deque([10 ** 10])
for a in A:
    a *= -1
    pos1 = bisect_left(LIS, a)
    pos2 = bisect_right(LIS, a)
    if LIS[-1] <= a:
        LIS.append(a)
    else:
        if LIS[pos1] == a:
            LIS[pos2] = a
        else:
            LIS[pos1] = a

print(len(LIS))

Problem: p02973
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


import sys 
from bisect import bisect_left
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,read().split()))


INF = 10**31
q = []

for a in A:
    idx = bisect_left(q, a)
    if idx == 0:
        q.append(a)
    else:
        q[idx-1] = a
print(len(q))

Failing test case input:
5
5
-1
6
9
3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):


import sys 
from bisect import bisect_left
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,read().split()))


INF = 10**31
q = deque([])

for a in A:
    idx = bisect_left(q, a)
    if idx == 0:
        q.appendleft(a)
    else:
        q[idx-1] = a
print(len(q))

Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
N = int(input())
seq = [-int(input()) for i in range(N)] 
LIS = [seq[0]]
for i in range(1,len(seq)):
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i])] = seq[i]
print(len(LIS))

Failing test case input:
5
4
1
4
9
3

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
seq = [-int(input()) for i in range(N)] 
LIS = [seq[0]]
for i in range(1,len(seq)):
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
print(len(LIS))
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import bisect

input = lambda: sys.stdin.readline().rstrip()

N = int(input())
A = [int(input()) for _ in range(N)]
A = A[::-1]


def solve():

    LIS = [A[0]]
    for i in range(1, N):

        if A[i] >= LIS[-1]:
            LIS.append(A[i])
        else:
            LIS[bisect.bisect_left(LIS, A[i])] = A[i]

    ans = len(LIS)
    print(ans)


if __name__ == '__main__':
    solve()


Failing test case input:
5
0
0
0
3
0

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
import bisect

input = lambda: sys.stdin.readline().rstrip()

N = int(input())
A = [int(input()) for _ in range(N)]
A = A[::-1]


def solve():

    LIS = [A[0]]
    for i in range(1, N):

        if A[i] >= LIS[-1]:
            LIS.append(A[i])
        else:
            LIS[bisect.bisect_right(LIS, A[i])] = A[i]

    ans = len(LIS)
    print(ans)


if __name__ == '__main__':
    solve()

Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
from collections import deque
n = int(input())
a = [int(input()) for _ in range(n)]
tree = deque([]) 
tree.append(a[0])

for a in a[1:]:
  index = bisect.bisect_left(tree, a)
  if index == 0:
    tree.append(a)
  else:
    tree[index-1] = a
print(len(tree))

    


    
    

Failing test case input:
5
8
-1
1
13
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect
from collections import deque
n = int(input())
a = [int(input()) for _ in range(n)]
tree = deque([]) 
tree.append(a[0])

for a in a[1:]:
  index = bisect.bisect_left(tree, a)
  if index == 0:
    tree.appendleft(a)
  else:
    tree[index-1] = a
print(len(tree))

Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import *
n = int(input())
a = [int(input()) for i in range(n)]

color = [-a[0]]
for i in range(1,n):
    if -a[i] >= color[-1]:
        color.append(-a[i])
    else:
        idx = bisect_left(color,-a[i])
        color[idx] = -a[i]

print(len(color))

Failing test case input:
5
4
1
4
17
3

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import *
n = int(input())
a = [int(input()) for i in range(n)]

color = [-a[0]]
for i in range(1,n):
    if -a[i] >= color[-1]:
        color.append(-a[i])
    else:
        idx = bisect_right(color,-a[i])
        color[idx] = -a[i]

print(len(color))
Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import bisect
from collections import deque

fastinput = sys.stdin.readline
N = int(fastinput())
A = [int(fastinput()) for j in range(N)]
surface = deque([A[0]])
surfMax = A[0]
surfMin = A[0]
color = 1
for n,a in enumerate(A):
    if n==0:
        continue
    if a<=surfMin:
        color += 1
        surface.appendleft(a)
        surfMin = a
    elif a>surfMax:
        surface[color-1] = a
        surfMax = a
    else:
        pos = bisect.bisect_left(surface,a) -1 
        surface[pos] = a
        if pos==0:
            surfMin = a
        if pos == color-1:
            surfMax = a
print(color)

Failing test case input:
4
-1
0
0
0

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
import bisect
from collections import deque

fastinput = sys.stdin.readline
N = int(fastinput())
A = [int(fastinput()) for j in range(N)]
surface = deque([A[0]])
surfMax = A[0]
surfMin = A[0]
color = 1
for n,a in enumerate(A):
    if n==0:continue

    if color == 1:
        c = surface[0]
        if a>c:
            surface[0] = a
            surfMax = a
            surfMin = a
        if a==c:
            surface.appendleft(a)
            color += 1
        if a<c:
            surface.appendleft(a)
            color += 1
            surfMin = a

    else:    
        if a<=surfMin:
            color += 1
            surface.appendleft(a)
            surfMin = a
        elif a>surfMax:
            surface[color-1] = a
            surfMax = a
        else:
            pos = bisect.bisect_left(surface,a) -1 
            surface[pos] = a
            if pos==0:
                surfMin = a
            if pos == color-1:
                surfMax = a
print(color)

Problem: p02973
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
import bisect
N=int(input())
L=deque()
for i in range(N):
  s=int(input())
  if i==0:
    L.append(s)
  else:
    if s<=L[0]:
      L.appendleft(s)
    else:
      L[bisect.bisect(L,s)-1]=s
print(len(L))

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import deque
import bisect
N=int(input())
L=deque()
for i in range(N):
  s=int(input())
  if i==0:
    L.append(s)
  else:
    if s<=L[0]:
      L.appendleft(s)
    else:
      L[bisect.bisect(L,s-1)-1]=s
print(len(L))

Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
from collections import deque
n = int(input())
l = deque([])
l.append(int(input()))
for i in range(n-1):
    a = int(input())
    if l[0] >= a:
        l.appendleft(a)
    else:
        l[bisect.bisect_left(l,a+1)-1] = a
print(len(l))

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect
from collections import deque
n = int(input())
l = deque([])
l.append(int(input()))
for i in range(n-1):
    a = int(input())
    if l[0] >= a:
        l.appendleft(a)
    else:
        l[bisect.bisect_left(l,a)-1] = a
print(len(l))
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
aa=list(map(int,sys.stdin.read().split()))
aa=aa[1:]
n=len(aa)
import bisect
bb=[]
for i in range(n):
    if not bb:
        bb.append(aa[-i-1])
    else:
        if bb[-1] <= aa[-i-1]:
            bb.append(aa[-i-1])
        else:
            j = bisect.bisect_left(bb,aa[-i-1])
            bb[j] = aa[-i-1]
print(len(bb))

Failing test case input:
5
0
0
0
3
0

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
aa=list(map(int,sys.stdin.read().split()))
aa=aa[1:aa[0]+1]
n=len(aa)
import bisect
bb=[]
for i in range(n):
    if not bb:
        bb.append(aa[-i-1])
    else:
        if bb[-1] <= aa[-i-1]:
            bb.append(aa[-i-1])
        else:
            j = bisect.bisect_right(bb,aa[-i-1])
            bb[j] = aa[-i-1]
print(len(bb))

Problem: p02973
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
from bisect import bisect_right
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(int(readline()) for _ in range(N))

    LIS = [INF]*N
    A.reverse()
    for a in A:
        i = bisect_right(LIS,a)
        LIS[i] = a
    print(bisect_right(LIS, INF))


if __name__ == '__main__':
    main()



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

Expected output:
2


Actual output:
5


Fixed submission (verdict: Accepted):
import sys
from bisect import bisect_right, bisect_left
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(int(readline()) for _ in range(N))

    LIS = [INF]*N
    A.reverse()
    for a in A:
        i = bisect_right(LIS,a)
        LIS[i] = a
    print(bisect_left(LIS, INF))


if __name__ == '__main__':
    main()

Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
N = int(input())
A = [int(input()) for _ in range(N)]
tmp = [A[0]]
for i in range(1, N):
    index = bisect.bisect_left(tmp, A[i])
    if index == 0:
        tmp.append(A[i])
    else:
        tmp[index-1] = A[i]

print(len(tmp))


Failing test case input:
5
8
-2
1
13
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
A = [-int(input()) for _ in range(N)]
tmp = [A[0]]
for i in A[1:N]:
    index = bisect.bisect(tmp, i)
    if index == len(tmp):
        tmp.append(i)
    else:
        tmp[index] = i

print(len(tmp))
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
N = int(input())
A = [int(input()) for i in range(N)]
A = [-a for a in A]

dp = []
for a in A:
    i = bisect.bisect_right(dp, a)
    if i >= len(dp):
        dp.append(a)
    else:
        dp[i] = a

print(N-len(dp))

Failing test case input:
4
0
0
0
0

Expected output:
4

Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
A = [-int(input()) for i in range(N)]


dp = []
for a in A:
    i = bisect.bisect_right(dp, a)
    if i >= len(dp):
        dp.append(a)
    else:
        dp[i] = a

print(len(dp))

Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect

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

def LIS(a, n):
	seq = []
	for ele in a:
		pos = bisect(seq, -ele)
		if len(seq) <= pos:
			seq.append(-ele)
		else:
			seq[pos] = -ele
	return len(seq)

print(LIS(a, n))

Failing test case input:
5
0
0
1
1
1

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
from bisect import bisect

n = int(input())

seq = []
for i in range(n):
	ele = int(input())
	pos = bisect(seq, -ele)
	if len(seq) <= pos:
		seq.append(-ele)
	else:
		seq[pos] = -ele

print(len(seq))

Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import bisect

def input():
    return sys.stdin.readline().rstrip()

def LIS(seq):
	l = [seq[0]]
	for i in range(1,len(seq)):
	    if seq[i] >= l[-1]:
	        l.append(seq[i])
	    else:
	        l[bisect.bisect_left(l, seq[i])] = seq[i]

	return(len(l))

def main():
	n=int(input())
	a=[int(input()) for _ in range(n)]
	print(LIS(a[::-1]))

main()

Failing test case input:
5
0
0
1
2
0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
import bisect

def input():
    return sys.stdin.readline().rstrip()

def LIS(seq):
	l = [seq[0]]
	for i in range(1,len(seq)):
	    if seq[i] >= l[-1]:
	        l.append(seq[i])
	    else:
	        l[bisect.bisect_right(l, seq[i])] = seq[i]

	return(len(l))

def main():
	n=int(input())
	a=[int(input()) for _ in range(n)]
	print(LIS(a[::-1]))

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



import heapq


def solve():
    N = int(input())
    A = []
    tails = []
    for _ in range(N):
        A.append(int(input()))
    A.reverse()
    a = A.pop()
    heapq.heappush(tails, a)
    while A:
        a = A.pop()
        t = heapq.heappop(tails)
        if a > t:
            heapq.heappush(tails, t)
        else:
            heapq.heappush(tails, a)
            heapq.heappush(tails, t)
    return len(tails)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Failing test case input:
5
0
1
1
2
1

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):



import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()

Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import heapq

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = []
heapq.heappush(ans, A[0])
for i in range(1, N):
    if A[i] > ans[0]:
        ans[0] = A[i]
    else:
        heapq.heappush(ans, A[i])

print(len(ans))


Failing test case input:
5
0
-1
1
4
0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect
from collections import deque

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans = deque([A[0]])
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index - 1] = A[i]
    else:
        ans.appendleft(A[i])

print(len(ans))

Problem: p02973
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from bisect import bisect_left, bisect_right
N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = (-1) * int(input())


LIS = [seq[0]]
for i in range(len(seq)):
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect_right(LIS, seq[i])] = seq[i]

print(len(LIS) - 1)


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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import bisect_left, bisect_right
N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = (-1) * int(input())


def getLIS(_N,a):
  INF = 1e18
  MaxP = _N+10
  dp = [INF for _ in range(MaxP)]
  for i in range(_N):
    dp[bisect_right(dp,a[i])] = a[i]

  
  return dp[:bisect_left(dp, INF)]

LIS2 = getLIS(N,seq)

print(len(LIS2))
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
N = int(input())
A = [int(input()) for _ in range(N)]
tmp = [A[0]]
for i in range(1, N):
    index = bisect.bisect_right(tmp, A[i])
    if index == 0:
        tmp.insert(0, A[i])
    else:
        tmp[index-1] = A[i]

print(len(tmp))


Failing test case input:
5
0
0
1
4
0

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
A = [-int(input()) for _ in range(N)]
tmp = [A[0]]
for i in A[1:N]:
    index = bisect.bisect(tmp, i)
    if index == len(tmp):
        tmp.append(i)
    else:
        tmp[index] = i

print(len(tmp))

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

def binSearch(S, x):
    a = -1
    b = len(S)-1

    while(a + 1 < b):
        c = (a+b)
        if S[c] > x:
            a = c
        else:
            b = c

    return b

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    S = []

    for a in A:
        if len(S) == 0 or S[-1] >= a:
            S.append(a)
        else:
            p = binSearch(S, a)
            S[p] = a
    
    print(len(S))


if __name__ == '__main__':
    main()


Failing test case input:
5
1
0
1
1
0

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

def binSearch(S, x):
    a = -1
    b = len(S)-1

    while(a + 1 < b):
        c = (a+b)
        if S[c] >= x:
            a = c
        else:
            b = c

    return b

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    S = []

    for a in A:
        if len(S) == 0 or S[-1] >= a:
            S.append(a)
        else:
            p = binSearch(S, a)
            S[p] = a
    
    print(len(S))


if __name__ == '__main__':
    main()

Problem: p02973
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
a=[int(input()) for _ in range(n)]
ans=[a[0]]
ansl=1
from bisect import bisect_right
for ai in a[1:]:
  tmp=bisect_right(ans,ai)
  if tmp<ansl:
    ans[tmp]=ai
  else:
    ans.append(ai)
    ansl+=1
print(ansl)

Failing test case input:
5
0
0
1
2
0

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(input()) for _ in range(n)]
ans=[-a[0]]
ansl=1
from bisect import bisect_right
for ai in a[1:]:
  tmp=bisect_right(ans,-ai)
  if tmp<ansl:
    ans[tmp]=-ai
  else:
    ans.append(-ai)
    ansl+=1
print(ansl)
Problem: p02973
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)[::-1]
x = []
heapify(x)
for i,j in enumerate(a):
    if i == 0:
        heappush(x,-j)
        continue
    m = -heappop(x)
    if j >= m:
        heappush(x,-j)
        heappush(x,-m)
    else:
        heappush(x,-j)
print(len(x))


Failing test case input:
5
1
0
2
1
0

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpln(n)
q = deque([])

for i,j in enumerate(a):
  if i == 0:
    q.append(j)
    continue
  c = bisect.bisect_left(q,j)
  if c == 0:
    q.appendleft(j)
  else:
    q[c-1] = j
    
print(len(q))

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


import bisect
def lis(seq):
    LIS = [seq[0]]
    for i in range(1, len(seq)):
        if seq[i] >= LIS[-1]:
            LIS.append(seq[i])
        else:
            LIS[bisect.bisect_left(LIS, seq[i])] = seq[i]
    return(len(LIS))

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

b = a[::-1]
print(lis(b))

Failing test case input:
5
0
0
0
2
0

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):


import bisect
def lis(seq):
    LIS = [seq[0]]
    for i in range(1, len(seq)):
        if seq[i] >= LIS[-1]:
            LIS.append(seq[i])
        else:
            LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
    return(len(LIS))

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

b = a[::-1]
print(lis(b))

Problem: p02973
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

N = int(input())
A = [-int(input()) for _ in range(N)]

dp = [float("inf")] * (N+1)
dp[0] = -1
dp[1] = A[0]

for i in range(1,N):
    dp[bisect.bisect_right(dp, A[i])] = A[i]

for i in reversed(range(N+1)):
    if dp[i] < float("inf"):
        print(i)
        break

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
A = [-int(input()) for _ in range(N)]

dp = [float("inf")] * (N+1)
dp[0] = -float("inf")
dp[1] = A[0]

for i in range(1,N):
    dp[bisect.bisect_right(dp, A[i])] = A[i]

for i in reversed(range(N+1)):
    if dp[i] < float("inf"):
        print(i)
        break
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import copy

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

for k in range(min(K, 41)):
    B = [0 for _ in range(N)]
    for i in range(N):
        left = max(i-A[i], 0)
        right = min(i+A[i], N-1)
        B[left] += 1
        if (right+1<N):
            B[right+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = copy.deepcopy(B)
print(A)


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

Expected output:
1 -1 1 2 1


Actual output:
[1, -1, 1, 2, 1]


Fixed submission (verdict: Accepted):
import copy

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

for k in range(min(K, 41)):
    B = [0 for _ in range(N)]
    for i in range(N):
        left = max(i-A[i], 0)
        right = min(i+A[i], N-1)
        B[left] += 1
        if (right+1<N):
            B[right+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = copy.deepcopy(B)
print(" ".join(list(map(str, A))))

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline

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


if a.count(0) == n:
    print(*a)
    exit()

for _ in range(k):
    b = [0]*n
    for i in range(n):
        if i-a[i] < 0:
            b[0] += 1
        else:
            b[i-a[i]] += 1
        if i+a[i]+1 < n:
            b[i+a[i]+1] -= 1
    
    judge = True
    tmp = 0
    for i in range(n):
        tmp += b[i]
        a[i] = tmp
        if tmp != n:
            judge = False
    if judge:
        break
print(*a)


Failing test case input:
5 3
0 0 0 0 0

Expected output:
4 4 5 4 4


Actual output:
0 0 0 0 0


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

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




for _ in range(k):
    b = [0]*n
    for i in range(n):
        if i-a[i] < 0:
            b[0] += 1
        else:
            b[i-a[i]] += 1

        if i+a[i]+1 < n:
            b[i+a[i]+1] -= 1
    
    judge = True
    tmp = 0
    for i in range(n):
        tmp += b[i]
        a[i] = tmp
        if tmp != n:
            judge = False
    if judge:
        break
print(*a)
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math

def action(A, N):
  B = [0] * N
  for i in range(N):
    s = max(0, math.ceil(i - A[i] - 0.5))
    e = min(N, math.ceil(i + A[i] + 0.5))
    for j in range(s, e):
      B[j] += 1 
  return B

def main():
  N, K = map(int, input().split())
  A = [int(s) for s in input().split()]

  for i in range(K):
    A = action(A, N)
    if A[0] == N & all(A):
      break
      
  print(A)

if __name__ == '__main__':
  main()

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

Expected output:
3 4 5 3 3


Actual output:
[3, 4, 5, 3, 3]


Fixed submission (verdict: Accepted):
def action(A, N):
  B = [0] * N
  for i, bright in enumerate(A):
    s = max(0, i - bright)
    B[s] += 1
    e = min(N, i + bright)
    if e < N - 1:
      B[e + 1] -= 1
  
  for i in range(N - 1):
    B[i + 1] += B[i]
  return B

def main():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))

  for i in range(K):
    A = action(A, N)
    if (A[0] == N) & all(A):
      break
      
  print(*A, sep=" ")

if __name__ == '__main__':
  main()

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
from copy import deepcopy
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    if a[0] == n and a[-1] == n:
        if sum(a) == n*n:
            print(a)
            sys.exit()
    b = [0]*n
    for i in range(n):
        b[i] += 1
        for j in range(1, a[i]+1):
            if i-j >= 0: b[i-j] += 1
            if i+j < n: b[i+j] += 1
    a = deepcopy(b)
print(a)

Failing test case input:
5 0
0 0 0 0 1

Expected output:
0 0 0 0 1


Actual output:
[0, 0, 0, 0, 1]


Fixed submission (verdict: Accepted):
from copy import deepcopy
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    b = [0] * (n+1)
    for i in range(n):
        b[max(0, i-a[i])] += 1
        b[min(n, i+a[i]+1)] -= 1
    for i in range(n-1):
        b[i+1] += b[i]
    b.pop()
    a = deepcopy(b)
    
    if bisect.bisect_left(a, n) == 0: break
    
print(*a)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, K= map(int,input().split())
A = list(map(int,input().split()))
p=0
while p<100:
  B=[0]*N
  for i in range(N):
    count = 0
    for j in range(N):
      if A[j]+1>abs(j-i):
        count +=1
    B[i] = count
  if min(A)==N:
    break
  A = B
  p +=1
print(*A)

Failing test case input:
5 1
0 1 1 1 1

Expected output:
2 2 3 3 2


Actual output:
5 5 5 5 5


Fixed submission (verdict: Accepted):
N, K= map(int,input().split())
A = list(map(int,input().split()))
a=A[:]
for _ in range(K):
  B=[0]*(N+1)
  for i in range(N):
    t = a[i]
    B[max(i-t,0)] +=1
    B[min(i+t+1,N)] -=1
  for i in range(N):
    B[i+1] += B[i]
  a=B[:N]        
  if min(a)==N:
    break
print(*a)
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K):
        b = [0] * (N+1)
        for j in range(N):
            a = A[j]
            b[max(j-a, 0)] += 1
            b[min(j+a+1, N)] -= 1
        for k in range(1,N+1):
            b[k] += b[k-1]
        b = b[:N]
        print(b)
        if b == A:
            break
        else:
            A = b
    print(*A)

if __name__ == '__main__':
    main()

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

Expected output:
3 4 5 4 3


Actual output:
[2, 2, 3, 2, 2]
[3, 4, 5, 4, 3]
3 4 5 4 3


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K):
        b = [0] * (N+1)
        for j in range(N):
            a = A[j]
            b[max(j-a, 0)] += 1
            b[min(j+a+1, N)] -= 1
        for k in range(1,N+1):
            b[k] += b[k-1]
        b = b[:N]
        if b == A:
            break
        else:
            A = b
    print(*A)

if __name__ == '__main__':
    main()

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    if min(B) == N: break
    B, A = A, B

print(*A)


Failing test case input:
5 6
0 1 0 4 0

Expected output:
5 5 5 5 5


Actual output:
4 5 5 5 4


Fixed submission (verdict: Accepted):

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


for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    B, A = A, B
    if min(A) == N:
        break

print(*A)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import copy

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


for k in range(K):
    B = [0 for _ in range(N)]
    for i in range(1, N+1):
        left = max(i-A[i-1], 1)
        right = min(i+A[i-1], N)
        for j in range(left, right+1):
            B[j-1]+=1
    A = copy.deepcopy(B)
print(A)

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

Expected output:
3 3 4 3 3


Actual output:
[3, 3, 4, 3, 3]


Fixed submission (verdict: Accepted):
import copy

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

for k in range(min(K, 41)):
    B = [0 for _ in range(N)]
    for i in range(N):
        left = max(i-A[i], 0)
        right = min(i+A[i], N-1)
        B[left] += 1
        if (right+1<N):
            B[right+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = copy.deepcopy(B)
print(" ".join(list(map(str, A))))
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k=map(int,input().split())
A=list(map(int,input().split()))

B=[0 for _ in range(n)]

for K in range(10):
    for i in range(n):
        num=A[i]
        for j in range(max(0,i-num),min(n,i+num+1)):
            B[j] +=1
    A=B
    B=[0 for _ in range(n)]
    if sum(A)==n**2:break
print(*A)

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

Expected output:
2 0 0 1 0


Actual output:
5 5 5 5 5


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for i in range(n)]

for m in range(k):
    B=[0 for _ in range(n)]
    for i in range(n):
        l,r=max(0,i-A[i]),min(n-1,i+A[i])
        B[l] +=1
        if r+1<n:B[r+1] -=1
    for i in range(n-1):
        B[i+1]=B[i]+B[i+1]
    A=B
    if A==C:break
print(*A)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
n,k=mi()
a=li()
for i in range(k):
    tmp=[0]*n
    for j in range(n):
        x1=max(0,j-a[j])
        x2=min(n+1,j+a[j])
        tmp[x1]+=1
        if(x2<n-1):
            tmp[x2+1]-=1
       
    a[0]=tmp[0]
    for j in range(1,n):
        tmp[j]+=tmp[j-1]
        a[j]=tmp[j]
    if(min(a)>=n):
        print([n]*n)
        exit(0)
print(*a)

Failing test case input:
5 6
0 1 0 4 0

Expected output:
5 5 5 5 5


Actual output:
[5, 5, 5, 5, 5]


Fixed submission (verdict: Accepted):
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
n,k=mi()
a=li()
for i in range(k):
    tmp=[0]*n
    for j in range(n):
        x1=max(0,j-a[j])
        x2=min(n+1,j+a[j])
        tmp[x1]+=1
        if(x2<n-1):
            tmp[x2+1]-=1
       
    f=1
    a[0]=tmp[0]
    if(a[0]<n):
        f=0
    for j in range(1,n):
        tmp[j]+=tmp[j-1]
        a[j]=tmp[j]
        if(a[j]<n):
            f=0
    if(f):
        break
print(*a)

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

for _ in range(min(50, k)):
    l = [0]*(n+1)
    for i in range(n):
        l[max(i-a[i], 0)] += 1 
        l[min(i+a[i]+1, n)] -= 1 
        print(l)
    add = 0
    for i in range(n):
        add += l[i] 
        a[i] = add
print(*a)


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

Expected output:
3 4 4 3 3


Actual output:
[1, -1, 0, 0, 0, 0]
[2, -1, 0, -1, 0, 0]
[2, -1, 1, -2, 0, 0]
[2, -1, 1, -1, -1, 0]
[2, -1, 1, 0, -1, -1]
[1, 0, 0, -1, 0, 0]
[2, 0, 0, -2, 0, 0]
[3, 0, 0, -2, 0, -1]
[3, 1, 0, -2, 0, -2]
[3, 1, 0, -1, 0, -3]
3 4 4 3 3


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

for _ in range(min(50, k)):
    l = [0]*(n+1)
    for i in range(n):
        l[max(i-a[i], 0)] += 1 
        l[min(i+a[i]+1, n)] -= 1 
    add = 0
    for i in range(n):
        add += l[i] 
        a[i] = add
print(*a)
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n, k = ZZ()
    A = ZZ() + [0]

    for _ in range(k):
        if A[0] >= n: break
        nA = [0] * (n+1)
        for i in range(n):
            nA[max(0, i-A[i])] += 1
            nA[min(n-1, i+1+A[i])] -= 1
        for i in range(1, n+1): nA[i] += nA[i-1]
        A = nA
    print(*A[:-1])

    return

if __name__ == '__main__':
    main()


Failing test case input:
5 2
0 0 0 2 0

Expected output:
3 3 4 4 3


Actual output:
3 3 3 3 0


Fixed submission (verdict: Accepted):
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n, k = ZZ()
    A = ZZ()+[0]

    for _ in range(k):
        if all([A[i] >= n for i in range(n)]): break
        nA = [0] * (n+1)
        for i in range(n):
            nA[max(0, i-A[i])] += 1
            nA[min(n, i+1+A[i])] -= 1
        for i in range(1, n+1): nA[i] += nA[i-1]
        A = nA
    print(*A[:-1])

    return

if __name__ == '__main__':
    main()

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = 5
K = 10000000000000
A = [1, 0, 0, 1, 0]




lenA = len(A)
for i in range(K):

    B = [0 for _ in range(lenA)]

    for j in range(lenA):
        num = A[j]


        B[max(0, j - num): min(lenA, j + num + 1)] = [b + 1 for b in B[max(0, j - num): min(lenA, j + num + 1)]]

    if all([a == b for a, b in zip(A,B)]):

        break
    else:
        A = B
print(' '.join(map(str, A)))

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

Expected output:
-9 0 1 0 1


Actual output:
5 5 5 5 5


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

lenA = len(A)
for i in range(K):
    B = [0 for _ in range(lenA)]

    for j in range(lenA):
        num = A[j]

        if j - num >= 0:
            B[max(0, j - num)] += 1
        else:
            B[0] += 1
        if j + num + 1 < lenA:
            B[min(lenA, j + num + 1)] -= 1

    for i in range(1, lenA):
        B[i] = B[i-1] + B[i]
    if all([a == b for a, b in zip(A,B)]):

        break
    else:
        A = B

print(' '.join(map(str, A)))

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, k = map(int, input().split())

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

from itertools import accumulate

aa

for _ in range(k):
    d = [0] * n

    for i, a in enumerate(aa):
        d[max(i-a, 0)] += 1
        end = i+1+a
        if end < n:
            d[end] -= 1

    d = list(accumulate(d))
    if aa == d:
        break
    aa = d

print(aa)

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

Expected output:
3 4 4 4 3


Actual output:
[3, 4, 4, 4, 3]


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

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

from itertools import accumulate

aa

for _ in range(k):
    d = [0] * n

    for i, a in enumerate(aa):
        d[max(i-a, 0)] += 1
        end = i+1+a
        if end < n:
            d[end] -= 1

    d = list(accumulate(d))
    if aa == d:
        break
    aa = d


print(' '.join(str(a) for a in aa))
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


B = [0]*N
for _ in range(K):
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    A[0] = 0
    for i in range(1,N):
        A[i] = 0
        B[i] += B[i-1]
    if min(B) == N: break
    B, A = A, B

print(*A)


Failing test case input:
5 6
0 1 0 4 0

Expected output:
5 5 5 5 5


Actual output:
0 0 0 0 0


Fixed submission (verdict: Accepted):

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


for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    B, A = A, B
    if min(A) == N:
        break

print(*A)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
readline=sys.stdin.readline

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

def calc(A):
    B = [0] * len(A)
    for i in range(len(A)):
        B[max(0,i - A[i])] += 1
        if i + A[i] + 1 < len(A):
            B[i + A[i] + 1] -= 1
    for i in range(1,len(B)):
        B[i] = B[i - 1] + B[i]
    return B

for i in range(K):
  A = calc(A)
  if len(set(A)) == 1:
    print(*A)
    break
else:
  print(*A)



Failing test case input:
5 3
0 0 0 0 0

Expected output:
4 4 5 4 4


Actual output:
1 1 1 1 1


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

N,K = map(int,readline().split())
A = list(map(int,readline().split()))
def calc(A):
    B = [0] * len(A)
    for i in range(len(A)):
        B[max(0,i - A[i])] += 1
        if i + A[i] + 1 < len(A):
            B[i + A[i] + 1] -= 1
    for i in range(1,len(B)):
        B[i] = B[i - 1] + B[i]
    return B

for i in range(K):
  A = calc(A)
  if len(set(A)) == 1 and A[0] == N:
    print(*A)
    break
else:
  print(*A)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k):
    acc = [0 for j in range(n+1)]
    for j in range(n):
        acc[max(0, j - a[j])] += 1
        acc[min(n-1, j + a[j]) + 1] -= 1
    for j in range(n):
        acc[j+1] += acc[j]
    a = acc[:-1]
    if sum(a) == n * n:
        print("i")
        break
print(" ".join(map(str, a)))


Failing test case input:
5 6
0 1 0 4 0

Expected output:
5 5 5 5 5


Actual output:
i
5 5 5 5 5


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k):
    acc = [0 for j in range(n+1)]
    for j in range(n):
        acc[max(0, j - a[j])] += 1
        acc[min(n-1, j + a[j]) + 1] -= 1
    for j in range(n):
        acc[j+1] += acc[j]
    a = acc[:-1]
    if sum(a) == n * n:

        break
print(" ".join(map(str, a)))
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
cnt=0
while a[0]!=n and cnt<k:
  cnt+=1
  for i in range(n):
    b[max(0,i-a[i]):min(n,i+a[i]+1)]=map(lambda x:x+1,b[max(0,i-a[i]):min(n,i+a[i]+1)])
  a=b
  b=[0]*n
print(a)



Failing test case input:
5 0
-1 0 1 0 1

Expected output:
-1 0 1 0 1


Actual output:
[-1, 0, 1, 0, 1]


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
c=[0]*n
cnt=0
while cnt<min(k,101):
  cnt+=1
  for i in range(n):
    b[max(0,i-a[i])]+=1
    if i+a[i]<n-1:
      b[i+a[i]+1]-=1
    c[0]=b[0]
  for j in range(n-1):
    c[j+1]=c[j]+b[j+1]
  a=c
  b=[0]*n
  c=[0]*n
print(*a)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, k = map(int, input().split())
A = list(map(int, input().split()))
for i in range(k):
    B = [0] * (n+1)
    for j in range(n):
        B[max(0, j-A[j])] += 1
        B[min(n, j+A[j])] -= 1
    A[0] = B[0]
    for j in range(1, n):
        A[j] = A[j-1]+B[j]
    if A == [n]*n:
        print(*A)
        exit()
print(*A)


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

Expected output:
3 4 4 4 3


Actual output:
1 2 2 2 2


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
A = list(map(int, input().split()))
for i in range(k):
    B = [0] * (n+1)
    for j in range(n):
        B[max(0, j-A[j])] += 1
        B[min(n, j+A[j]+1)] -= 1
    A[0] = B[0]
    for j in range(1, n):
        A[j] = A[j-1]+B[j]
    if A == [n]*n:
        print(*A)
        exit()
print(*A)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
for j in range(min(K,int(math.log2(N)))):
	B = [0]*N
	for i in range(N):
		l = max(0,i-A[i])
		r = min(N-1,i+A[i])
		B[l] += 1
		if r < N-1:
			B[r+1] -= 1
	for i in range(1,N):
		B[i] += B[i-1]
	A = B
print(' '.join(map(str,A)))


Failing test case input:
5 3
0 0 0 0 0

Expected output:
4 4 5 4 4


Actual output:
2 3 3 3 2


Fixed submission (verdict: Accepted):
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
for j in range(min(K,50)):
	B = [0]*N
	for i in range(N):
		l = max(0,i-A[i])
		r = min(N-1,i+A[i])
		B[l] += 1
		if r < N-1:
			B[r+1] -= 1
	for i in range(1,N):
		B[i] += B[i-1]
	A = B
print(' '.join(map(str,A)))
Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
now = list(mapint())
if sum(now)==0:
    print(*now)
else:
    for k in range(K):
        nx = [0]*N
        for i, a in enumerate(now):
            for m in range(max(0, i-a), min(i+a+1, N)):
                nx[m] += 1
        now = nx[:]
        if sum(now)==N**2:
            break
    print(*now)

Failing test case input:
5 2
0 0 0 0 0

Expected output:
2 3 3 3 2


Actual output:
0 0 0 0 0


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
now = list(mapint())
from itertools import accumulate
iteration = min(N.bit_length()*4, K)
for k in range(iteration):
    nx = [0]*N
    for i, a in enumerate(now):
        nx[max(0, i-a)] += 1
        if i+a+1<N:
            nx[i+a+1] -= 1
    nx = list(accumulate(nx))
    now = nx[:]
print(*now)

Problem: p02647
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
def update(A,N):
    B=[0 for i in range(N+1)]

    for i in range(N):
        l = max(0,i-A[i])
        r = min(N,i+A[i]+1)
        B[l]+=1
        B[r]-=1
    A[0]=B[0]
    for i in range(1,N):
        B[i]+=B[i-1]
        A[i]=B[i]

def resolve():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    for i in range(min(M,int(math.log2(N)))):
        update(A,N)
    print(" ".join(map(str,A)))
resolve()

Failing test case input:
5 3
1 0 0 1 0

Expected output:
4 5 5 5 4


Actual output:
3 3 4 4 3


Fixed submission (verdict: Accepted):
def update(A,N):
    B=[0 for i in range(N+1)]

    for i in range(N):
        l = max(0,i-A[i])
        r = min(N,i+A[i]+1)
        B[l]+=1
        B[r]-=1
    x = A[0] == B[0]
    A[0]=B[0]
    for i in range(1,N):
        B[i]+=B[i-1]
        x = x and A[i] == B[i]
        A[i]=B[i]
    return x

def resolve():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    for i in range(M):
        x=update(A,N)
        if x:
            break
    print(" ".join(map(str,A)))
resolve()