Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

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

for i in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)

fe=[0 for i in range(n+1)]
que=[(1,0)]
visited=[0 for i in range(n+1)]
visited[1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    fe[now[0]]=now[1]
    for nex in L[now[0]]:
        if visited[nex]==0:
            visited[nex]=1
            que.append((nex,now[1]+1))
            
sn=[0 for i in range(n+1)]
que=[(n,0)]
visited=[0 for i in range(n+1)]
visited[-1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    sn[now[0]]=now[1]
    for nex in L[now[0]]:
        if visited[nex]==0:
            visited[nex]=1
            que.append((nex,now[1]+1))

kaname=[]
for i in range(1,n+1):
    ck=fe[i]-sn[i]
    if ck==1 or ck==2:
        kaname.append(i)

cnt=0
que=[(1,0)]
visited=[0 for i in range(n+1)]
visited[1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    cnt+=1
    for nex in L[now[0]]:
        if visited[nex]==0 and not nex in kaname:
            visited[nex]=1
            que.append((nex,now[1]+1))

if cnt*2>n:
    print("Fennec")
else:
    print("Snuke")

Fixed submission:
n=int(input())

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

for i in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)

fe=[0 for i in range(n+1)]
que=[(1,0)]
visited=[0 for i in range(n+1)]
visited[1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    fe[now[0]]=now[1]
    for nex in L[now[0]]:
        if visited[nex]==0:
            visited[nex]=1
            que.append((nex,now[1]+1))
            
sn=[0 for i in range(n+1)]
que=[(n,0)]
visited=[0 for i in range(n+1)]
visited[-1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    sn[now[0]]=now[1]
    for nex in L[now[0]]:
        if visited[nex]==0:
            visited[nex]=1
            que.append((nex,now[1]+1))

kaname=[]
for i in range(1,n+1):
    ck=fe[i]-sn[i]
    if ck==1 or ck==2:
        kaname.append(i)

cnt=0
que=[(1,0)]
visited=[0 for i in range(n+1)]
visited[1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    cnt+=1
    for nex in L[now[0]]:
        if visited[nex]==0 and not nex in kaname:
            visited[nex]=1
            que.append((nex,now[1]+1))

if cnt*2>n:
    print("Fennec")
else:
    print("Snuke")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p,q=1,1

for _ in range(n):
    t,a=map(int,input().split())
    n=1
    while p>n*t or q>n*a:
        n+=1
    p,q=n*t,n*a

print(p+q)

Fixed submission:
n=int(input())
p,q=1,1

for _ in range(n):
    t,a=map(int,input().split())
    #n=1
    #hile p>n*t or q>n*a:
    #    n+=1
    n=max((p+t-1)//t,(q+a-1)//a)
    p,q=n*t,n*a
    #print(n,p,q)

print(p+q)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<6:print(int(n>2));quit()
M=10**9+7
ln,hn,dp=n-6,n-5,2
s=n-4
n,d=n-5,1
while n:
  for i in range(3):n=(n*ln)%M;ln-=1
  for i in range(2):n=(n*pow(hn,-1,M))%M;hn-=1
  d=(d*pow(dp,-1,M))%M;dp+=1
  s=(s+n*d)%M
print(s)

Fixed submission:
n=int(input())
if n<7:print(n//3);quit()
M=10**9+7
ln,hn,dp=n-6,n-5,2
s=n-4
n,d=n-5,1
while n:
  for i in range(3):n=(n*ln)%M;ln-=1
  for i in range(2):n=(n*pow(hn,-1,M))%M;hn-=1
  d=(d*pow(dp,-1,M))%M;dp+=1
  s=(s+n*d)%M
print(s)

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<6:print(int(n>2));quit()
M=10**9+7
ln,hn,dp=n-6,n-5,2
s=0
n,d=n-5,1
while n:
  for i in range(3):n=(n*ln)%M;ln-=1
  for i in range(2):n=(n*pow(hn,-1,M))%M;hn-=1
  d=(d*pow(dp,-1,M))%M;dp+=1
  s=(s+n*d)%M
print(s)

Fixed submission:
n=int(input())
if n<7:print(n//3);quit()
M=10**9+7
ln,hn,dp=n-6,n-5,2
s=n-4
n,d=n-5,1
while n:
  for i in range(3):n=(n*ln)%M;ln-=1
  for i in range(2):n=(n*pow(hn,-1,M))%M;hn-=1
  d=(d*pow(dp,-1,M))%M;dp+=1
  s=(s+n*d)%M
print(s)

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<6:print(int(n>2));quit()
M=10**9+7
ln,hn,dp=n-6,n-5,2
s=0
n,d=n-5,1
while n:
  for i in range(3):n=(n*ln)%M;ln-=1
  for i in range(2):n=(n*pow(hn,-1,M))%M;hn-=1
  d=(d*pow(dp,-1,M))%M,dp+=1
  s=(s+n*d)%M
print(s)

Fixed submission:
n=int(input())
if n<7:print(n//3);quit()
M=10**9+7
ln,hn,dp=n-6,n-5,2
s=n-4
n,d=n-5,1
while n:
  for i in range(3):n=(n*ln)%M;ln-=1
  for i in range(2):n=(n*pow(hn,-1,M))%M;hn-=1
  d=(d*pow(dp,-1,M))%M;dp+=1
  s=(s+n*d)%M
print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  	if i % 2 == 0 and a[i] % 2 == 1:
      	ans += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i % 2 == 0 and a[i] % 2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


x, n = read_ints()
p = list(read_ints())
ans = -1
delta = 1000
for i in range(102):
    ok = True
    for j in p:
        if p == i:
            ok = False
            break
    if ok:
        d = abs(x - i)
        if d < delta:
            ans = i
print(ans)


Fixed submission:
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


x, n = read_ints()
p = []
if n > 0:
    p = list(read_ints())
ans = -1
delta = 1000
for i in range(-1, 102):
    ok = True
    for j in p:
        if j == i:
            ok = False
            break
    if ok:
        d = abs(x - i)
        if d < delta:
            ans = i
            delta = d
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n + 1):
	if i % 3 != 0 and i % 5 != 0:
    	ans += i
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n + 1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, M = map(int, input.split(' '))
a = list(map(int, input.split(' ')))
b = list(map(int, input.split(' ')))
asum = [0]
bsum = [0]
for i in a:
    asum.append(asum[-1] + i)
for i in b:
    bsum.append(bsum[-1] + i)
ans = int(1e18)
for i in range(M):
    x, y, c = map(int, input.split(' '))
    ans = min(ans, asum[x] + bsum[y] - c)
print(ans)

Fixed submission:
A, B, M = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split(' '))
    ans = min(ans, a[x - 1] + b[y - 1] - c)
print(ans)

Buggy python submission (verdict: Runtime Error):
A, B, M = map(int, input.split(' '))
a = list(map(int, input.split(' ')))
b = list(map(int, input.split(' ')))
asum = [0]
bsum = [0]
for i in a:
    asum.append(asum[-1] + i)
for i in b:
    bsum.append(bsum[-1] + i)
ans = int(1e18)
for i in range(M):
    x, y, c = map(int, input.split(' '))
    ans = min(ans, asum[x] + bsum[y] - c)
print(ans)

Fixed submission:
A, B, M = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split(' '))
    ans = min(ans, a[x - 1] + b[y - 1] - c)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class SCC:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
        self.graph_rev = [[] for _ in range(N)]
        self.flag = [False]*N

    def add_edge(self,start,end):
        if start == end:
            return
        self.graph[start].append(end)
        self.graph_rev[end].append(start)

    def dfs(self,node,graph):
        self.flag[node] = True
        for n in graph[node]:
            if self.flag[n]:
                continue
            self.dfs(n,graph)
        self.order.append(node)

    def first_dfs(self):
        self.flag = [False]*self.N
        self.order = []
        for i in range(self.N):
            if self.flag[i] == False:
                self.dfs(i,self.graph)

    def second_dfs(self):
        self.flag = [False]*self.N
        self.ans = []
        for n in reversed(self.order):
            if self.flag[n]:
                continue
            self.flag[n] = True
            self.order = []
            self.dfs(n,self.graph_rev)
            self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans


N,M = MI()
SCC = SCC(N)

for _ in range(M):
    a,b = MI()
    SCC.add_edge(a,b)

ANS = SCC.scc()

print(len(ANS))
for s in ANS:
    print(*([len(s)]+s))



Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class SCC:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
        self.graph_rev = [[] for _ in range(N)]
        self.flag = [False]*N

    def add_edge(self,start,end):
        if start == end:
            return
        self.graph[start].append(end)
        self.graph_rev[end].append(start)

    def dfs(self,node,graph):
        self.flag[node] = True
        for n in graph[node]:
            if self.flag[n]:
                continue
            self.dfs(n,graph)
        self.order.append(node)

    def first_dfs(self):
        self.flag = [False]*self.N
        self.order = []
        for i in range(self.N):
            if self.flag[i] == False:
                self.dfs(i,self.graph)

    def second_dfs(self):
        self.flag = [False]*self.N
        self.ans = []
        for n in reversed(self.order):
            if self.flag[n]:
                continue
            self.flag[n] = True
            self.order = []
            self.dfs(n,self.graph_rev)
            self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans


N,M = MI()
SCC = SCC(N)

for _ in range(M):
    a,b = MI()
    SCC.add_edge(a,b)

ANS = SCC.scc()

print(len(ANS))
for s in ANS:
    print(*([len(s)]+s))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()
B = []
for i in range(N):
    if A[i] != 0:
        B.append(A[i])
N = len(B)
P = 200003

d = {}
D = []
a = 1
for i in range(P-1):
    D.append(a)
    d[a] = i
    a *= 2
    a %= P

E = [0]*(P-1)
for i in range(P-1):
    if D[i]*2 > P:
        E[i] = 1

C = []
for i in range(N):
    C.append(d[B[i]])

c = len(C)
ANS = [0]*(P-1)
for i in range(c-1):
    for j in range(i+1,c):
        ANS[(C[i]+C[j]) % (P-1)] += 1

x = sum(D[i]*ANS[i] for i in range(P-1))
print(x)
# a = sum(B)
# b = sum(B[i]**2 for i in range(N))
# r = ((a**2-b)//2) % P

# print(P*x+r,C)

Fixed submission:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()
B = []
for i in range(N):
    if A[i] != 0:
        B.append(A[i])
N = len(B)
P = 200003

# 2はPの原始根

C = []  # C[i] = (2**i mod P)
d = {}  # d[n] = (2**i == n たるi)
a = 1
for i in range(P-1):
    C.append(a)
    d[a] = i
    a *= 2
    a %= P

D = [0]*(P-1)
for i in range(N):
    D[d[B[i]]] += 1

n = 2**((2*P-3).bit_length())
D += [0]*(n-(P-1))


from cmath import pi,exp

def dfs(f,start,step,N,inverse=False):
    if N == 2:
        a,b = f[start],f[start+step]
        return [a+b,a-b]
    if inverse is False:
        f0 = dfs(f,start,2*step,N//2,inverse=False)
        f1 = dfs(f,start+step,2*step,N//2,inverse=False)
        z = exp(2j*pi/N)
    else:
        f0 = dfs(f,start,2*step,N//2,inverse=True)
        f1 = dfs(f,start+step,2*step,N//2,inverse=True)
        z = exp(-2j*pi/N)
    z0 = 1.0
    for i in range(N//2):
        a,b = f0[i],f1[i]*z0
        f0[i],f1[i] = a+b,a-b
        z0 *= z
    return f0+f1

def DFT(f,N):  # fを離散フーリエ変換
    if N == 1:
        return f
    return dfs(f,0,1,N)

def iDFT(F,N):  # Fを離散フーリエ逆変換
    if N == 1:
        return F
    f = dfs(F,0,1,N,inverse=True)
    for i in range(N):
        f[i] /= N
    return f

# deg(f)+deg(g)<Nとなる2冪Nを選び、f,gの長さがNになるように0を埋めておく

def product(f,g,N):  # 多項式f,gの積
    F = DFT(f,N)
    G = DFT(g,N)
    FG = [F[i]*G[i] for i in range(N)]
    fg = iDFT(FG,N)
    for i in range(N):
        fg[i] = int(fg[i].real+0.5)
    return fg


E = product(D,D,n)
ans = 0
for i in range(P-1):
    ans += (C[i]*(E[i]+E[i+(P-1)]))

for i in range(N):
    ans -= (B[i]**2) % P

print(ans//2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]

M = D*26
dq = []
for i in range(1,D+1):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for i in range(M):
    d,q = dq[i]
    t0 = t[d]
    last2 = deepcopy(last)
    manzoku = s[d][q] - s[d][t0]
    for j in range(d,D+1):
        if j == d:
            last2[d][t0] = last2[d-1][t0]
            manzoku -= c[t0] * (d - last2[d][t0])
            last2[d][q] = d
            manzoku += c[q] * (d - last2[d-1][q])
        else:
            if last2[j][t0] == d:
                last2[j][t0] = last2[d-1][t0]
                manzoku -= c[t0] * (d - last2[d][t0])
            if last2[j][q] == last2[d-1][q]:
                last2[j][q] = d
                manzoku += c[q] * (d - last2[d-1][q])
    if manzoku > 0:
        t[d] = q
        last = last2

del t[0]

print(*t,sep='\n')

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for i in range(D)]

last = [0]*27

for i in range(1,D+1):
    r = 0
    manzokudo = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[k])
            else:
                continue
        if j == 1:
            r = 1
            manzokudo = m
        else:
            if manzokudo < m:
                manzokudo = m
                r = j
    print(r)
    last[r] = i
Buggy python submission (verdict: Runtime Error):
import sys

def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
mod = 10**9+7

a = M  # (M_P_N)**2
for i in range(1,N):
    a *= M-i
    a %= mod

# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
    r *= (N-i+1)*pow(i,-1,mod)*pow(M-i+1,-1,mod)*(-1)
    r %= mod
    ans += r
    ans %= mod

print(ans)

Fixed submission:
import sys

def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
mod = 10**9+7

a = M  # (M_P_N)**2
for i in range(1,N):
    a *= M-i
    a %= mod

# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
    r *= (N-i+1)*pow(i,-1,mod)*pow(M-i+1,-1,mod)*(-1)
    r %= mod
    ans += r
    ans %= mod

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

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
S = LI2()
s = len(S)
mod = 10**9+7

dp1 = [0]*(K+s)
dp2 = [0]*(K+s)

for i in range(K+s):
    if i == s-1:
        dp1[i] = pow(26,i,mod)-1
    elif i == s:
        dp2[i] = pow(26,i,mod)-1
    else:
        dp1[i] = dp1[i-1]*26+dp2[i-1]*25
        dp1[i] %= mod
        dp2[i] = dp2[i-1]*26 + dp1[i-1]*25
        dp2[i] %= mod



print((dp1[K+s-1]*26 + (dp2[K+s-1]-dp1[K+s-1])*25) % mod)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
n = len(LS2())
mod = 10**9+7

# 完成図は、
# (S[0]以外からなる文字列)S[0](S[1]以外からなる文字列)S[1]…(S[n-1]以外からなる文字列)S[n-1](任意の文字列)
# この表記は一意
# 形式的冪級数で考えると,
# 求めたいものは (1-25x)^(-n)*(1-26x)^(-1) の x^K の係数であり、
# これは、(i+n-1)_C_(n-1)*25^i*26^(K-i) を i=0,…,K にわたって足し合わせたものである

C = [1]
for i in range(1,K+1):
    C.append((C[-1]*(i+n-1)*pow(i,mod-2,mod)) % mod)
# C[i] = (i+n-1)_C_(n-1)

ans = 0
for i in range(K+1):
    ans += C[i]*pow(25,i,mod)*pow(26,K-i,mod)
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()
A = sorted(A)

B = [0]*(10**6+1)
C = [0]*(10**6+1)
for i in range(len(A)):
    if B[A[i]] == 0:
        C[A[i]] = 1
    for j in range(A[i]*2,10**6+1,A[i]):
        B[j] = 1

from collections import Counter

c = Counter(A)

for i in c.keys():
    if c[i] >= 2:
        C[i] = 0

print(sum(C))

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()
A = sorted(A)

if N == 1:
    print(1)
    exit()

if A[0] == 1:
    if N >= 2 and A[1] == 1:
        print(0)
        exit()
    else:
        print(1)
        exit()

B = [0]*(10**6+1)
C = [0]*(10**6+1)
for i in range(len(A)):
    if B[A[i]] == 0:
        C[A[i]] = 1
    for j in range(A[i]*2,10**6+1,A[i]):
        B[j] = 1

from collections import Counter

c = Counter(A)

for i in c.keys():
    if c[i] >= 2:
        C[i] = 0

print(sum(C))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = map(int,S().split())
A = LI()

from itertools import accumulate

ANS = A+[0]

for i in range(K):
    B = [0]*(N+1)
    for j in range(N):
        B[max(0,j-ANS[j])] += 1
        B[min(N,j+ANS[j]+1)] -= 1
    ANS = list(accumulate(B))

del ANS[N]
print(*ANS)

Fixed submission:
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,K = map(int,S().split())
A = LI()

from itertools import accumulate

ANS = A+[0]

for i in range(K):
    B = [0]*(N+1)
    for j in range(N):
        B[max(0,j-ANS[j])] += 1
        B[min(N,j+ANS[j]+1)] -= 1
    ANS = list(accumulate(B))
    for i in range(N):
        if ANS[i] != N:
            break
    else:
        break

del ANS[N]
print(*ANS)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,S = map(int,S().split())
A = [0] + LI()
mod = 998244353

from collections import defaultdict

dp = defaultdict(int)

# dp[i][j] = A_1からA_iまでを用いて和がj

for i in range(N+1):
    for j in range(S+1):
        if i == 0:
            dp[(i,0)] = 1
        else:
            if j >= A[i]:
                dp[(i,j)] = (dp[(i-1,j)]*2 + dp[(i-1,j-A[i])]) % mod
            else:
                dp[(i,j)] = dp[(i-1,j)]*2 % mod

print(dp[(N,S)])

Fixed submission:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,S = map(int,S().split())
A = [0] + LI()
mod = 998244353

dp = [[0]*(S+1) for _ in range(N+1)]

# dp[i][j] = {A_1,…,A_i}の部分集合の部分集合で、和がjとなるものの個数

for i in range(N+1):
    for j in range(S+1):
        if i == 0:
            dp[i][0] = 1
        else:
            if j >= A[i]:
                dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) % mod
            else:
                dp[i][j] = dp[i-1][j]*2 % mod

print(dp[N][S])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,S = map(int,S().split())
A = [0] + LI()
mod = 998244353

from collections import defaultdict

dp = defaultdict(int)

# dp[i][j] = A_1からA_iまでを用いて和がj

for i in range(N+1):
    for j in range(S+1):
        if i == 0:
            dp[(i,0)] = 1
        else:
            if j >= A[i]:
                dp[(i,j)] = (dp[(i-1,j)]*2 + dp[(i-1,j-A[i])]) % mod
            else:
                dp[(i,j)] = dp[(i-1,j)]*2 % mod

print(dp[(N,S)])

Fixed submission:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,S = map(int,S().split())
A = [0] + LI()
mod = 998244353

dp = [[0]*(S+1) for _ in range(N+1)]

# dp[i][j] = {A_1,…,A_i}の部分集合の部分集合で、和がjとなるものの個数

for i in range(N+1):
    for j in range(S+1):
        if i == 0:
            dp[i][0] = 1
        else:
            if j >= A[i]:
                dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) % mod
            else:
                dp[i][j] = dp[i-1][j]*2 % mod

print(dp[N][S])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

T = LS2()

for i in range(len(T)):
    if T[i] == '?':
        T[i] = 'D'

ans = ''
for i in range(len(T)):
    ans += T[i]

print(ans)

Fixed submission:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

T = LS2()

for i in range(len(T)):
    if T[i] == '?':
        T[i] = 'D'

ans = ''
for i in range(len(T)):
    ans += T[i]

print(ans)