Problem:
 Score : 500 points    Problem Statement We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i .  Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x , the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5 .
Initially, the intensity of Bulb i is A_i . We will now do the following operation K times in a row:   For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i . Then, change the intensity of each bulb i to B_i .   Find the intensity of each bulb after the K operations.      Constraints  1 \leq N \leq 2 \times 10^5  1 \leq K \leq 2 \times 10^5  0 \leq A_i \leq N         Input Input is given from Standard Input in the following format:  N  K  A_1  A_2  \ldots  A_N       Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:  A{'}_1  A{'}_2  \ldots  A{'}_N         Sample Input 1 5 1
1 0 0 1 0      Sample Output 1 1 2 2 1 2  Initially, only Bulb 1 illuminates coordinate 1 , so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2 , so the intensity of Bulb 2 becomes 2 .       Sample Input 2 5 2
1 0 0 1 0      Sample Output 2 3 3 4 4 3

Solution (Python):
import copy
from functools import lru_cache
import numpy as np
from numba import njit
















def resolve():
    N, K = map(int, input().split())
    A = np.array(list(map(int, input().split())))

    
    
    

    @njit
    def func(A):
        
        B = np.zeros_like(A)
        for i in range(N):
            l = max(0, i - A[i])
            r = min(i + A[i], N-1)
            B[l] += 1
            if r+1 < N:
                B[r+1] -= 1

        B = np.cumsum(B)
        return B

    for k in range(K):
        
        A = func(A)
        if k >= 50:
            break

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

if __name__ == "__main__":
    resolve()

Solution (Python):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(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]
    a=b
print(" ".join(map(str,a)))

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=A[:]
for _ in range(K):
    t=[0]*(N+1)
    for i in range(N):
        ti=a[i]
        t[max(0,i-ti)]+=1
        t[min(N,i+ti+1)]-=1
    a=[]
    for i in range(N):
        a.append(t[i])
        if i>0:
            a[i]+=a[i-1]
    if min(a)==N:
        break
print(*a)

Solution (Python):
import numpy as np



import sys
input = sys.stdin.readline

from numba import njit,i8


@njit(i8[:](i8,i8,i8[:],i8,i8))
def loop(N,K,A,l,r):
    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            l = max(i - A[i],0)
            r = min(i + A[i],N-1)
            B[l] += 1
            if r + 1 < N:
                B[r+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        A = B
    return A


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

    if K >= 43:
        M = 43
    else:
        M = K

    res = loop(N,M,A,0,0)

    print(*res)



main()

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

def simulate():
    global 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+1 < N:
            B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    
    
    
    
    A = B

for k in range(min(K,43)):
    simulate()
print(*A)

Solution (Python):
from itertools import accumulate
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))

c_sum = [0] * (n+1)
now = [0] * n

if k > 50:
    ans = [n] * n
    print(*ans)
    exit()

for i in range(k):
    c_sum = [0] * (n+1)
    for x, d in enumerate(a):
        s = max(0, x - d)
        c_sum[s] += 1
        e = min(n-1, x + d)
        c_sum[e+1] -= 1
    a = list(accumulate(c_sum))

print(*list(accumulate(c_sum))[:-1])

Solution (Python):

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)

Solution (Python):
import numpy as np
from numba import njit
 
@njit('i8,i8,i8[::1]', cache=True)
def fn(N, K, A):
    for _ in range(K):
        B = np.zeros(N, dtype=np.int64)
        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 = np.cumsum(B)
        if (np.all(A == N)):
            return A
    return A

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A, dtype=np.int64)

B = fn(N, K, A)
print(" ".join(B.astype(str)))

Solution (Python):
from itertools import accumulate

N, K, *A = map(int, open(0).read().split())

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = accumulate(B)

print(*list(A)[:-1])

Solution (Python):
import sys
import numpy as np
from numba import njit


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

@njit('(i8[::1],)', cache=True)
def c(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    B = np.cumsum(B)
    return B


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)


    K = min(K, 50)
    for _ in range(K):
        A = c(A)

    print(' '.join(A.astype(str)))


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int, input().split())
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(min(50,k)):
    new=[0]*n
    for i in range(n):
        j=a[i]
        l=max(0,i-j)
        r=min(n-1,i+j)
        new[l]+=1
        if r+1<n:
            new[r+1]-=1
    new=list(accumulate(new))
    a=new
print(*a)

Solution (Python):
from math import log
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = [0] + list(map(int, input().split()))
    from math import log
    mx = min(int(log(K)) + 100, K)
    for _ in range(mx):
        left_right = [0] + [(i-A[i], i+A[i]) for i in range(1, N+1)]
        ini = [0]*(N+1)
        for i in range(1, 1+N):
            l, r = left_right[i]
            l = max(1, l)
            ini[l] += 1
            if r+1 <= N:
                ini[r+1] -= 1
        is_all_n = True
        A[1] = ini[1]
        if A[1] != N:
            is_all_n = False
        for i in range(2, N+1):
            A[i] = A[i-1] + ini[i]
            if A[i] != N:
                is_all_n = False
        if is_all_n:
            break
    print(*A[1:])
main()

Solution (Python):
N, K=map(int, input().split())
A=list(map(int, input().split()))
for i in range(K):
  p=[0]*N
  n=[0]*N
  for i in range(N):
    if i-A[i]>0:
      p[i-A[i]]+=1
    else:
      p[0]+=1
    if i+A[i]<N-1:
      n[i+A[i]+1]+=1
  light=0
  Ncount=0
  for i in range(N):
    light=light+p[i]-n[i]
    A[i]=light
    if light==N:
      Ncount+=1
  if Ncount==N:
    out=[N]*N
    print(*out, sep=' ')
    exit()
print(*A, sep=' ')

Solution (Python):
n,k,*a=map(int,open(0).read().split())
for _ in range(k):
  b=[0]*(n+1)
  for i,c in enumerate(a):
    b[max(0,i-c)]+=1
    b[min(n,c+i+1)]-=1
  for i in range(n):
    b[i+1]+=b[i]
  a=b[:-1]
  if a==[n]*n:
    print(*a)
    exit()
print(*a)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(min(42, k)):
    nex = [0]*n
    for i, v in enumerate(current):
        l = max(0, i-v)
        r = min(n-1, i+v)
        nex[l] += 1
        if r+1 < n:
            nex[r+1] -= 1
    for i in range(1, n):
        nex[i] += nex[i-1]
    current = nex

print(*current)

Solution (Python):

import sys



def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


n, k = xnxn()
a = xnxn(flag="l")
for _ in range(k):
    tmp = [0]*(n+1)
    for i in range(0, n):
        l = max(0, i - a[i])
        r = min(n, i + a[i]+1)
        tmp[l] += 1
        tmp[r] -= 1
    for i in range(1, n):
        tmp[i] += tmp[i - 1]
    if a == tmp:
        break
    a = tmp

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline    
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')


from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations




def solve():
    N, K = MI()
    A = LI()
    for i in range(K):
        B = [0] * N
        for idx, a in enumerate(A):
            l = max(0, idx - a)
            r = idx + a + 1
            
            B[l] += 1
            if N > r:
                B[r] -= 1
        
        B = list(accumulate(B))
        
        if all([j == N for j in B]):
            printlist(B)
            return
        A = B
    printlist(A)

if __name__ == '__main__':
    solve()

Solution (Python):



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

for _ in range(K):
    B = [0] * (N+1)
    for i, a in enumerate(A):
        left = max(0, i-a)
        right = min(i+a+1, N)
        B[left] += 1
        B[right] -= 1
    for i in range(N):
        B[i+1] += B[i]
    B.pop()
    if A == B:
        break
    else:
        A = B

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

Solution (Python):
from numba import jit
import numpy as np

@jit
def resolve():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    for m in range(k):
        B = np.zeros(n + 1, dtype=np.int64)
        for i in range(n):
            l = max(0, i - A[i])
            r = min(n, i + A[i] + 1)
            B[l] += 1
            if r < n:
                B[r] -= 1
        A = np.cumsum(B)[:-1]
        if np.all(A == n):
            break

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

resolve()

Solution (Python):
[n,k]=list(map(int,input().split()))
akarusa=list(map(int,input().split()))


for i in range(k):
    imos=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        imos[kagen]+=1
        if jogen+1<n:
            imos[jogen+1]-=1
    akarusanext=imos
    for j in range(1,n):
        akarusanext[j]+=akarusanext[j-1]
    
    if akarusa==akarusanext:
        break
    else:
        akarusa=akarusanext

for i in range(n):
    print(akarusa[i], end=" ")

Solution (Python):
from itertools import accumulate
n, K = map(int,input().split())
A = list(map(int,input().split()))
b = [0 for _ in range(n+1)]

for _ in range(K):
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    ac = list(accumulate(b))
    A = ac[:-1]
    b = [0 for _ in range(n+1)]
    if sum(A) == n*n:
        break
    
print(*A)

Solution (Python):
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(k):
        imos = [0] * (n + 1)
        for i in range(n):
            imos[max(0, i - a[i])] += 1
            imos[min(n, i + a[i] + 1)] -= 1
        for i in range(1, n):
            imos[i] += imos[i-1]
        imos.pop()
        a = imos
        if min(a) == n:
            break 
    print(*a)
main()

Solution (Python):
import numpy as np
from numba import jit 
N , K = map(int,input().split())
Lum = np.array(list(map(int,input().split())))

@jit("i8,i8,i8[:]")
def fn(N,K,A):
    K1 = min(K,41)
    for i1 in range(K1):
        B = np.zeros(N,dtype=np.int64)
        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]
        A = B
    return A

Lum = list(fn(N,K,Lum))
Lum = [str(l) for l in Lum]
Lum=" ".join(Lum)
print(Lum)

Solution (Python):
n, K = map(int,input().split())
A = list(map(int,input().split()))
b = [0 for _ in range(n+1)]

for _ in range(K):
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    for i in range(n):
        b[i+1] += b[i]
    A = b[:-1]
    b = [0 for _ in range(n+1)]
    if sum(A) == n*n:
        break
    
print(*A)

Solution (Python):



def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = list(map(int, args[1].split()))

    cur = A
    for _ in range(k):
        prev = cur.copy()
        cur = [0]*n
        for x, p in enumerate(prev):
            cur[max(0, x-p)] += 1
            if x+p+1 < n:
                cur[x+p+1] -= 1

        satulated = True
        for i in range(1, n):
            cur[i] += cur[i-1]
            satulated &= cur[i] == n
        if satulated:
            break

    return ' '.join(map(str, cur))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
n,k,*a=map(int,open(0).read().split())
for _ in range(k):
 b=[0]*n
 for i,q in enumerate(a):
  b[max(0,i-q)]+=1
  if i+q+1<n:b[i+q+1]-=1
 for i in range(1,n):b[i]+=b[i-1]
 if b==a:break
 a=b[:]
print(*a)

Solution (Python):
n, K = map(int,input().split())
A = list(map(int,input().split()))

for _ in range(K):
    b = [0 for _ in range(n+1)]
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    for i in range(n):
        b[i+1] += b[i]

    A = b[:-1]
    if all(a == n for a in A):
        break
print(*A)

Solution (Python):
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()

Solution (Python):
import sys
sys.setrecursionlimit(300000)
n,k=map(int,input().split())
a=list(map(int,input().split()))

def dfs(index, lx):
  if index < 1:
    return lx
  b=[0]*n
  for i in range(n):
    l=max(0,i-lx[i])
    g=min(n-1,i+lx[i])
    b[l]+=1
    if g+1<n:
      b[g+1]-=1
  for i in range(1,n):
    b[i]+=b[i-1]
  return dfs(index-1,b)
  
    
print(*dfs(min(k,44),a))

Solution (Python):
from itertools import accumulate

def calc(n,A):
    Imos=[0]*(n+1)
    for i,a in enumerate(A):
        Imos[max(0,i-a)]+=1
        Imos[min(n,i+a+1)]-=1
    Ret=list(accumulate(Imos))
    return Ret[:n]

def main():
    n,k=map(int,input().split())
    A=tuple(map(int,input().split()))
    if k>=42:
        A=[n]*n
    else:
        for _ in range(k):
            A=calc(n,A)
    print(*A)
    
if __name__=='__main__':
    main()

Solution (Python):
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=" ")

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')


from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations




def solve():
    N, K = MI()
    A = LI()
    for i in range(K):
        B = [0] * N
        for idx, a in enumerate(A):
            l = max(0, idx - a)
            r = idx + a + 1
            
            B[l] += 1
            if N > r:
                B[r] -= 1
        
        B = list(accumulate(B))
        
        if all([j == N for j in B]):
            printlist(B)
            return
        A = B
    printlist(A)



if __name__ == '__main__':
    solve()

Solution (Python):
def solve():
    ans = 0
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for j in range(K):
        check = [0]*(N+1)
        for i in range(N):
            check[max(0,i-A[i])] += 1
            check[min(N,i+A[i]+1)] -= 1
        A = [check[0]]*N
        for i in range(1,N):
            A[i] = A[i-1]+check[i]
        if A==[N]*N:
            break
    return A
print(*solve())

Solution (Python):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=[0]*n
num=[]
if k>41:
    ans=[n]*n
    print(*ans)
else:
    def c(num1,num2,num3):
        num[max(0,num1-num2)]+=1
        num[min(num3,num1+num2+1)]-=1
    for i in range(k):
        num=[0]*(n+1)
        for j in range(n):
            c(j,a[j],n)
        num5=0
        for j in range(n):
            num5+=num[j]
            a[j]=num5
        if sum(a)==n*n:
            break
    print(*a)

Solution (Python):
n,k=map(int, input().split())
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(k):
    new=[0]*n
    for i in range(n):
        j=a[i]
        l=max(0,i-j)
        r=min(n-1,i+j)
        new[l]+=1
        if r+1<n:
            new[r+1]-=1
    new=list(accumulate(new))
    a=new
    if all([i==n for i in a]):
        break
print(*a)

Solution (Python):
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline
def main():
    n,k=map(int,input().split())
    a=[*map(int,input().split())]
    for _ in'_'*k:
        b=[0]*n
        for i,t in enumerate(a):
            if i>t:b[i-t]+=1
            else:b[0]+=1
            j=i-~t
            if j<n:b[j]-=1
        a=[*accumulate(b)]
        if min(a)==n:break
    print(' '.join(map(str,a)))
main()

Solution (Python):

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

if K > 4 * math.log2(N):
    for _ in range(N):
        print(N," ", end = "")
    print()
else:
    for i in range(K):
        cum_sum = [0]*N
        for j in range(N):
            left = max(0, j - A[j])
            right = min(N-1, j+A[j])
            cum_sum[left] += 1
            if right + 1 < N:
                cum_sum[right+1] -= 1
        A[0] = cum_sum[0]
        for j in range(N-1):
            cum_sum[j+1] += cum_sum[j]
            A[j+1] = cum_sum[j+1]

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

Solution (Python):
import copy

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




for i in range(K):
    B = [0] * (N+1)
    for j in range(N):
        l = max(0, j-A[j])
        r = min(j+A[j]+1, N)
        B[l] += 1
        B[r] -= 1
    
    for j in range(N):
        B[j+1] += B[j]
    del B[N]
    
    if A == B:
        break
    A = copy.deepcopy(B)

print(*A)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
K = min(50, K)

for k in range(K):
    for i in range(N):
        if A[i] != N:
            break
    else:
        break

    B = [0] * N
    for i in range(N):
        d = A[i]
        left = max(0, i - d)
        right = min(N-1, i + d)
        B[left] += 1
        if right + 1 < N:
            B[right+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = B
print(" ".join(map(str, A)))

Solution (Python):
import numpy as np
from numba import njit

@njit('i8,i8,i8[::1]', cache=True)
def fn(n, k, a):
    for _ in range(k):
        b = np.zeros(n, dtype=np.int64)
        for i in range(n):
            lb = max(i - a[i], 0)
            ub = min(i + a[i], n - 1)

            b[lb] += 1
            if ub + 1 < n:
                b[ub + 1] -= 1

        a = b.cumsum()
        if np.all(a == n):
            return a
    return a

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = np.array(a, dtype=np.int64)

b = fn(n, k, a)
print(' '.join(b.astype(str)))

Solution (Python):
import sys
from pprint import pprint

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

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

    for i in range(N):
        B[i+1] += B[i]

    if A == B:
        break

    A = B[:]

print(*B[:N])

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

for _ in range(k):
    imos=[0]*(n+1)
    for i in range(n):
        imos[max(0,i-a[i])]+=1
        imos[min(n,1+i+a[i])]-=1
    
    a[0]=imos[0]
    if a[0]==n:
        flag=0
    else:
        flag=1

    for i in range(1,n):
        a[i]=a[i-1]+imos[i]
        if a[i]!=n:
            flag=1
    
    if flag==0:
        break

print(" ".join(list(map(str,a))))

Solution (Python):


import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import bisect
from queue import PriorityQueue
import itertools
from itertools import accumulate
from copy import deepcopy
import random
import time
import os
import sys
import datetime
from functools import lru_cache
from functools import reduce
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):
    if b:print("yes")
    else:print("no")
def Yn(b):
    if b:print("Yes")
    else:print("No")
def YN(b):
    if b:print("YES")
    else:print("NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(bbool,ret1,ret2):
    if bbool:return ret1
    else:return  ret2
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    return c.join(A)
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def pm(x):
    return x//abs(x)
def inputintlist(): 
    return list(map(int,input().split()))
def inputfloatlist(): 
    return list(map(float,input().split()))
def tozero(A):
    ret=[None]*len(A)
    for a in range(len(A)):
        ret[a]=A[a]-1
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def heron(a,b,c):
    s=(a+b+c)/2
    S=s(s-a)(s-b)(a-c)
    S=math.sqrt(S)
    return S
def getAreaOfTriangle(x1,y1,x2,y2,x3,y3):
    a=geted(x1,y1,x2,y2)
    b=geted(x2,y2,x3,y3)
    c=geted(x3,y3,x1,y1)
    return heron(a,b,c)










N,K=inputintlist()
A=inputintlist()
K=min(K,43)
for k in range(K):
    imos=[0]*(N)
    for a in range(len(A)):
        mmin=max(a-A[a],0)
        mmax=min(a+A[a],N-1)
        imos[mmin]+=1
        if mmax!=N-1:imos[mmax+1]-=1
    A=list(accumulate(imos))
print(join(A))

Solution (Python):
from numba import njit
import numpy as np


@njit
def main(N, K, A):
    for _ in range(min(K, 41)):
        ne = np.zeros_like(A)
        for i in range(N):
            ne[max(0, i-A[i])] += 1
            if i+A[i]+1 < N:
                ne[i+A[i]+1] -= 1
        A = ne.cumsum()
    return A


N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
ans = main(N, K, A)
print(*ans)

Solution (Python):
n,k=map(int, input().split())
*a,=map(int, input().split())

if k>100:
    ans=[n]*n
    print(*ans)
    exit()

for _ in range(k):
    pre_cum = [0]*(n+1)
    for i,ai in enumerate(a):
        if i-ai>=0:
            pre_cum[i-ai]+=1
        else:
            pre_cum[0]+=1
        if i+ai<n-1:
            pre_cum[i+ai+1]-=1
        else:
            pre_cum[n]-=1
    a=[]
    tmp=0
    for i in range(n):
        tmp+=pre_cum[i]
        a.append(tmp)

print(*a)