Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, a, b, c, q, k, x, y):
    E = {}
    G = {}
    for u, v, d in zip(a, b, c):
        if not u in E:
            E[u] = []
        if not v in E:
            E[v] = []
        E[u].append(v)
        E[v].append(u)
        G[u, v] = d
        G[v, u] = d
    dist = {}
    dist[k] = 0
    que = [k]
    group = {}
    while que:
        v = que.pop(0)
        for u in E[v]:
            if not u in dist:
                dist[u] = dist[v] + G[u,v]
                if v == k:
                    group[u] = u
                else:
                    group[u] = group[v]
                que.append(u)
    for i in range(q):
        if group[x[i]] == group[y[i]]:
            print(dist[x[i]] + dist[y[i]])
        else:
            print(dist[x[i]] + dist[y[i]])

n = int(input())
a = [0] * (n-1)
b = [0] * (n-1)
c = [0] * (n-1)
for i in range(n-1):
    a[i], b[i], c[i] = map(int, input().split())
q, k = map(int, input().split())
x = [0] * q
y = [0] * q
for i in range(q):
    x[i], y[i] = map(int, input().split())
solve(n, a, b, c, q, k, x, y)

Fixed submission:
from collections import deque

def solve(n, a, b, c, q, k, x, y):
    E = {}
    G = {}
    for u, v, d in zip(a, b, c):
        if not u in E:
            E[u] = []
        if not v in E:
            E[v] = []
        E[u].append(v)
        E[v].append(u)
        G[u, v] = d
        G[v, u] = d
    dist = {}
    dist[k] = 0
    que = deque([k])
    while que:
        v = que.pop()
        for u in E[v]:
            if not u in dist:
                dist[u] = dist[v] + G[u,v]
                que.append(u)
    for i in range(q):
        print(dist[x[i]] + dist[y[i]])

n = int(input())
a = [0] * (n-1)
b = [0] * (n-1)
c = [0] * (n-1)
for i in range(n-1):
    a[i], b[i], c[i] = map(int, input().split())
q, k = map(int, input().split())
x = [0] * q
y = [0] * q
for i in range(q):
    x[i], y[i] = map(int, input().split())
solve(n, a, b, c, q, k, x, y)
Buggy python submission (verdict: Runtime Error):
def f(k):
    if k == 0:
        return [0,0]
    elif k == 1:
        return [2,0]
    elif k == 2:
        return [2,1]
    else:
        return [k//2, k-k//2]
def solve(k):
    a = f(k)
    print(len(a))
    print(" ".join(map(str, a))
solve(k=int(input()))

Fixed submission:
def f(k):
    n = 50
    a = [k//n + n-1] * n
    for i in range(k%n):
        for j in range(n):
            if i == j:
                a[j] += n
            else:
                a[j] -= 1
    return a

def solve(k):
    a = f(k)
    print(len(a))
    print(" ".join(map(str, a)))

solve(k=int(input()))

Buggy python submission (verdict: Runtime Error):
def solve(k):
    print(2)
    print(f"0 {k}")
solve(k=int(input()))

Fixed submission:
def f(k):
    n = 50
    a = [k//n + n-1] * n
    for i in range(k%n):
        for j in range(n):
            if i == j:
                a[j] += n
            else:
                a[j] -= 1
    return a

def solve(k):
    a = f(k)
    print(len(a))
    print(" ".join(map(str, a)))

solve(k=int(input()))
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
a = map(int, raw_input().split())
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print " ".join(map(str, b))

Fixed submission:
n = input()
a = map(int, raw_input().split())
b = [-1] * n
for i in range(n):
    b[n/2 - (2*(i%2) - 1) * ((i+1)/2)] = a[i]
if n % 2 == 1:
    b = b[::-1]
print " ".join(map(str, b))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, W0 = map(int, raw_input().split())
items = [map(int, raw_input().split()) for i in range(N)]
w0, _ = items[0]
dp = np.full((N, N*4), -1)
def dfs(i, W):
    if i < 0:
        return 0
    if (W-N*w0 >= 0) and (dp[i][W-N*w0] != -1):
        return dp[i][W-N*w0]
    w, v = items[i]
    res = dfs(i-1, W)
    if W >= w:
        res = max(res, dfs(i-1, W-w) + v)
    if (W-N*w0 >= 0):
        dp[i][W-N*w0] = res
    return res
print dfs(N-1, W0)

Fixed submission:
import numpy as np
N, W0 = map(int, raw_input().split())
items = [map(int, raw_input().split()) for i in range(N)]
w0, _ = items[0]
dp = {}
def dfs(i, W):
    if i < 0:
        return 0
    if (i, W) in dp:
        return dp[i, W]
    w, v = items[i]
    res = dfs(i-1, W)
    if W >= w:
        res = max(res, dfs(i-1, W-w) + v)
    dp[i, W] = res
    return res
print dfs(N-1, W0)
Buggy python submission (verdict: Runtime Error):
W, a, b = map(int, raw_input().split())
print min(abs(b-a-W), abs(b-a), abs(b+W-a), abs(b-a))

Fixed submission:
a, b = raw_input().split()
print "H" if (a == "H" and b == "H") or (a == "D" and b == "D") else "D"
Buggy python submission (verdict: Runtime Error):
print min(abs(b-a-W), abs(b-a), abs(b+W-a), abs(b-a))

Fixed submission:
W, a, b = map(int, raw_input().split())
if (a+W-b) * (a-b-W) < 0:
    print 0
else:
    print min(abs(b-a-W), abs(b-a), abs(b+W-a), abs(b-a))
Buggy python submission (verdict: Runtime Error):
H, W = map(int, raw_input().split())
for i in range(W):
    s = raw_input()
    print s
    print s

Fixed submission:
H, W = map(int, raw_input().split())
for i in range(H):
    s = raw_input()
    print s
    print s
Buggy python submission (verdict: Time Limit Exceeded):
s = raw_input()
t = 0
while True:
    N = len(s)
    ok = False
    for i in range(1, N-1):
        if s[i-1] != s[i+1]:
            ok = True
            s = s[:i] + s[i+1:]
            break
    if not ok:
        print "First" if (t % 2 == 1) else "Second"
        break
    t += 1

Fixed submission:
def solve(s):
    return "First" if (len(s) % 2 == 1) ^ (s[0] == s[-1]) else "Second"
s = input()
print(solve(s))
Buggy python submission (verdict: Runtime Error):
def solve(n, a):
    """
    References
    ----------
    [1]. 足跡-sokuseki-, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://wk1080id.hatenablog.com/entry/2018/08/17/234023
    [2]. iroiro, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://xxxasdfghjk999.hatenablog.jp/entry/2018/11/01/235259
    [3]. Yang33, 競プロにおけるNim、Grundy数とNimK, http://yang33-kassa.hatenablog.com/entry/2017/12/21/202812
    """
    x = 0
    for i in range(n):
        x ^= a[i]
    b = [a[i] ^ (a[i] - 1) for i in range(n)]
    mapping = {2**k-1: 0 for k in range(30)}
    for y in b:
        mapping[y] += 1
    ans = 0
    for k in range(30, 0, -1):
        y = 2**k - 1
        z = 2**(k-1)
        if (x & z) > 0 and (mapping[y] > 0):
            ans += 1
            mapping[y] -= 1
            x ^= y
    return ans if x == 0 else -1

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Fixed submission:
def solve(n, a):
    """
    References
    ----------
    [1]. 足跡-sokuseki-, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://wk1080id.hatenablog.com/entry/2018/08/17/234023
    [2]. iroiro, CODE FESTIVAL 2016 Grand Final C - Cheating Nim, http://xxxasdfghjk999.hatenablog.jp/entry/2018/11/01/235259
    [3]. Yang33, 競プロにおけるNim、Grundy数とNimK, http://yang33-kassa.hatenablog.com/entry/2017/12/21/202812
    """
    x = 0
    for i in range(n):
        x ^= a[i]
    b = [a[i] ^ (a[i] - 1) for i in range(n)]
    mapping = {2**k-1: 0 for k in range(31)}
    for y in b:
        mapping[y] += 1
    ans = 0
    for k in range(30, 0, -1):
        y = 2**k - 1
        z = 2**(k-1)
        if (x & z) > 0 and (mapping[y] > 0):
            ans += 1
            mapping[y] -= 1
            x ^= y
    return ans if x == 0 else -1

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))
Buggy python submission (verdict: Time Limit Exceeded):
pos_black_mapping = {}
pos_num_mapping = {}
H, W, N = map(int, raw_input().split())
for i in range(N):
    a, b = map(int, raw_input().split())
    a, b = a-1, b-1
    pos_black_mapping[a, b] = 1
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            na, nb = a+dx, b+dy
            if (0 <= na < H-2) and (0 <= nb < W-2):
                pos_num_mapping[na, nb] = 1

ans = [0 for _ in range(10)]
for a, b in pos_num_mapping.keys():
    cnt = 0
    for dy in range(3):
        for dx in range(3):
            na, nb = a+dx, b+dy
            if (na, nb) in pos_black_mapping:
                cnt += 1
    ans[cnt] += 1
ans[0] = (W-2)*(H-2) - sum(ans[1:])
for v in ans:
    print v

Fixed submission:
pos_black_mapping = {}
pos_num_mapping = {}
H, W, N = map(int, raw_input().split())
for i in range(N):
    a, b = map(int, raw_input().split())
    a, b = a-1, b-1
    if (a, b) in pos_black_mapping:
        continue
    pos_black_mapping[a, b] = 1
    for da in range(-1, 2):
        for db in range(-1, 2):
            na, nb = a+da, b+db
            if (0 < na < H-1) and (0 < nb < W-1):
                if not (na, nb) in pos_num_mapping:
                    pos_num_mapping[na, nb] = 0
                pos_num_mapping[na, nb] += 1

ans = [0 for _ in range(10)]
for a, b in pos_num_mapping.keys():
    ans[pos_num_mapping[a, b]] += 1
ans[0] = (W-2)*(H-2) - sum(ans[1:])
for v in ans:
    print v
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())
dp = np.full((N+1, A+1, (N+1)*(A+1)), -1)
def dfs(i, t, W):
    if t == 0:
        return int(W == 0)
    if i < 0:
        return 0
    if dp[i, t, W] > -1:
        return dp[i, t, W]
    dp[i, t, W] = dfs(i-1, t, W) + dfs(i-1, t-1, W-x[i])
    return dp[i, t, W]
print sum([dfs(N-1, T, T*A) for T in range(1, N+1)])

Fixed submission:
N, A = map(int, raw_input().split())
x = [v - A for v in map(int, raw_input().split())]
dp = {}
def dfs(i, W):
    if i < 0:
        return int(W == 0)
    if (i, W) in dp:
        return dp[i, W]
    dp[i, W] = dfs(i-1, W) + dfs(i-1, W-x[i])
    return dp[i, W]
print dfs(N-1, 0) - 1
Buggy python submission (verdict: Runtime Error):
import numpy as np
def f(b, n):
    s = 0
    while n > 0:
        s += n % b
        n //= b
    return s

INF = int("inf")
def solve(n, s):
    if n < s:
        return -1
    if n == s:
        return n+1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m+1):
        if f(b, n) == s:
            return b
    best = INF
    for p in range(1, m+1):
        q = s - p
        if (n - q) % p != 0:
            continue
        b = (n - q) // p
        if (b > 1) and (f(b, n) == s):
            best = min(best, s)
    return -1 if (best == INF) else best

n = int(input())
s = int(input())
print(solve(n, s))

Fixed submission:
import numpy as np
def f(b, n):
    s = 0
    while n > 0:
        s += n % b
        n //= b
    return s

INF = 10**15
def solve(n, s):
    if n == s:
        return n+1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m+1):
        if f(b, n) == s:
            return b
    best = INF
    for p in range(1, m+10):
        q = s - p
        b = (n - q) // p
        if (b > p) and (b > q) and (f(b, n) == s):
            best = min(best, b)
    return -1 if (best == INF) else best

n = int(input())
s = int(input())
print(solve(n, s))

Buggy python submission (verdict: Runtime Error):
import numpy as np
def f(b, n):
    if n < b:
        return n
    else:
        n2 = n // b
        if n2 == n:
            return -1
        else:
            return f(b, n2) + (n % b)

def solve(n, s):
    if s == n:
        return n + 1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m):
        if f(b, n) == s:
            return b
    for p in range(1, m):
        q = s - p
        if (n - q) % p != 0:
            continue
        b = (n - q) // p
        if f(b, n) == s:
            return b
    return -1

n = int(input())
s = int(input())
print(solve(n, s))

Fixed submission:
import numpy as np
def f(b, n):
    s = 0
    while n > 0:
        s += n % b
        n //= b
    return s

INF = 10**15
def solve(n, s):
    if n == s:
        return n+1
    m = int(np.sqrt(n)) + 1
    for b in range(2, m+1):
        if f(b, n) == s:
            return b
    best = INF
    for p in range(1, m+10):
        q = s - p
        b = (n - q) // p
        if (b > p) and (b > q) and (f(b, n) == s):
            best = min(best, b)
    return -1 if (best == INF) else best

n = int(input())
s = int(input())
print(solve(n, s))
Buggy python submission (verdict: Runtime Error):
def solve(n, a):
    res = 0
    for i in range(n-1):
        b = min(a[i], a[i+1])
        res += b
        a[i] -= b
        a[i+1] -= b
        if a[i] > 0:
            res += a[i] // 2
    if a[-1] > 0:
        res += a[i] // 2
    return res

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Fixed submission:
def solve(n, a):
    res, total = 0, 0
    for x in a:
        if x == 0:
            res += total // 2
            total = 0
        else:
            total += x
    return res + total // 2

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(s) for s in input().split()]

total=0

for i in range(n-1):
  for j in range(n-i-1):
    total=total+a[i]*a[i+j+1]%1000000007
    
print(total% 1000000007)


Fixed submission:
n = int(input())
a = [int(s) for s in input().split()]
s=sum(a)

total=0

for i in range(n-1):
  s=s-a[i]
  total=total+a[i]*s%1000000007
  
print(total%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(s) for s in input().split()]

total=0

for i in range(n-1):
  for j in range(n-i-1):
    total=total+a[i]*a[i+j+1]%1000000007
    total=total % 1000000007
    
print(total)


Fixed submission:
n = int(input())
a = [int(s) for s in input().split()]
s=sum(a)

total=0

for i in range(n-1):
  s=s-a[i]
  total=total+a[i]*s%1000000007
  
print(total%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
x, k, d = map(int, input().split())

if x>0:
  f=True
else:
  f=False
  
for i in range(k):
  if x > 0:
    if f==False and (k-i)%2==0:
      print(abs(x))
      exit()
    x -= d
    f=True
  else:
    if f==True and (k-i)%2==0:
      print(abs(x))
      exit()
    x += d
    f=False
print(abs(x))

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

# k回　dだけ変化

n=abs(x)//d
if k>=n:
  k=k-n
else:
  n=k
  k=0
  
if k%2 == 0:
  x=abs(x)-d*n
else:
  x=abs(x)-d*(n+1)

print(abs(x))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = [0 for _ in range(N)]

num_m = (N-4)//2

for x in range(1, num_m):
    for y in range(1, num_m-x):
        for z in range(1, num_m-x-y):
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n <= N-1:
                ans[n-1] += 1


print(*ans, sep="\n")

Fixed submission:
N = int(input())

ans = [0 for _ in range(N)]

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n <= N:
                ans[n-1] += 1


print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

N = int(input())
X = list(input())

for i in range(N):
    x = X.copy()
    cnt = 0
    x[i] = str(int(x[i])^1)
    n = int("".join(x), 2)

    while n>0:
        n = n%popcnt3(n)
        cnt += 1
    print(cnt)

Fixed submission:
#2回目以降のあまりを計算
def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

N = int(input())
S = input()

#入力を数値に変換
X = int(S, 2)

#元のbit数をカウント
pcx = S.count("1")
#bit数は-1, +1のみなので予め計算しておく
#カウントが0ならば0にしておく
pc1 = X % (pcx - 1) if pcx > 1 else 0
pc2 = X % (pcx + 1)

for i, y in enumerate(S):
    k = N - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
def popcnt3(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

N = int(input())
X = list(input())

for i in range(N):
    x = X.copy()
    cnt = 0
    x[i] = str(int(x[i])^1)
    n = int("".join(x), 2)

    while n>0:
        n = n%popcnt3(n)
        cnt += 1
    print(cnt)

Fixed submission:
#2回目以降のあまりを計算
def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

N = int(input())
S = input()

#入力を数値に変換
X = int(S, 2)

#元のbit数をカウント
pcx = S.count("1")
#bit数は-1, +1のみなので予め計算しておく
#カウントが0ならば0にしておく
pc1 = X % (pcx - 1) if pcx > 1 else 0
pc2 = X % (pcx + 1)

for i, y in enumerate(S):
    k = N - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
N = int(input())

ans = 0
for i in range(1, N+1):
    ans += len(make_divisors(i))*i
print(ans)

Fixed submission:
N = int(input())

ans = 0
for i in range(1, N+1):
    y = N//i
    
    ans += y*(y+1)*i//2



print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

dic = Counter(A)

Q = int(input())

for _ in range(Q):
    b, c = map(int, input().split())
    if b in dic.keys():
        ans = sumA+(dic[b]*(c-b))

        B = dic[b]
        if c in dic.keys():
            dic[c] += dic[b]
            del dic[b]
        else:
            dic[c] = dic[b]
            del dic[b]
        
        sumA += (dic[c]*c-B*b)
        
        # print(dic)
    print(ans)

Fixed submission:
from collections import Counter

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

dic = Counter(A)

Q = int(input())

for _ in range(Q):
    b, c = map(int, input().split())
    if b in dic.keys():
        sumA += ((c-b)*dic[b])

        #変更後の数字は既にいる？
        if c in dic.keys():
            #個数を保持
            #bの個数をcに追加し、bを削除
            dic[c] += dic[b]
            del dic[b]
        else:
            dic[c] = dic[b]
            del dic[b]
        # print("C", C)
        
        
        
        # print(dic)
    # else:
    #     ans = sumA
    print(sumA)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int, input().split())))
n = 10**6+1

dp = [0 for _ in range(max(A)+1)]

for i in A:
    dp[i] += 1
    if dp[i]==1:
        for j in range(i*2, max(A)+1, i):
            dp[j] += 2
    # print(dp)
print(dp.count(1))

Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))

m_a = max(A)+1
dp = [0]*m_a

for i in A:
    dp[i] += 1
    if dp[i]==1:
        for j in range(i*2, m_a, i):
            dp[j] += 2
    # print(dp)
print(dp.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted(list(map(int, input().split())))
n = 10**6+1

dp = [0 for _ in range(max(A)+1)]

for i in A:
    dp[i] += 1
    if dp[i]==1:
        for j in range(i*2, max(A)+1, i):
            dp[j] = 2
    # print(dp)
print(dp.count(1))

Fixed submission:
N = int(input())
A = sorted(list(map(int, input().split())))

m_a = max(A)+1
dp = [0]*m_a

for i in A:
    dp[i] += 1
    if dp[i]==1:
        for j in range(i*2, m_a, i):
            dp[j] += 2
    # print(dp)
print(dp.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

def imos(A):
    B = np.zeros_like(A)
    for i,x in enumerate(A):
        a = max(0, i-x)
        b= min(i+x, N-1)
        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)

Fixed submission:
import numpy as np
from numba import njit

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

@njit
def imos(A):
    B = np.zeros(N, dtype=np.int64)
    for i,x in enumerate(A):
        a = max(0, i-x)
        b = min(i+x, N-1)
        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)

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

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

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

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

Fixed submission:
import numpy as np
from numba import njit

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

@njit
def imos(A):
    B = np.zeros(N, dtype=np.int64)
    for i,x in enumerate(A):
        a = max(0, i-x)
        b = min(i+x, N-1)
        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)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

ans = 1
for i in a:
    ans *= i

if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

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

ans = 1
if 0 in a:
    print(0)
else:
    for i in a:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            exit()

    print(ans)
Buggy python submission (verdict: Runtime Error):
A, B =int(input()), float(input())
print(int(A*B))

Fixed submission:
from decimal import *

A, B = input().split()
print(int(Decimal(A)*Decimal(B)))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

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

ord = [-1 for _ in range(N+1)]
v = 1
root = []

while ord[v] == -1:
    #ordに何回目のワープかが記録される
    ord[v] = len(root)
    #ワープの軌跡を記録
    root.append(v)
    #次の地点にワープ
    v = A[v-1]

# print("len(root)", len(root))
# print("ord[v]", ord[v])
# print("ord", ord)
# print("root", root)

#ord[v]:最終地点（ループ起点 or ループ前の道のり）
l = ord[v]
#ループ距離
c = len(root) - l

if K < l:
    #ループ前にワープが終了した場合、最終地点を出力
    ans = root[K]
else:
    #ループする回数を計算
    K -= l
    K %= c
    res = root[l+K]
print(res)



Fixed submission:
N, K = map(int, input().split())

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

ord = [-1 for _ in range(N)]
ord[0] = 0
v = A[0]-1
root = [0]

while ord[v] == -1:
    #ordに何回目のワープかが記録される
    ord[v] = len(root)
        #ワープの軌跡を記録
    root.append(v)

    #次の地点にワープ5
    v = A[v]-1

# print(ord)
# print(root)

#ord[v]:最終地点（ループ起点 or ループ前の道のり）
# ループ起点までの余分な手
l = ord[v]
#ループ距離
c = len(root) - l

if K < l:
    #ループ前にワープが終了した場合、最終地点を出力
    ans = root[K]
else:
    #ループする回数を計算
    # はじめにループ起点までの余分手をKから引く
    K -= l
    # ループのmodを計算
    K %= c
    # 余分手＋ループのmodの位置の国に止まる
    ans = root[l+K]
print(ans+1)