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 math
N,K=map(int,input().split())
A=[0]*N
A=list(map(int,input().split()))

da=[0 for i in range(N)]
for k 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]=B[l]+1
        if(r+1<N):
            B[r+1]=B[r+1]-1
    for i in range(1,N):
        B[i]=min(N,B[i]+B[i-1])
    if(A==B):
        break
    A=B
b=[str(i) for i in B]
b=" ".join(b)
print(b)

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

if K >= N - 1:
    ans = [N] * N
    print(*ans)

else:
    for i in range(K):
        tmp = [0] * (N + 1)
        
        for j in range(N):
            end_l = max(j - A[j], 0)
            end_r = min(j + A[j] + 1, N)
            
            tmp[end_l] += 1
            tmp[end_r] -= 1
        
        flg = tmp[0]
        
        for j in range(1, N):
            tmp[j] += tmp[j - 1]
            flg += tmp[0]
            A[j] = tmp[j]
        
        A[0] = tmp[0]
        
        if flg == N**2:
            break
            
    print(*A[:N])

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

Solution (Python):



'''
5 100
1 0 0 1 0
'''

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline




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

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

for b in B:
    print(b, end=' ')
print()

Solution (Python):
n,k=map(int,input().split())
dp2=list(map(int,input().split()))
    
k=min(k,41)
for ki in range(1,k+1):
    ims=[0]*(n+1)
    for ni in range(n):
        if 0>ni-dp2[ni]:
            ims[0]+=1
        else:
            ims[ni-dp2[ni]]+=1
        if n<ni+dp2[ni]+1:
            ims[n]-=1
        else:
            ims[ni+dp2[ni]+1]-=1

    dp2[0]=ims[0]
    for ni in range(1,n):
        dp2[ni]=dp2[ni-1]+ims[ni]
    
for i in range(n):
    print(dp2[i],end=" ")
print()

Solution (Python):
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
 
K = min(K, 41)
 

for _ in range(K):
    B = [0 for _ 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(*A)

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

for _ in range(k):
    r = [0]*(n+1)
    for i in range(n):
        r[max(i-a[i],0)] += 1
        r[min(i+a[i]+1,n)] -= 1
    for i in range(n-1):
        r[i+1] += r[i]
    a = r
    if a.count(n)==n:
        break
print(*a[:-1])

Solution (Python):
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

K = min(K, 41)


for _ in range(K):
    B = [0 for _ 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

for i in range(N):
    A[i] = str(A[i])
print(' '.join(A))

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

Solution (Python):
import math
from collections import deque
from collections import defaultdict
import itertools as it


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	
	ans = data[:]
	return ans

def solve(n,k,a):
	for j 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 a==b:
			break
		a = b[:]

	for i in range(len(b)):
		print(b[i],end=" ")

def main():
	n,k = readInts()
	a = readInts()
	solve(n,k,a)

if __name__=='__main__':
	main()

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for _ in range(n)]

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

Solution (Python):


import sys
stdin = sys.stdin
from itertools import accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    a = na()
    def step():
        b = [0] * n
        for i, ai in enumerate(a):
            start, stop = i - ai, i + ai + 1
            if start > 0:
                b[start] += 1
            else:
                b[0] += 1
            if stop < n:
                b[stop] -= 1
        return list(accumulate(b))

    for i in range(k):
        anext = step()
        if sum(a) == sum(anext):
            print(*a)
            quit()
        a = anext
    print(*a)


if __name__ == "__main__":
    main()

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

@njit(i8[:](i8[:]),cache = True)
def calc(A):
    B = np.zeros_like(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
    B = np.cumsum(B)
    return B

@njit(i8[:](i8,i8,i8[:]),cache = True)
def solve(N,K,A):
  for i in range(K):
    A = calc(A)
    if len(set(A)) == 1 and A[0] == N:
      break
  return A
  
import sys
readline=sys.stdin.readline
  
N,K = map(int,readline().split())
A = np.array(list(map(int,readline().split())))

ans = solve(N,K,A)
print(*ans)

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

@njit(i8[:](i8[:]),cache = True)
def calc(A):
    B = np.zeros_like(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
    B = np.cumsum(B)
    return B
  
import sys
readline=sys.stdin.readline
  
N,K = map(int,readline().split())
A = np.array(list(map(int,readline().split())))

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

Solution (Python):
N,K = map(int,input().split())
A = [int(i) for i in input().split()]
loop = min(41,K)
for _ in range(loop):
    B = [0]*N
    for n in range(N):
        l = max(0,n-A[n])
        r = min(N-1,n+A[n])
        
        B[l]+=1
        if r+1<N:
            B[r+1] -= 1
    
    for n in range(1,N):
        B[n] += B[n-1]
    A = B
print(*A)

Solution (Python):
import math
from collections import deque
from collections import defaultdict
import itertools as it


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	
	ans = data[:]
	return ans

def solve(n,k,a):
	for j in range(int(min(42,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]
		a = b[:]

	for i in range(len(b)):
		print(b[i],end=" ")

def main():
	n,k = readInts()
	a = readInts()
	solve(n,k,a)

if __name__=='__main__':
	main()

Solution (Python):
N,K = map(int,input().rstrip().split(" "))
A = [list(map(int,input().rstrip().split(" ")))]
imos = [0 for i in range(N + 1)]
P = 0
flag = True
counter = 0
while flag:
    A.append([0 for i in range(N)])
    P = 0
    for i in range(N+1):
        imos[i] = 0
    for i in range(N):
        imos[max(0,i - A[counter][i])] += 1
        imos[min(N,i + A[counter][i] + 1)] -= 1
    if imos[0] == N and imos[N] == -1 * N:
        flag = False
    for i in range(N):
        P += imos[i]
        A[counter + 1][i] = P
    counter += 1
    if counter == K:
        break
print(" ".join(map(str,A[-1])))

Solution (Python):
from numba import njit

@njit(cache=True)
def aaa(n,k,a):
    for f in range(k):
        a1=[0]*(n+1)
        for x in range(n):
            y=max(0,x-a[x])
            a1[y]=a1[y]+1    
            z=min(n-1,x+a[x])
            a1[z+1]=a1[z+1]-1
        a[0]=a1[0]
        for x in range(1,n):    
            a[x]=a[x-1]+a1[x]
        if a==[n]*n:
            break
    return a

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
a0=input()
a0=a0.split()
a=[int(s) for s in a0]

b=aaa(n,k,a)
for i in range(n):
    print(b[i])

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

    for i in range(min(k, 50)):
        b = [0] * (n + 1)
        for j in range(n):
            l = max(0, j - a[j])
            r = min(n - 1, j + a[j])
            b[l] += 1
            b[r + 1] -= 1
        for m in range(n):
            b[m + 1] += b[m]
        a = b[:-1]
    print(*a)
if __name__ == '__main__':
    main()

Solution (Python):
N,K = map(int,input().split())
A = [int(i) for i in input().split()]
loop = min(41,K)
for _ in range(loop):
    B = [0]*N
    for n in range(N):
        l = max(0,n-A[n])
        r = min(N-1,n+A[n])
        B[l]+=1
        if r+1<N:
            B[r+1] -= 1
    for n in range(1,N):
        B[n] += B[n-1]
    A = [b for b in B]
print(*A)

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

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

Solution (Python):
from numba import jit
import sys
input = sys.stdin.readline


@jit
def solve(n, k, A):
    for _ in range(k):
        B = [0]*(n+1)
        for i, a in enumerate(A):
            B[max(0, i-a)] += 1
            B[min(n, i+a+1)] -= 1
        for j in range(1, n):
            B[j] += B[j-1]
        if A == B[:-1]:
            break
        A = B[:-1]
    return A


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    ans = solve(n, k, A)
    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):
from numba import jit
import sys
input = sys.stdin.readline


@jit
def solve(n, k, X):
    for _ in range(k):
        Y = [0]*(n+1)
        for i, x in enumerate(X):
            Y[max(0, i-x)] += 1
            Y[min(n, i+x+1)] -= 1
        for j in range(1, n):
            Y[j] += Y[j-1]
        if X == Y[:-1]:
            break
        X = Y[:-1]
    return X


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


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,int(n**0.5)+10)):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))

Solution (Python):
from numba import njit

@njit
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

@njit
def solve(N,K,A):
  
  for i in range(K):
    A = calc(A)
    if len(set(A)) == 1 and A[0] == N:
      break
  return A
  
import sys
readline=sys.stdin.readline
  
N,K = map(int,readline().split())
A = list(map(int,readline().split()))

ans = solve(N,K,A)
print(*ans)

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

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

def solve():
    imos=[0]*(n+1)
    for i in range(n):
        mnind=max(0,i - a[i])
        mxind=min(n,i+ a[i]+1)
        imos[mnind]+=1
        imos[mxind]-=1
    for i in range(len(imos)-1):
        imos[i+1]+=imos[i]
    return imos[:n]

if k>50:
    k=50
for i in range(k):
    a = solve()
print(*a,sep=" ")

Solution (Python):
from numba import jit
import sys
input = sys.stdin.readline


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

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

    ans = ' '.join(list(map(str, A)))
    print(ans)


if __name__ == '__main__':
    main()

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

for i in range(min(k, 45)):
    b = [0] * n
    for j in range(n):
        mi = max(0, j-a[j])
        ma = min(n-1, j+a[j])
        b[mi] += 1
        if ma + 1 <= n -1:
            b[ma+1] -= 1
    c = [0] * n
    s = 0
    for k in range(n):
        s += b[k]
        c[k] = s
    a = c

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

Solution (Python):
import sys
import numpy as np
from numba import jit
 
readline = sys.stdin.readline
 
@jit
def loop(n,k,a):
    for j in range(k):
        b = np.zeros(n+1, dtype=np.int64)
        for i in range(n):
            b[max(i-a[i], 0)] += 1
            b[min(i+a[i]+1, n)] -= 1
        a = np.cumsum(b)[:-1]
        if np.all(a==n):
            return(a)
            break
    else:
        return(a)
 
 
n, k = map(int, readline().split())
a = np.array(readline().split(), dtype=np.int64)
 
ans = loop(n,k,a)
print(*ans)

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

for i in range(1, 100):
  imos = [0] * (n + 1)
  for j in range(n):
    imos[max(0, j - A[j])] += 1
    imos[min(n, j + A[j] + 1)] -= 1
  
  nA = [0] * n
  nA[0] = imos[0]
  for j in range(1, n):
    nA[j] = nA[j - 1] + imos[j]

  A = nA[:]
  if i >= k:
    break

print(*A)

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

for _ in range(K):
    B = [0] * (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[:N]

    if min(A) >= N:
        break

print(*A)

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

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

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

@njit(cache=True)
def light(n,a_list):
    outcome= np.zeros(n+1, dtype=np.int64)
    for i in range(n):
        outcome[max(0,i-a_list[i])] += 1
        outcome[min(n,i+a_list[i]+1)] -= 1
    outcome = np.cumsum(outcome)[:-1]
    return outcome

for _ in range(k):
    if min(a) == n:
        break
    a = light(n,a)

[print(aa,end=' ') for aa in a]

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


def main(N, K, A):
    @njit(cache = True) 
    def rep(N, A):
        B = np.zeros(N + 1, dtype=np.int64) 
        for x in range(N):
            minimum = max(0, x - A[x])
            maximum = min(N, x + A[x] + 1)
            
            B[minimum] += 1
            B[maximum] -= 1
        
        return np.cumsum(B)[:-1]

    A = np.array(A, dtype=np.int64)
    for k in range(K):
        B = rep(N, A)
        if np.array_equal(A, B):
            break
        else:
            A = B
    return A



if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    print(' '.join([str(i) for i in main(N, K, A)]))

Solution (Python):
import sys
from itertools import accumulate


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for _ in range(K):
        B = [0 for _ in range(N)]
        count = 0
        for i in range(N):
            if A[i] == N:
                count += 1
            l = max(0, i - A[i])
            r = min(N - 1, i + A[i])
            B[l] += 1
            if r + 1 < N:
                B[r + 1] -= 1
        B = list(accumulate(B))
        if count == N:
            break
        else:
            A = B
    print(*B, sep=" ")


if __name__ == "__main__":
    main()

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 sys
import numpy as np
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, *A = map(int, read().split())
 
@jit
def imos(A):
  B = np.zeros_like(A)
  for i,x in enumerate(A):
    a = max(0,i-x)
    b = min(N-1,i+x)
    B[a] += 1
    if b+1 <= N-1:
      B[b+1] -= 1
  B = np.cumsum(B)
  return B
 
for i in range(K):
  if i >= 50:
    break
  A = imos(A)
print(*A)

Solution (Python):
import sys
import numpy as np
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, *A = map(int, read().split())
K = min(50,K)

@jit
def imos(A):
  B = np.zeros_like(A)
  for i,x in enumerate(A):
    a = max(0,i-x)
    b = min(N-1,i+x)
    B[a] += 1
    if b+1 <= N-1:
      B[b+1] -= 1
  B = np.cumsum(B)
  return B

for i in range(K):
  if i >= 50:
    break
  A = imos(A)
print(*A)

Solution (Python):

def main():
    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):
            l = max(0,i-A[i])
            r = min(N,i+A[i]+1)
            B[l] += 1
            B[r] -= 1
        for i in range(N):
            B[i+1] += B[i]
        B.pop(-1)
        if A == B:
            break
        A = B

    print(*A)
    

if __name__ == "__main__":
    main()

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

Solution (Python):
from sys import stdin
import numpy as np
from numba import njit
def main():
    
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=np.array(list(map(int,readline().split())),dtype=np.int64)

    cnt=0
    while cnt<k:
        s=f(n,a)
        a=np.cumsum(s)
        cnt+=1
        if a[a==n].size==n:
            break

    print(*a)

@njit("i8[:](i8,i8[:])",cache=True)
def f(n,a):
    s=np.zeros(n,dtype=np.int64)
    for i in range(n):
        x_min=i-a[i]
        x_max=i+a[i]+1
        s[max(0,x_min)]+=1
        if n-1<x_max:
            pass
        else:
            s[x_max]-=1
    return s

if __name__=="__main__":
    main()

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k):
  l=[0]*(n+1)
  for j in range(n):
    l[max(0,j-a[j])]+=1
    l[min(n-1,j+a[j])+1]-=1
  b=0
  for j in range(n):
    b+=l[j]
    a[j]=b
  if l[0]==n:
    break
print(*a,sep=' ')

Solution (Python):
from sys import stdin
import numpy as np
from numba import njit
def main():
    
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=np.array(list(map(int,readline().split())),dtype=np.int64)

    cnt=0
    while cnt<k:
        s=f(n,a)
        a=np.cumsum(s)
        cnt+=1
        if a[a==n].size==n:
            break

    print(*a)

@njit(cache=True)
def f(n,a):
    s=np.zeros(n,dtype=np.int64)
    for i in range(n):
        x_min=i-a[i]
        x_max=i+a[i]+1
        s[max(0,x_min)]+=1
        if n-1<x_max:
            pass
        else:
            s[x_max]-=1
    return s

if __name__=="__main__":
    main()

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

Solution (Python):

import numpy as np
from numba import njit

@njit(cache=True)
def loop(n, k, A):
    for _ in [0] * k:
        B = np.zeros(n + 1, dtype=np.int64)
        for i in range(n):
            left = max(0, i - A[i])
            right = min(n, i + A[i] + 1)
            B[left] += 1
            B[right] -= 1
        A = np.cumsum(B)[:-1]
        
        if np.all(A == n):
            return A
            break

    return A


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    A = np.array(a, dtype=np.int64)
    A = loop(n, k, A)
    print(*A)


if __name__ == "__main__":
    main()

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 range(min(k,41)):
        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)]
    print(' '.join(map(str,a)))
main()

Solution (Python):
n,k,*a=map(int,open(0).read().split())
r=range(n)
for _ in a[:k][:41]:
 b=[0]*n*3
 for i in r:b[max(0,i-a[i])]+=1;b[i-~a[i]]-=1
 for i in r:b[i+1]+=b[i]
 a=b
print(*a[:n])

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = [0]*N

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

print(" ".join(str(a) for a in A))

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


    for _ in range(K):
        counter=[0 for _ in range(N)]

        for i in range(len(A)):
            left=max(0,i-A[i])
            right=min(N-1,i+A[i])
            counter[left]+=1
            if right+1<N:
                counter[right+1]-=1
        for i in range(len(counter)-1):
            counter[i+1]+=counter[i]

        if counter==A:
            break
        else:
            A=counter

    for i in range(N):
        if i!=N-1:
            print(str(A[i])+" ",end="")
        else:
            print(A[i])

if __name__ == "__main__":
    main()

Solution (Python):
from numba import njit
@njit(cache=True)
def func(n, k, a):
    for i in range(k):
        b = []
        for i in range(n+1):
            b.append(0)
        for i in range(n):
            l = max(0, i - a[i])
            r = min(n, i + a[i] + 1)
            b[l] += 1
            b[r] -= 1
        for i in range(len(b)-1):
            b[i+1] += b[i]
        b = b[:n]
        if a == b:
            break
        else:
            a = b
    return b
if __name__ == '__main__':
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = func(n, k, a)
    for i in range(n):
        print(b[i])

Solution (Python):
from itertools import accumulate

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

for j in range(k):
    a01 = [0] * (n + 1)
    for i, ai in enumerate(a):
        l, r = max(0, i - ai), min(i + ai + 1, n)
        a01[l] += 1
        a01[r] -= 1
    a = list(accumulate(a01))[:-1]
    if all(ai == n for ai in a):
        break
print(*a)

Solution (Python):
N, K= map(int,input().split())
a = list(map(int,input().split()))
p=0
while p<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
  p+=1
print(*a)