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
import random
import bisect 
import fractions 
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()

if K > 50:
    print(" ".join([str(N) for i in range(N)]))
    sys.exit()

for i in range(K):
    A_new = [0 for i in range(N)]
    imos_table = [0 for i in range(N)]

    for j in range(N):
        left = max(0, j - A[j])
        right = j + A[j] + 1
        imos_table[left] += 1
        if right >= N:
            pass
        else:
            imos_table[right] -= 1
    
    tmp = 0
    for j in range(N):
        tmp += imos_table[j]
        A_new[j] += tmp

    A = copy.deepcopy(A_new)

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

Solution (Python):
from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for _ in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = list(accumulate(temp))
        if templi == dists:
            break
        else:
            dists = templi
    dists.pop()
    print(*dists)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for ope_count in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = list(accumulate(temp))
        if templi == dists:
            break
        else:
            dists = templi

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue


sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n, k = ns()
    a = na()

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

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

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        if min(a) == n:
            break

    print(*a, sep=" ")


if __name__ == '__main__':
    main()

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue


sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n, k = ns()
    a = na()

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

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

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        if min(a) == n:
            break

    print(*a, sep=" ")


if __name__ == '__main__':
    main()

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue


sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n, k = ns()
    a = na()

    for _ in range(min(k,42)):
        imos = [0 for _ in range(n)]

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

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        
        

    print(*a, sep=" ")


if __name__ == '__main__':
    main()

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

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

    a=[0]*n
    a[0]=imos[0]
    for i in range(1,n):
        a[i] = a[i-1]+imos[i]

print(*a)

Solution (Python):
from itertools import accumulate
from operator import add

N,K = map(int,input().split())
A = map(int,input().split()) 
for k in range(K):
    B = [0] * N
    for i,x in enumerate(A):
        L = max(0, i-x)
        R = min(N-1, i+x)
        B[L] += 1
        if R+1 != N:
            B[R+1] -= 1
    L = list(accumulate(B,add)) 
    
    if L == A:
        break
    A = L
print(*A)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline

from itertools import accumulate
def resolve():
 
    N, K = map(int, inp().split())
    A = list(map(int, inp().split()))
 
    for _ in range(K):
        imos_table = [0]*(N+1)
        for i, a in enumerate(A):
            
            imos_table[max(i - a, 0)] += 1
            imos_table[min(i + a + 1, N)] -= 1
        A = list(accumulate(imos_table))[:-1]
        if all([True if a == N else False for a in A]):
            print(*A)
            return
    else:
        print(*A)
        
if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
from copy import deepcopy
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)


n, k = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
k = min(k, 50)
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]
    A = deepcopy(B)

print(" ".join(str(b) for b in B))

Solution (Python):
from itertools import accumulate


N,K = map(int,input().split())
A = map(int,input().split()) 
for k in range(K):
    B = [0] * N
    for i,x in enumerate(A):
        L = max(0, i-x)
        R = min(N-1, i+x)
        B[L] += 1
        if R+1 != N:
            B[R+1] -= 1
    
    L = list(accumulate(B))[:]
    if L == A:
        break
    A = L
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
def solve(N,K,A):
    for j in range(0, K):
        B = np.zeros(N, dtype=np.int64)

        for i in range(0,N):
            f = max(0, i - A[i])
            t = min(N-1, i + A[i])
            
            
            B[f] += 1
            if t+1 < N:
                B[t+1] -= 1
        A = np.cumsum(B)
        if np.all(A == N):
            return A
        i += 1
    return A
    

print(" ".join(map(str, solve(N,K,A))))

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

isMax = False
while K > 0 and not isMax:
    isMax = True
    B = [0] * N
    for i, d in enumerate(A):
        l = max(0, i - d)
        B[l] += 1
        r = i + d + 1
        if r < N:
            B[r] -= 1
    for i in range(N - 1):
        isMax &= (B[i] >= N)
        B[i + 1] += B[i]
    A = B
    K -= 1

print(*A[:N])

Solution (Python):

from itertools import accumulate
def resolve():

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

    for _ in range(K):
        imos_table = [0]*(N+1)
        for i, a in enumerate(A):
            
            imos_table[max(i - a, 0)] += 1
            imos_table[min(i + a + 1, N)] -= 1
        A = list(accumulate(imos_table))[:-1]
        if all([True if a == N else False for a in A]):
            print(*A)
            return
    else:
        print(*A)

if __name__ == "__main__":
    resolve()

Solution (Python):
def a_to_b(A):
    c = [0] * N
    for i, a in enumerate(A):
        lb = max(0, i - a)
        c[lb] += 1
        ub = i + a + 1
        if ub < N:
            c[ub] -= 1
    tmp = 0
    B = []
    for ci in c:
        tmp += ci
        B.append(tmp)
    return B


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

ans = A
for _ in range(K):
    ans = a_to_b(ans)
    if sum(ans) == N ** 2:
        break

print(*ans)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]
zero=[0 for i in range(N+1)]
ANS=[str(N)]*N
if K>=40:
  ans=" ".join(ANS)
  print(ans)
else:
  for t in range(K):
    for i in range(N):
      l=max(0,i-A[i])
      r=min(N,i+A[i]+1)
      imos[l]+=1
      imos[r]-=1
    for i in range(0,N):
      imos[i+1]+=imos[i]
      A[i]=imos[i]
    imos=[0 for i in range(N+1)]
  for i in range(N):
    A[i]=str(A[i])
  ans=" ".join(A)
  print(ans)

Solution (Python):
from itertools import accumulate

N, K = map(int, input().split())
*A, = map(int, input().split())
for i in range(K):
    a = [0]*N
    allN = True
    for j in range(N):
        l, r = max(j-A[j], 0), (j+A[j]+1)
        a[l] += 1
        if r < N:
            a[r] -= 1
        if A[j] != N:
            allN = False
    A = list(accumulate(a))
    if allN:
        break

print(*A)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]

for t in range(K):
  for i in range(N):
    l=max(0,i-A[i])
    r=min(N,i+A[i]+1)
    imos[l]+=1
    imos[r]-=1
  for i in range(0,N):
    imos[i+1]+=imos[i]
    A[i]=imos[i]
  imos=[0 for i in range(N+1)]
  if len(set(A))==1 and (N in set(A)):
    break
for i in range(N):
  A[i]=str(A[i])
ans=" ".join(A)
print(ans)

Solution (Python):
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):
        l = max(0, j-a[j])
        r = min(n, j+a[j]+1)
        b[l] += 1
        b[r] -= 1
    for j in range(n):
        b[j+1] += b[j]
    b.pop()
    if a == b:
        break
    a = b
print(' '.join(map(str, a)))

Solution (Python):

import numpy as np

def main():
    N, K = map(int, input().split())
    A = np.array(input().split(),dtype=int)
    I = np.arange(N)
    for i in range(K):
        B = np.zeros(N+1, int)
        
        np.add.at(B, np.maximum(0,I-A),1)
        np.add.at(B, np.minimum(N,I+A+1),-1)
        A = B.cumsum()[:-1]
        if np.all(A == N):
            break
    print(*A)

if __name__ == "__main__":
    main()

Solution (Python):
import copy
n,k = map(int,input().split())
ai = [int(i) for i in input().split()]


cnt = 0

aij = [[0 for i in range(n)] for j in range(2)]
aij[0] = ai

while 1 == 1:
    li = [0]*(n+1)
    for i in range(n):
        li[max(0,i-aij[0][i])] += 1
        li[min(n,i+1+aij[0][i])] -= 1
        
    
    tmp = 0
    for i in range(n):
        if i == 0:
            aij[1][i] = li[i]
            tmp += aij[1][i]
        else:
            aij[1][i] = li[i] + aij[1][i-1]
            tmp += aij[1][i]
    
    if aij[1] == aij[0]:
        print(*aij[1])
        exit()
        break
    cnt += 1
    if cnt == k:
        print(*aij[1])
        exit()
    for i in range(n):
        aij[0][i] = aij[1][i]

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

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    loop_count = min(K, 42)
    for _ in range(loop_count):
        light_range_list = [[0, 0] for _ in range(N)]
        for i, a in enumerate(A):
            start, end = max(0, i-a), min(N, i+a+1)
            light_range_list[i][0] = start
            light_range_list[i][1] = end
        ans = [0] * N
        for light_range in light_range_list:
            start, end = light_range[0], light_range[1]
            ans[start] += 1
            if end < N:ans[end] -= 1
        for i in range(N-1):
            ans[i+1] = ans[i] + ans[i+1]
        A = ans
    print(" ".join(list(map(str, ans))))
if __name__ == "__main__":
    main()

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]
ANS=[str(N)]*N
if K>=50:
  ans=" ".join(ANS)
  print(ans)
else:
  for t in range(K):
    for i in range(N):
      l=max(0,i-A[i])
      r=min(N,i+A[i]+1)
      imos[l]+=1
      imos[r]-=1
    for i in range(0,N):
      imos[i+1]+=imos[i]
      A[i]=imos[i]
    imos=[0 for i in range(N+1)]
  for i in range(N):
    A[i]=str(A[i])
  ans=" ".join(A)
  print(ans)

Solution (Python):
import copy
n,k = map(int,input().split())
ai = [int(i) for i in input().split()]


cnt = 0
old_tmp = sum(ai)

while 1 == 1:
    
    li = [0]*(n+1)
    for i in range(n):
        li[max(0,i-ai[i])] += 1
        li[min(n,i+1+ai[i])] -= 1
        
    
    tmp = 0
    for i in range(n):
        if i == 0:
            ai[i] = li[i]
            tmp += ai[i]
        else:
            ai[i] = li[i] + ai[i-1]
            tmp += ai[i]
    
    if old_tmp == tmp:
        print(*ai)
        exit()
        break
    cnt += 1
    if cnt == k:
        print(*ai)
        exit()
    old_tmp = tmp

Solution (Python):
import copy
n,k = map(int,input().split())
ai = [int(i) for i in input().split()]

old_ai = ai
cnt = 0

while 1 == 1:
    old_ai = copy.deepcopy(ai)
    li = [0]*(n+1)
    for i in range(n):
        li[max(0,i-ai[i])] += 1
        li[min(n,i+1+ai[i])] -= 1
        
    
    tmp = 0
    for i in range(n):
        if i == 0:
            ai[i] = li[i]
            tmp += ai[i]
        else:
            ai[i] = li[i] + ai[i-1]
            tmp += ai[i]
    
    if ai == old_ai:
        print(*ai)
        exit()
        break
    cnt += 1
    if cnt == k:
        print(*ai)
        exit()
    old_ai = ai

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
import math

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mina = min(A)
    for i in range(K):
        B = [0]*N
        for j in range(N):
            if j-A[j] >= 0:
                B[j-A[j]] += 1
            else:
                B[0] += 1
            if j+A[j]+1 < N:
                B[j+A[j]+1] -= 1
        A = list(accumulate(B[:]))
        mina = mina*2+1
        if mina >= N and A[0] == A[-1] == N:
            break
    print(*A)

if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate
N, K, *A = map(int, open(0).read().split())
for _ in range(min(K, 41)):
    next_A = [0] * (N + 1)
    for i, a in enumerate(A):
        next_A[max(0, i - a)] += 1
        next_A[min(N, i + a + 1)] -= 1
    A = list(accumulate(next_A))
A.pop()
print(*A)

Solution (Python):
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)  
I = np.arange(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):
N, K = map(int, input().split())
As = list(map(int, input().split()))


for i in range(K):
    
    table = [0 for _ in range(N+1)]
    
    
    
    for j in range(1,N+1):
        ai = As[j-1]
        
        
        table[max(j-ai, 1)] += 1
        
        
        if j+ai<N:
            table[min(j+ai+1, N)] -= 1 

    
    for j in range(1,N+1):
        table[j] += table[j-1]
        
    
    for j in range(N):
        As[j] = table[j+1]
        
    
    exit_condition = True
    for j in range(N):
        if As[j] != N:
            exit_condition = False
            break
        
    
    if exit_condition:
        print(*As)
        exit(0)
            

print(*As)

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

for i in range(k):
    table = [0 for _ in range(n*2)]
    
    for j in range(n):
        ai = a[j]
        
        table[max((j-ai)*2-1,0)] += 1
        
        table[min((j+ai)*2+1,n*2-1)] -= 1
    
    for j in range(n*2):
        if j > 0:
            table[j] += table[j-1]
    for j in range(n):
        a[j] = table[j*2]
    flag = True
    for j in range(n):
        if a[j] != n:
            flag = False
            break
    if flag:
        print(*a)
        exit()
print(*a)

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

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


if __name__ == '__main__':
    main()

Solution (Python):

import copy
import itertools

n, k = map(int, input().split())
a_list = [int(x) for x in input().split()]

for j in range(k):
    b_list = [0]*n

    for i in range(n):
        l = max(0, i-a_list[i])
        r = min(n-1, i+a_list[i])
        b_list[l] += 1
        if r+1 < n:
            b_list[r+1] -= 1

    cumsum = list(itertools.accumulate(b_list))
    if cumsum == [n]*n:
        break
    a_list = cumsum
print(*cumsum)

Solution (Python):
import copy
n,k = map(int,input().split())
ai = [int(i) for i in input().split()]

old_ai = ai
cnt = 0

while 1 == 1:
    old_ai = copy.deepcopy(ai)
    li = [0]*(n+1)
    for i in range(n):
        li[max(0,i-ai[i])] += 1
        li[min(n,i+1+ai[i])] -= 1
        
    
    rui = [0]*n
    tmp = 0
    for i in range(n):
        if i == 0:
            ai[i] = li[i]
            tmp += ai[i]
        else:
            ai[i] = li[i] + ai[i-1]
            tmp += ai[i]
    
    if ai == old_ai:
        print(*ai)
        exit()
        break
    cnt += 1
    if cnt == k:
        print(*ai)
        exit()
    old_ai = ai

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

ML = 50
r = min(ML,k)

for l in range(r):
    imos = [0]*(n+1)
    for i in range(n):
        left = max(0,i-a[i])
        right = min(n,i+a[i]+1)
        
        imos[left] += 1
        imos[right] -= 1
        
    c = 0
    for i in range(n):
        c += imos[i]
        a[i] = c
        
print(*a)

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
import copy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,k=MI()
lis=LI()
for i in range(min(k,100)):
    lis2=[0 for i in range(n)]
    for i in range(n):
        lis2[max(0,i-lis[i])]+=1
        if i+lis[i]+1<n:
            lis2[i+lis[i]+1]+=-1
    lis=list(accumulate(lis2))
    
print(*lis)

Solution (Python):
import numpy as np
from numba import jit
@jit(cache=True)
def solve(n,k,A):
    l,r=0,0
    for ki in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for i,j in enumerate(A):
            l=max(0,i-j)
            r=min(n,i+j+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=np.array(A)
x=solve(n,k,A)
print(*x)

Solution (Python):
import numpy as np
from numba import jit
@jit(cache = True)
def solve(n,k,A):
    l,r=0,0
    for i in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for x,y in enumerate(list(A)):
            l=max(0,x-y)
            r=min(n,x+y+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=np.array(a)
X=solve(n,k,A)
print(*X,sep=' ')

Solution (Python):
from itertools import accumulate

N, K = map(int, input().split())
al = list(map(int, input().split()))
syusoku = [N] * N

for _ in range(K):
    s = [0] * N
    for i in range(N):
        left = i - al[i]
        right = i + al[i]
        if left < 0:
            left = 0
        s[left] += 1
        if right + 1 <= N - 1:
            s[right + 1] -= 1
        
    al = list(accumulate(s))
    
    if al == syusoku:
        print(*al)
        
        exit()

print(*al)

Solution (Python):
import math
from itertools import accumulate

N, K = map(int, input().split())
al = list(map(int, input().split()))
syusoku = [N] * N

for _ in range(K):
    s = [0] * N
    for i in range(N):
        left = i - al[i]
        right = i + al[i]
        if left < 0:
            left = 0
        s[left] += 1
        if right + 1 <= N - 1:
            s[right + 1] -= 1
        
    al = list(accumulate(s))
    
    if al == syusoku:
        print(*al)
        
        exit()

print(*al)

Solution (Python):
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()


end = [n]*n

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

for i in range(n):
    print(str(int(a[i]))+" ",end = "" )

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

    for i in range(K):

        arr = [0] * (N + 1)

        for ind,j in enumerate(A):
            arr[max(ind-j,0)] += 1
            arr[min(ind+j+1, N)] -= 1

        A[0] = arr[0]
        for k in range(N-1):
            A[k+1] = A[k] + arr[k+1]

        if arr[0] ==N and arr[-1] == -N:
            return A
    return A


if __name__ == "__main__":
    ans = solve()
    print(*ans)

Solution (Python):
def solve(N,K,A):
    for i in range(K):
        arr = [0] * (N + 1)

        for ind,j in enumerate(A):
            arr[max(ind-j,0)] += 1
            arr[min(ind+j+1, N)] -= 1

        A[0] = arr[0]
        for k in range(N-1):
            A[k+1] = A[k] + arr[k+1]

        if arr[0] ==N and arr[-1] == -N:
            return A
    return A


if __name__ == "__main__":
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = solve(n,k,a)
    print(*ans)

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

from itertools import accumulate

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

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

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])

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

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

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

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, k = i_map()
    num_list = i_list()

    for _ in range(k):
        if num_list.count(n) == n:
            break
        tmp_list = [0] * (n+1)
        for j in range(n):
            l = max(0, j - num_list[j])
            r = min(j + num_list[j]+ 1, n)
            tmp_list[l] += 1
            tmp_list[r] -= 1
        for j in range(n):
            tmp_list[j+1] += tmp_list[j]
        num_list = deepcopy(tmp_list)
        
    print(*num_list[:n])

if __name__ == '__main__':
    main()

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

for i in range(k):
    imo = [0] * (n + 1)
    for j in range(n):
        tmp = j-A[j]
        if tmp < 0:
            tmp = 0
        imo[tmp] += 1
        tmp2 = j+A[j]+1
        if tmp2 > n:
            tmp2 = n
        imo[tmp2] -=1
    if imo[0] == n and imo[n] == -n:
        A = [n] * n
        A = map(str, A)
        print(' '.join(A))
        exit()
    else:
        temp = 0
        for k in range(n):
            temp += imo[k]
            A[k] = temp
A = map(str, A)
print(' '.join(A))

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

for _ in range(k):
    tmp = [0 for _ in range(n + 1)]
    for i, num in enumerate(alst):
        min_ind = max(i - num, 0)
        max_ind = min(i + num + 1, n)
        tmp[min_ind] += 1
        tmp[max_ind] -= 1
    next_num = 0
    for i, num in enumerate(tmp[:-1]):
        next_num += num
        alst[i] = next_num
    if tmp[0] == n and tmp[-1] == -n:
        break
print(*alst)

Solution (Python):
import sys

from numba import njit

import numpy as np

readline = sys.stdin.buffer.readline


@njit('i8[:](i8, i8, i8[:])', cache=True)
def f(N, K, A):
    for i in range(min(K, 100)):
        C = np.zeros(N + 1, dtype=np.int64)

        for j, a in enumerate(A):
            l = max(0, j - a)
            r = min(j + a + 1, N)
            C[l] += 1
            C[r] -= 1

        A = np.cumsum(C)

    return A


def solver():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = f(N, K, np.array(A))
    print(*A[:-1])


solver()

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 update(a):
    n = len(a)
    b = np.zeros_like(a)       
    for i, x in enumerate(a):  
        l = max(0, i - x)      
        r = min(n - 1, i + x)  
        b[l] += 1              
        if r + 1 < n:          
            b[r + 1] -= 1
    b = np.cumsum(b)           
    return b


n, k = map(int, readline().split())
a = np.array(read().split(), np.int64)

k = min(k, 41)                 
for _ in range(k):
    a = update(a)
print(' '.join(map(str, a)))

Solution (Python):

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

for i in range(K):
    table = [0 for _ in range(N*2)]
    
    for j in range(N):
        ai = As[j]
        
        table[max((j-ai)*2-1, 0)] += 1
        
        table[min((j+ai)*2+1, N*2-1)] -= 1
    
    
    for j in range(N*2):
        if j > 0:
            table[j] += table[j-1]
    
    
    for j in range(N):
        As[j] = table[j*2]
    
    exit_condition = True
    for j in range(N):
        if As[j] != N:
            exit_condition = False
            break
    
    if exit_condition:
        print(*As)
        exit(0)
            

print(*As)

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

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

    for j in range(1, N):
        B[j] += B[j - 1]
        
    A = B

[print(i, end=' ') for i in B]
print()