qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N, K = NMI()
    A = NLI()

    for k in range(min(K, 500)):
        tmp = [0] * (N+1)
        for i, a in enumerate(A):
            tmp[max(0, i-a)] += 1
            tmp[min(N, i+a+1)] -= 1
        cum = [0] * (N+1)
        for i, t in enumerate(tmp):
            if i == 0:
                cum[0] = t
                continue
            cum[i] = cum[i-1] + t
        A = cum[:-1]
    print(A)
    

if __name__ == "__main__":
    main()

Fixed code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N, K = NMI()
    A = NLI()

    for k in range(min(K, 42)):
        tmp = [0] * (N+1)
        for i, a in enumerate(A):
            tmp[max(0, i-a)] += 1
            tmp[min(N, i+a+1)] -= 1
        cum = [0] * (N+1)
        for i, t in enumerate(tmp):
            if i == 0:
                cum[0] = t
                continue
            cum[i] = cum[i-1] + t
        A = cum[:-1]
    print(" ".join(map(str, A)))


if __name__ == "__main__":
    main()
Buggy code:
def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    for _ in range(41):
        cumsum = [0 for _ in range(N)]
        for i, a in enumerate(A):
            left = max(0, i - a)
            cumsum[left] += 1
            right = i + 1 + a
            if right <= N - 1:
                cumsum[right] -= 1
        for i in range(1, N):
            cumsum[i] += cumsum[i - 1]
        A = cumsum
    print(' '.join(map(str, A)))


if __name__ == '__main__':
    main()

Fixed code:
def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    if K >= 42:
        print(' '.join([str(N) for _ in range(N)]))
        return
    for _ in range(K):
        cumsum = [0 for _ in range(N)]
        for i, a in enumerate(A):
            left = max(0, i - a)
            cumsum[left] += 1
            right = i + 1 + a
            if right <= N - 1:
                cumsum[right] -= 1
        for i in range(1, N):
            cumsum[i] += cumsum[i - 1]
        A = cumsum
    print(' '.join(map(str, A)))
 
 
if __name__ == '__main__':
    main()
Buggy code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

n = 2 * 10**5
k = 2 * 10**5
a = [0] * n

for i in range(min(k, 450)):
    tmp = [0] * (n + 1)
    for j in range(n):
        tmp[max(0, j - a[j])] += 1
        tmp[min(n, j + a[j] + 1)] -= 1
    
    cnt = 0
    for j in range(n):
        cnt += tmp[j]
        a[j] = cnt

for i in range(n):
    print(a[i], end='')

Fixed code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

for i in range(min(k, 450)):
    tmp = [0] * (n + 1)
    for j in range(n):
        tmp[max(0, j - a[j])] += 1
        tmp[min(n, j + a[j] + 1)] -= 1
    
    cnt = 0
    for j in range(n):
        cnt += tmp[j]
        a[j] = cnt

for i in range(n):
    print(a[i], end=' ')
Buggy code:
from itertools import accumulate

def mi():
    return map(int, input().split())

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        if A != list(accumulate(l)):
            A = accumulate(l)
        else:
            break
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()

Fixed code:
from itertools import accumulate

def mi():
    return map(int, input().split())

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        if A != list(accumulate(l)):
            A = list(accumulate(l))
        else:
            break
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()
Buggy code:
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 20:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break

Fixed code:
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 50:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break
print(*A)
Buggy code:
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    _max = max
    _min = min
    for _ in range(50):
        C = [0] * n
        for i in range(n):
            a = A[i]
            l = _max(0, i - a)
            r = _min(n, i + a + 1)
            C[l] += 1
            if r < n:
                C[r] -= 1
        r = 0
        for i in range(n):
            r += C[i]
            A[i] = r
        if A == [n] * n:
            break
    print(" ".join(map(str, A)))
main()

Fixed code:
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    _max = max
    _min = min
    for _ in range(k):
        C = [0] * n
        i = 0
        for a in A:
            l = _max(0, i - a)
            r = _min(n, i + a + 1)
            C[l] += 1
            if r < n:
                C[r] -= 1
            i += 1
        r = 0
        for i in range(n):
            r += C[i]
            A[i] = r
        if A == [n] * n:
            break
    print(" ".join(map(str, A)))
main()
Buggy code:
import itertools

N, K = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * (N+1)
chk = [N] *N
for k in range(K):
    if A == chk:
        break
    for i in range(N):
        if A[i] == 0:
            B[i] += 1
            B[i+1] -= 1
            continue
        l = i - A[i]
        r = i + A[i]
        if l <= 0:
            B[0] += 1
        else:
            B[l] += 1
        if r >= N-1:
            B[N] -= 1
        else:
            B[r+1] -= 1        
    A = list(itertools.accumulate(B))[:-1]
    B = [0] * (N+1)
print(A)
#print("B = " ,B)

Fixed code:
import itertools

N, K = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * (N+1)
chk = [N] *N
for k in range(K):
    if A == chk:
        break
    for i in range(N):
        if A[i] == 0:
            B[i] += 1
            B[i+1] -= 1
            continue
        l = i - A[i]
        r = i + A[i]
        if l <= 0:
            B[0] += 1
        else:
            B[l] += 1
        if r >= N-1:
            B[N] -= 1
        else:
            B[r+1] -= 1        
    A = list(itertools.accumulate(B))[:-1]
    B = [0] * (N+1)
print(*A)
#print("B = " ,B)
Buggy code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

def s(n,a):
  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(n):
    b[i+1] = b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(A)
      

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

def s(n,a):
  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(n-1):
    b[i+1] += b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(*A)
Buggy code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n

if(k > log2(n)):
    for i in range(n):
        print(n,end=" ")

else:
    for j in range(k):
        b = [0]*n
        for i in range(n):
            l = max(0,i-a[i])
            r = min(n-1,a[i]+i)
            b[l] += 1
            if(r+1<n):
                b[r+1] -= 1
        for i in range(1,n):
            b[i] += b[i-1]
        a = b


    for i in a:
        print(i,end=" ")


Fixed code:
from math import log2
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n

if(k > 10*log2(n) + 1):
    for i in range(n):
        print(n,end=" ")

else:
    for j in range(k):
        b = [0]*n
        for i in range(n):
            l = max(0,i-a[i])
            r = min(n-1,a[i]+i)
            b[l] += 1
            if(r+1<n):
                b[r+1] -= 1
        for i in range(1,n):
            b[i] += b[i-1]
        a = b


    for i in a:
        print(i,end=" ")
Buggy code:
import math
n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    for k in range(1,n):
        a1[k]=a1[k-1]+a1[k]
    a=a1[:n]
    a1=[0]*n
print(' '.join([str(n) for n in a]))


Fixed code:
import math
n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    for k in range(1,n):
        a1[k]=a1[k-1]+a1[k]
    a=a1[:n]
    a1=[0]*(n+1)
print(' '.join([str(n) for n in a]))
Buggy code:
@njit
def solve():
  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)
  
solve()

Fixed code:
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)
Buggy code:
from itertools import accumulate
n, k, *A = map(int, open(0).read().split())
for _ in range(min(k, 99)):
    B = [0] * (n+1)
    for i in range(n):
        B[max(0, i-A[i])] += 1
        B[min(n, i+A[i]+1)] -= 1
    A = list(accumulate(B))[:n]
print(A)

Fixed code:
from itertools import accumulate
n, k, *A = map(int, open(0).read().split())
for _ in range(min(k, 50)):
    B = [0] * (n+1)
    for i in range(n):
        B[max(0, i-A[i])] += 1
        B[min(n, i+A[i]+1)] -= 1
    *A, = accumulate(B)
print(*A[:n])
Buggy code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0]*N
for i in range(K):
    for j in range(N):
        g = math.ceil(j+1-A[j]-0.5)
        if g<1:
            g=1
        h = math.floor(j+1+A[j]+0.5)
        if h>N:
            h=N
        for x in range(g,h+1):
            A2[x-1]+=1
    A=A2[:]
    A2 = [0]*N
    c = 0
    for p in range(N):
        c+=A[p]
    if c => N*N:
        break

print(*A)


Fixed code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0]*(N+1)
for i in range(K):
    for j in range(N):
        g = math.ceil(j+1-A[j]-0.5)
        if g<1:
            g=1
        h = math.floor(j+1+A[j]+0.5)
        if h>N:
            h=N
        A2[g-1]+=1
        A2[h]-=1
    A[0]=A2[0]
    for j in range(1, N):
        A[j]=A[j-1]+A2[j]
    A2 = [0]*(N+1)
    c = 0
    for p in range(N):
        c+=A[p]
    if c >= N*N:
        break

print(*A)
Buggy code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
b = [0 for i in range(N+2)]
if K > 70:
    ans = [N for i in range(N)]
    print(*ans)
else:
    for _ in range(K):
        for i in range(N+2):
            b[i] = 0
        for i in range(N):
            b[max(0, i+1-a[i])] += 1
            b[min(N+1, i+1+a[i]+1)] -= 1
        for i in range(1, N+1):
            b[i] += b[i-1]
            a[i-1] = b[i]
    print(*a)

Fixed code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
b = [0 for i in range(N+2)]
if K > 70:
    ans = [N for i in range(N)]
    print(*ans)
else:
    for _ in range(K):
        for i in range(N+2):
            b[i] = 0
        for i in range(N):
            b[max(0, i+1-A[i])] += 1
            b[min(N+1, i+1+A[i]+1)] -= 1
        for i in range(1, N+1):
            b[i] += b[i-1]
            A[i-1] = b[i]
    print(*A)
Buggy code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, k = LI()
    a = LI()
    for i in range(k):
        bit = [0] * (n+1)
        for j in range(n):
            bit[max(0, j - a[j])] += 1
            bit[min(n, j + a[j] + 1)] -= 1
        f = 0
        bit = list(itertools.accumulate(bit))
        for j in range(n):
            a[j] = bit[j]
            if a[j] < n:
                f = 1
        if f:
            print(bit[0])
            continue
        break
    print(*a)
    return


#main
if __name__ == '__main__':
    solve()


Fixed code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, k = LI()
    a = LI()
    for i in range(k):
        bit = [0] * (n+1)
        for j in range(n):
            bit[max(0, j - a[j])] += 1
            bit[min(n, j + a[j] + 1)] -= 1
        f = 0
        bit = list(itertools.accumulate(bit))
        for j in range(n):
            a[j] = bit[j]
            if a[j] < n:
                f = 1
        if f:
            continue
        break
    print(*a)
    return


#main
if __name__ == '__main__':
    solve()
Buggy code:
from heapq import heappush, heappop

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

while K and sum(A) < N * N :
  l = [0] * N
  h = []
  for i in range(N) :
    while h and h[0] < i :
      heappop(h)
    l[i] = len(h)
    heappush(h, (i + A[i]))
    
  r = [0] * N
  h = []
  for i in range(N - 1, -1, -1) :
    while h and h[0] > i :
      heappop(h)
    r[i] = len(h)
    heappush(h, (i - A[i]))
    
  for i in range(N) :
    A[i] = l[i] + r[i] + 1
    
  K -= 1
  
print(*A)

Fixed code:
from heapq import heappush, heappop

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

while K and sum(A) < N * N :
  l = [0] * N
  h = []
  for i in range(N) :
    while h and h[0] < i :
      heappop(h)
    l[i] = len(h)
    heappush(h, (i + A[i]))
    
  r = [0] * N
  h = []
  for i in range(N - 1, -1, -1) :
    while h and h[0] < -i :
      heappop(h)
    r[i] = len(h)
    heappush(h, (-(i - A[i])))
    
  for i in range(N) :
    A[i] = l[i] + r[i] + 1
    
  K -= 1
  
print(*A)
Buggy code:
n,k=map(int,input().split())
A=list(map(int,input().split()))

def culc(L):
    subL=[0]*(n+1)

    for i in range(n):
        temp=L[i]
        bottom=max(i-temp,0)
        top=min(i+temp,n-1)

        subL[bottom]+=1
        subL[top+1]-=1
    
    resL=[0]*n
    resL[0]=subL[0]
    for i in range(1,n):
        resL[i]=resL[i-1]+subL[i]

    return resL

for i in range(min(k,50)):
    A=culc(A)

print(A)


Fixed code:
n,k=map(int,input().split())
A=list(map(int,input().split()))

def culc(L):
    subL=[0]*(n+1)

    for i in range(n):
        temp=L[i]
        bottom=max(i-temp,0)
        top=min(i+temp,n-1)

        subL[bottom]+=1
        subL[top+1]-=1
    
    resL=[0]*n
    resL[0]=subL[0]
    for i in range(1,n):
        resL[i]=resL[i-1]+subL[i]

    return resL

for i in range(min(k,50)):
    A=culc(A)

print(*A)
Buggy code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

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

    a = l[:]

print(a)

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

for i in range(min(41, k)):
    t = [0] * (n+1)
    for j in range(n):
        t[max(0, j-a[j])] += 1
        t[min(j+a[j]+1, n)] -= 1

    for j in range(1, n):
        t[j] += t[j-1]
    a = t[:n]

print(*a)
Buggy code:
N, K = map(int, input().split())
import numpy as np
A = np.array(input().split(), dtype=int)
I = np.arange(0, N)
for i in range(K):
  X = np.zeros(N + 1, int)
  np.add.at(X, np.maximum(0, I - A), 1)
  np.add.at(X, np.minimum(N, I + A + 1), -1)
  A = X.cumsum()[:-1]
  if np.all(A == N):
    break
print(A)

Fixed code:
N, K = map(int, input().split())
import numpy as np
A = np.array(input().split(), dtype=int)
I = np.arange(0, N)
for i in range(K):
  X = np.zeros(N + 1, int)
  np.add.at(X, np.maximum(0, I - A), 1)
  np.add.at(X, np.minimum(N, I + A + 1), -1)
  A = X.cumsum()[:-1]
  if np.all(A == N):
    break
print(*A)
Buggy code:
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

from itertools import accumulate
    
for _ in range(K):
	ans=[0]*(N+1)
    for i,a in enumerate(A):
        ans[max(0,i-a)]+=1
        ans[min(i+a+1,N)]-=1
    A = list(accumulate(ans))[:-1]
    if all(i == N for i in A):
        break
print(*A)

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

from itertools import accumulate

if N-min(A) <= K:
    print(*[N]*N)
    exit()
    
ans=[0]*(N+1)
for _ in range(K):
    for i,a in enumerate(A):
        ans[max(0,i-a)]+=1
        ans[min(i+a+1,N)]-=1
    A = list(accumulate(ans))[:-1]
    ans=[0]*(N+1)
    if all(i == N for i in A):
        break
print(*A)
Buggy code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
    
N, K = mi()
A = li()

#light = [0] * (N+2)
#A = [0] + A + [0]
#print(math.log(N, 2))

thre = 0
for i in range(N):
    if A[i] < i:
        thre = max(thre, i-A[i])

if K >= min(math.log(N, 2)//2, thre):
        for i in range(N):
            print(N, '', end='')
        print()
        exit()


for i in range(K):
    new = [0] * (N+1)
    for j in range(N):
        new[max(j-A[j], 0)] += 1
        new[min(j+A[j]+1, N)] += -1
        #print(new)
    new = list(accumulate(new))
    A = new[:N]

for i in range(N):
    print(A[i], '', end='')
print()

Fixed code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
    
N, K = mi()
A = li()
 
#light = [0] * (N+2)
#A = [0] + A + [0]
#print(math.log(N, 2))
'''
thre = 0
for i in range(N):
    if A[i] < i:
        thre = max(thre, i-A[i])
'''
if K > pow(N, 0.5) + 1:
        for i in range(N):
            print(N, '', end='')
        print()
        exit()
 
 
for i in range(K):
    new = [0] * (N+1)
    for j in range(N):
        new[max(j-A[j], 0)] += 1
        new[min(j+A[j]+1, N)] += -1
        #print(new)
    new = list(accumulate(new))
    A = new[:N]
 
for i in range(N):
    print(A[i], '', end='')
print()
Buggy code:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

# N, k = map(int, input().split())
# prev_arr = list(map(int, input().split()))

N = k = 200000
prev_arr = [0]*N

count = 0
for i in range(min(k, 3*int(math.log(N))+10)):
    arr = [0]*N
    for j in range(N):
        left = max(0, j-prev_arr[j])
        right = min(N-1, j+prev_arr[j])
        arr[left] += 1
        if right < N-1:
            arr[right+1] -= 1

    # print(arr)
    for j in range(1, N):
        arr[j] += arr[j-1]

    # print(arr)
    prev_arr = arr
    count += 1

# print(count)
print(*prev_arr)


Fixed code:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

N, k = map(int, input().split())
prev_arr = list(map(int, input().split()))

count = 0
for i in range(min(k, 3*int(math.log(N))+10)):
    arr = [0]*N
    for j in range(N):
        left = max(0, j-prev_arr[j])
        right = min(N-1, j+prev_arr[j])
        arr[left] += 1
        if right < N-1:
            arr[right+1] -= 1

    # print(arr)
    for j in range(1, N):
        arr[j] += arr[j-1]

    # print(arr)
    prev_arr = arr
    count += 1

# print(count)
print(*prev_arr)