Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-i]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)

Fixed submission:
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-1]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
for i in range(1,n):
    b = a[-i]
    c = getNearestValue(a,b/2)
    an = combinations_count(b,c)
    if check < an:
        check = an
        ans = str(b) + ' ' + str(c)
print(ans)

Fixed submission:
import math
import numpy as np

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
a = [int(i) for i in input().split()]
check = 0
a.sort()
b = a[-1]
c = getNearestValue(a,b/2)
ans = str(b) + ' ' + str(c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k = map(int,input().split())

a = np.array([0]*n)
a[0] += n
b = np.array([1,0])
for i in range(1,n):
    c = n // np.size(b)
    d = n % np.size(b)
    a[1:i+1] += c
    a[0] +=c
    b = np.append(b,i+1)
    if d > 0:
        a[1:d+1] +=1
    #print(a)
print(np.sum(a[k:]))


Fixed submission:
import numpy as np
n,k = map(int,input().split())

a = np.array([0]*n,dtype ='int64')
a[0] += n
for i in range(1,n):
    c = n // (1+i)
    d = n % (1+i)
    a[1:i+1] += c
    a[0] +=c
    if d > 0:
        a[1:d+1] +=1
print(np.sum(a[k:]))
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
def get_prime(n):
    if n<= 1:
        return[]
    prime = [2]
    limit = int(math.sqrt(n))
    
    data = [i + 1 for i in range(2,n,2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
n = int(input())
a = get_prime(10**5+1)
b = np.array([0]*(10**5+2))
c =0
d = 0
add = 0
for i in range(1,len(a)):
    if is_prime((a[i]+1)/2):
        d = a[i] 
        b[c:d] = add 
        c = d
        add +=1
b[c:] = add 
b[0::2] = 0

for i in range(n):
    l, r =map(int,input().split())
    print(b[max(0, l[i] - 2)] - b[r[i]])
    

Fixed submission:
q = int(input())
l, r = [0] * q, [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())
 
mini = min(min(l), min(r))
maxi = max(max(l), max(r))
ans = [0] * (maxi + 1)
prime = [0] * (maxi + 1)
def judge_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    
    return True if n != 1 else False
 
for i in range((mini + 1) // 2, maxi + 1):
    prime[i] = judge_prime(i)
 
for i in range(mini, maxi + 1, 2):
    ans[i] = ans[i - 2] + 1 if prime[i] and prime[(i + 1) // 2] else ans[i - 2]
for i in range(q):
    print(ans[r[i]] - ans[max(0, l[i] - 2)])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a =[int(i)  for i in input().split()]
b = sum(a) // 2
z = sum(a)
ans = 10**20

for i in range(1,n):
    c = sum(a[:i])
    d = z - c
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Fixed submission:
n = int(input())
a =[int(i)  for i in input().split()]
z = sum(a)
ans = 10**20
c = 0

for i in range(n-1):
    c += a[i]
    z -= a[i]
    if abs(c-z) < ans:
        ans = abs(c-z)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a =[int(i)  for i in input().split()]
b = sum(a) // 2

ans = 10**20

for i in range(1,n):
    c = sum(a[:i])
    d = sum(a[i:])
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Fixed submission:
n = int(input())
a =[int(i)  for i in input().split()]
z = sum(a)
ans = 10**20
c = 0

for i in range(n-1):
    c += a[i]
    z -= a[i]
    if abs(c-z) < ans:
        ans = abs(c-z)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = n-m
ans = 0
if abs(a) > 1:
    ans = 0
elif abs(a) == 1:
    x = 1
    y = 1
    for i in range(1,n+1):
        x *= i % (10**9+7)
    for i in range(1,m+1):
        y *= i % (10**9+7)
    ans = x * y %(10**9+7)
else:
    x = 1
    y = 1
    for i in range(1,n+1):
        x *= i % (10**9+7)
    for i in range(1,m+1):
        y *= i % (10**9+7)
    ans = 2*x * y %(10**9+7)
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = n-m
ans = 0
if abs(a) > 1:
    ans = 0
elif abs(a) == 1:
    x = 1
    if a < 0:
        s = n
    else:
        s = m
    for i in range(1,s+1):
        x *= i 
        x %= (10**9+7)
    ans = x * x *(i+1) %(10**9+7)
else:
    x = 1
    for i in range(1,n+1):
        x *= i 
        x %= (10**9+7)
    ans = 2* x**2  %(10**9+7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = 1
for i in range(1,n+1):
    a *= i

print(a % (10**9+7))

Fixed submission:
n = int(input())
a = 1
for i in range(1,n+1):
    a = i * a % (10**9+7)

print(a)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int, input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        l = s - i - j
        #print('{} {} {}'.format(i,j,l))
        if i + j + l == s and l >= 0 and k >= l:
            ans +=  1
            
print(ans)

Fixed submission:
k,s = map(int, input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        l = s - i - j
        #print('{} {} {}'.format(i,j,l))
        if  l >= 0 and k >= l:
            ans +=  1
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
s = 0
if n % 2 == 0:
    b = [int(i) for i in range(n) if i % 2 == 1]
    for i in b:
        c = a.count(i)
        if c != 2:
            s = 1
            break
    ans = 2 ** len(b) % (10**9 + 7)
else:
    b = [int(i) for i in range(n) if i % 2 == 0]
    for i in b:
        c = a.count(i)
        
        
        if c == 1 and i == 0:
            ans = 1
        elif c != 2:
            s = 1
            break
    ans = 2 ** (len(b)-1) % (10**9 + 7)

if s == 0:
    print(ans)
elif s == 1:
    print('0')

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
s = 0
b = 0
d = [0]*n
if n % 2 == 0:
    for i in a:
        d[i] += 1 
    for i in range(1,n,2):
        if d[i] != 2:
            s = 1
            break
        else:
            b += 1
    ans = 2 ** b % (10**9 + 7)
else:
    for i in a:
        d[i] += 1 
    
    for i in range(0,n,2):
        if i == 0 and d[0] == 1:
            ans = 1
        elif d[i] != 2:
            s = 1
            break
        else:
            b += 1
    ans = 2 ** (b) % (10**9 + 7)

if s == 0:
    print(ans)
elif s == 1:
    print('0')
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
c = range(a,b+1)
ans = 0
for i in range(len(c)):
    if c[i] % x == 0:
        ans +=1
        
print(ans)

Fixed submission:
a,b,x = map(int,input().split())
print(b//x - (a-1)//x)
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())
a = list(input().split())
ans = 0

if int(a[0]) > x:
    ans += a[0]-x
    a[0] = x
for i in range(n-1):
    c = int(a[i+1]) + int(a[i])
    if c > x:
        ans += c-x
        a[i+1] = int(a[i+1])-(c-x)
print(ans)

Fixed submission:
n,x = map(int,input().split())
a = list(input().split())
ans = 0

if int(a[0]) > x:
    ans += int(a[0])-x
    a[0] = x
for i in range(n-1):
    c = int(a[i+1]) + int(a[i])
    if c > x:
        ans += c-x
        a[i+1] = int(a[i+1])-(c-x)
print(ans)
Buggy python submission (verdict: Runtime Error):
w,h,n = map(int,input().split())

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j >= int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j <= int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j >= int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j <= int(y_i)]

print((max(x)-min(x)) * (max(y)-min(y)))

Fixed submission:
w,h,n = map(int,input().split())

x = [int(i) for i in range(w+1)]
y = [int(i) for i in range(h+1)]

for i in range(n):
    x_i, y_i, a = map(int,input().split())
    if a == 1:
        x = [int(j) for j in x if j >= int(x_i)]
    elif a == 2:
        x = [int(j) for j in x if j <= int(x_i)]
    elif a == 3:
        y = [int(j) for j in y if j >= int(y_i)]
    elif a == 4:
        y = [int(j) for j in y if j <= int(y_i)]
if len(x) == 0 or len(y) == 0:
    print('0')
else:
    print((max(x)-min(x)) * (max(y)-min(y)))
Buggy python submission (verdict: Runtime Error):
w = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
c = []
for i in range(26):
    a = w.count(alp[i])
    c.append(a)
d = 0
for i in range(len(w)):
    if int(c[i]) % 2 == 0:
        d = 1
    else:
        break
if d == 0:
    print('No')
else:
    print('Yes')

Fixed submission:
w = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
c = []
for i in range(26):
    a = w.count(alp[i])
    c.append(a)
d = 0
for i in range(26):
    if c[i] % 2 == 0:
        d = 1
    else:
        d = 0
        break
if d == 0:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
s = list(input())
a = s.count('B')
b = []
for i in range(len(s)):
    if s[i] == 'B':
        b.append(i)
b.sort(reverse=True)
for i in b:
    s.pop(i)
    s.pop(i-1)
print(''.join(s))


Fixed submission:
s = input()
b = ''
for i in s:
    if i == 'B':
        b = b[:-1]
    else:
        b += i
print(b)
Buggy python submission (verdict: Runtime Error):
 = int(input())

ans = 0

for i in range(1,n):
    s = (n-1)//i
    if  0< s < n:
        ans += s
print(ans)

Fixed submission:
n = int(input())

ans = 0

for i in range(1,n):
    s = (n-1)//i
    if  0< s < n:
        ans += s
print(ans)
Buggy python submission (verdict: Runtime Error):
S =input()
T =input()
min_count　=　10000

for i in range(len(S)-len(T)+1):
    count = 0
    for j in range(len(T)):
        if T[i+j] != S[j]:
            count += 1
        min_count =min(count,min_count)
        if min_count = 0:
            print(min_count)
            break

print(min_count)

Fixed submission:
D ,T, S   = map(int,input().split()) 
if (D )/ S <= T :
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
S =input()
T =input()
mint=10000

for i in range(len(S)-len(T)+1):
    con = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            con += 1
            
    mint =min(con,mint)
    
    if min_count == 0:
        break


print(mint)

Fixed submission:
S =input()
T =input()
mint=10000

for i in range(len(S)-len(T)+1):
    con = 0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            con += 1
            
    mint =min(con,mint)
    
    if mint == 0:
        break


print(mint)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
n = 1
ans = 0
mainus = 0
 

for i in a:
    mainus += i
    ans_a = a[n-1] * (sum(a) - mainus )
    ans += ans_a
    n += 1

MOD = 10 ** 9 + 7
ans %= MOD

print(ans)

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

MOD = 10 ** 9 + 7
s =sum(a) % MOD
ans = 0

for i in a :
    s -= i
    s %= MOD
    ans += i * s
    ans %= MOD
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))

ans = 0

l.sort()

for i in range(n) :
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] != l[j] != l[k] and  l[i] < l[j] < l[k]:
                    ans += 1

print(ans)

Fixed submission:
s = input()

three ='RRR'
two ='RR'
one ='R'

if  three in s:
    print('3')
elif two in s:
    print('2')
elif one in s:
    print('1')
    
else :
    print('0')
Buggy python submission (verdict: Runtime Error):
c = x // d
# 必要な移動回数
k_r = k - c
# 移動した後の残りの移動回数
ans_2 = x - d * c
#残り移動回数が偶数のときのｘからの距離

if c >= k:
    print(x - k * d )
    exit()

x_l = x - d * c
#ｘまでの残りの距離

if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)

Fixed submission:
x ,k ,d = map(int,input().split())

x = abs(x)
c = x // d
# 必要な移動回数
k_r = k - c
# 移動した後の残りの移動回数
ans_2 = x - d * c
#残り移動回数が偶数のときのｘからの距離

if c >= k:
    print(x - k * d )
    exit()

x_l = x - d * c
#ｘまでの残りの距離

if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)
Buggy python submission (verdict: Runtime Error):
a, b, c, x, y = map(int,input().split())

mast = max(x,y)
ans = max(a * x + b * y,c *2 *i)

for i in range(mast+1):
    price = a * max(x-i,0) + b * max(y-i,0) + c *2 *i
    ans =min(ans,price) 
    
print(ans)

Fixed submission:
a, b, c, x, y = map(int,input().split())

mast = max(x,y)
ans = float('INF')

for i in range(mast+1):
    price = a * max(x-i,0) + b * max(y-i,0) + c *2 *i
    ans =min(ans,price) 
    
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b, c, x, y = map(int,input().split())

mast = max(x,y)
ans =  c *2 *i

for i in range(mast+1):
    price = a * max(x-i,0) + b * max(y-i,0) + c *2 *i
    ans =min(ans,price) 
    
print(ans)

Fixed submission:
a, b, c, x, y = map(int,input().split())

mast = max(x,y)
ans = float('INF')

for i in range(mast+1):
    price = a * max(x-i,0) + b * max(y-i,0) + c *2 *i
    ans =min(ans,price) 
    
print(ans)

Buggy python submission (verdict: Runtime Error):
# 095 c
a, b, c, x, y = map(int,input().split())

mast = max(x,y)
ans =  c *2 *i

for i in range(mast+1):
    price = a * max(x-i,0) + b * max(y-i,0) + c *2 *i
    ans =min(ans,price) 
    
print(ans)

Fixed submission:
a, b, c, x, y = map(int,input().split())

mast = max(x,y)
ans = float('INF')

for i in range(mast+1):
    price = a * max(x-i,0) + b * max(y-i,0) + c *2 *i
    ans =min(ans,price) 
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int,input().split())

ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s :
                ans += 1

print(ans)

Fixed submission:
k, s = map(int,input().split())

ans = 0
for x in range(k+1):
    for y in range(k+1):
            z = s - x - y 
            if z <= k and z >= 0 :
                ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int64)
b = np.array(input().split(), dtype=np.int64)
ac = np.bincount(a, minlength=n+2)
ab = np.bincount(b, minlength=n+2)
if np.max(ac+ab) <= n:
    num, count = np.unique(b, return_counts=True)
    ans = []
    for i in range(n):
        if a[i] == num[-1]:
            if len(num) == 1:
              print("No")
              sys.exit()
            ans.append(num[-2])
            if count[-2] == 1:
                num[-2] = num[-1]
                count[-2] = count[-1]
                num = num[:-1]
                count = count[:-1]
            else:
                count[-2] -= 1
        else:
            ans.append(num[-1])
            if count[-1] == 1:
                num = num[:-1]
                count = count[:-1]
            else:
                count[-1] -= 1
    print("Yes")
    print(*ans)
else:
    print("No")


Fixed submission:
x = int(input())
if x == 1:
    ans = 0
else:
    ans = 1
print(ans)

Buggy python submission (verdict: Runtime Error):
x = int(input())
if x ==　1:
    ans = 0
else:
    ans = 1
print(ans)

Fixed submission:
x = int(input())
if x == 1:
    ans = 0
else:
    ans = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read
MOD = 10**9 + 7

n = int(input())
a = np.array(readline().split(), dtype=np.uint64)
r = np.cumsum(a[::-1])[::-1]
r &= MOD
x = a[:-1] * r[1:]
x %= MOD
ans = int(np.sum(x) % MOD)
print(ans)


Fixed submission:
d, t, s = map(int, input().split())
ans = "No" if d > t * s else "Yes"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
for i in range(1,n+1):
    ans = 0
    N = int((i*2)**(1/2))+1
    for j in range(1,N+1):
        for k in range(1,j+1):
            for l in range(1, k+1):
                if (j+k)**2 + (k+l)**2 + (l+j)**2 == 2*i:
                    if j==k==l:
                        ans += 1
                    elif j > k > l:
                        ans += 6
                    else:
                        ans += 3
                if (j+k)**2 + (k+l)**2 + (l+j)**2 >= 2*i:
                    break
            if (j+k)**2 > 2*i:
                break
    print(ans)

Fixed submission:
from numba import njit

@njit("i8(i8)")
def loop(i):
    ans = 0
    N = int((i*2)**(1/2))+1
    for j in range(1,N+1):
        for k in range(1,j+1):
            for l in range(1, k+1):
                if (j+k)**2 + (k+l)**2 + (l+j)**2 == 2*i:
                    if j==k==l:
                        ans += 1
                    elif j > k > l:
                        ans += 6
                    else:
                        ans += 3
                if (j+k)**2 + (k+l)**2 + (l+j)**2 >= 2*i:
                    break
            if (j+k)**2 > 2*i:
                break
    return(ans)

n = int(input())
for i in range(1,n+1):
    print(loop(i))
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

read = sys.stdin.read

n = int(input())
a = np.array(readline().split(), dtype=np.int64)
a.sort()
a = a[::-1]
m = -(-n//2)
ans = np.sum(a[:m])*2 - a[0] if n % 2 == 0 else np.sum(a[:m])*2 - a[0] - a[m]
print(ans)

Fixed submission:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
a = np.array(readline().split(), dtype=np.int64)
a.sort()
a = a[::-1]
m = -(-n//2)
ans = np.sum(a[:m])*2 - a[0] if n % 2 == 0 else np.sum(a[:m])*2 - a[0] - a[m-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

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):
        print(*a)
        break
else:
    print(*a)

Fixed submission:
import sys
import numpy as np
from numba import njit

readline = sys.stdin.readline

@njit('i8,i8,i8[::1]',cache=True)
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)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

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]
print(*a)


Fixed submission:
import sys
import numpy as np
from numba import njit

readline = sys.stdin.readline

@njit('i8,i8,i8[::1]',cache=True)
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)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, k = map(int, input().split())
a = (0,) + tuple(map(int, input().split()))

c = deque()
i = 1
while True:
    A = a[i]
    if A in c:
        break
    else:
        c.append(a[i])
        i = A

c = list(c)
s = c.index(A)

if k < s:
    print(c[k-1])
else:
    k -= s
    c = c[s:]
    ans = c[k % len(c) - 1]
    print(ans)

Fixed submission:
import sys
import numpy as np

read = sys.stdin.read

def dubbling(a:np.array, k:int, MAXk=10**12) -> np.array:
    bl = MAXk.bit_length()
    b = np.empty([bl,len(a)+1], dtype=np.int64)
    b[0] = np.append(a, -1)
    for i in range(1,bl):
        x = b[i-1]
        b[i] = x[x]
    X1 = b[np.array(list(format(k,'0'+str(bl)+'b')), dtype=np.int8).astype(np.bool)[::-1]]
    ret = np.append(np.arange(len(a)), -1)
    for i in X1:
        ret = ret[i]
    return ret

n, k = map(int, input().split())
a = np.array(read().split(), dtype=np.int64)
maxk = 10**18

ans = dubbling(a-1, k, MAXk=maxk)[0] + 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

c = list()
i = 1
while True:
    if a[i] in c:
        break
    else:
        c.append(a[i])
        i = a[i]

s = c.index(a[i])

if k < s:
    print(c[k-1])
else:
    k -= s
    c = c[s:]
    ans = c[k % len(c) - 1]
    print(ans)

Fixed submission:
import sys
import numpy as np

read = sys.stdin.read

def dubbling(a:np.array, k:int, MAXk=10**12) -> np.array:
    bl = MAXk.bit_length()
    b = np.empty([bl,len(a)+1], dtype=np.int64)
    b[0] = np.append(a, -1)
    for i in range(1,bl):
        x = b[i-1]
        b[i] = x[x]
    X1 = b[np.array(list(format(k,'0'+str(bl)+'b')), dtype=np.int8).astype(np.bool)[::-1]]
    ret = np.append(np.arange(len(a)), -1)
    for i in X1:
        ret = ret[i]
    return ret

n, k = map(int, input().split())
a = np.array(read().split(), dtype=np.int64)
maxk = 10**18

ans = dubbling(a-1, k, MAXk=maxk)[0] + 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

c = list()
i = 1
while True:
    if a[i] in c:
        break
    else:
        c.append(a[i])
        i = a[i]

s = c.index(a[i])

if k < s:
    print(c[k-1])
else:
    k -= s
    c = c[s:]
    ans = c[k % len(c) - 1]
    print(ans)


Fixed submission:
import sys
import numpy as np

read = sys.stdin.read

def dubbling(a:np.array, k:int, MAXk=10**12) -> np.array:
    bl = MAXk.bit_length()
    b = np.empty([bl,len(a)+1], dtype=np.int64)
    b[0] = np.append(a, -1)
    for i in range(1,bl):
        x = b[i-1]
        b[i] = x[x]
    X1 = b[np.array(list(format(k,'0'+str(bl)+'b')), dtype=np.int8).astype(np.bool)[::-1]]
    ret = np.append(np.arange(len(a)), -1)
    for i in X1:
        ret = ret[i]
    return ret

n, k = map(int, input().split())
a = np.array(read().split(), dtype=np.int64)
maxk = 10**18

ans = dubbling(a-1, k, MAXk=maxk)[0] + 1
print(ans)