Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p04031 (python)

Fixed submission:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)+1):
        cost = 0
        for j in a:
            if i != j:
                cost += (i - j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    listcost = []
  
    for i in range(min(a),max(a)):
        cost = 0
        for j in a:
            if i != j:
                cost += (i-j) ** 2
        listcost.append(cost)
    print(min(listcost))
  
  
if __name__=='__main__':
  main()
Problem p02817 (python)

Fixed submission:
S, T = input().strip().split()
print(T+S)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
print(T+S)
Problem p03240 (python)

Fixed submission:
N = int(input().strip())
xyh = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    xyh.append((xi, yi, hi))

xyh.sort(key = lambda t: t[2], reverse = True)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                Hi = xyh[i][2] + abs(xyh[i][0]-Cx) + abs(xyh[i][1]-Cy)
                if H == -1:
                    H = Hi

                if xyh[i][2] == 0:
                    if H > Hi:
                        break
                elif H != Hi:
                    break

                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
x = []
y = []
h = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    x.append(xi)
    y.append(yi)
    h.append(hi)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                Hi = h[i] + abs(x[i]-Cx) + abs(y[i]-Cy)
                if H == -1:
                    H = Hi

                if h[i] == 0:
                    if H < Hi:
                        break
                elif H != Hi:
                    break

                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
x = []
y = []
h = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    x.append(xi)
    y.append(yi)
    h.append(hi)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                Hi = h[i] + abs(x[i]-Cx) + abs(y[i]-Cy)
                if H == -1:
                    H = Hi

                if h[i] == 0:
                    if H > Hi:
                        break
                elif H != Hi:
                    break

                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
x = []
y = []
h = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    x.append(xi)
    y.append(yi)
    h.append(hi)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                if h[i] == 0:
                    continue
                Hi = h[i] + abs(x[i]-Cx) + abs(y[i]-Cy)
                if H == -1:
                    H = Hi
                if H != Hi:
                    break
                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())
Problem p02584 (python)

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

a = [abs(x // d), x % d]

if a[0] > k:
   ans = min(abs(x+k*d) ,abs(x-k*d))
else:
    b = (k- a[0]) % 2
    ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))

print(ans)

Buggy submission (verdict: Runtime Error):
x, k, d = map(int, input().split())

a = [abs(x // d), x % d]

if a[0] > k:
   ans = min(abs(x+k*d) ,abs(x-k*d))
else:
    b = (k- a[0]) % 2
    ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))

print(ans))
Problem p02684 (python)

Fixed submission:
#N,K入力
N,K= map(int,input().split())
#街のテレポート先入力
A = [int(i)-1 for i in input().split()]
judge = [-1] * N
judge[0] = 0
#初期位置
a = 0
#移動回数
step = 1

while step != K +1:
    #移動する街を決める
    a = A[a]
    if judge[a] > -1:
        break
    #何回目の移動なのか加える
    judge[a] = step
    step = step + 1

if step == K +1:
    print(a+1)
    # プログラム終了
else:
    width = step - judge[a]
    s =(K - judge[a]) % width
    print(judge.index(judge[a]+s)+1)

Buggy submission (verdict: Runtime Error):
#N,K入力
N,K= map(int,input().split())
#街の番号入力
A = [int(i) for i in input().split()]

# 重複した要素があるかどうかを判定
def has_duplicates(seq):
    return len(seq) == len(set(seq))

#移動経路
warp = [1]
a = 1

#同じ街にたどり着くまでループ
while has_duplicates(warp):
    a = A [a - 1]
    warp.append(a)
    #同じ街にたどり着かなかった場合はこっち
    if len(warp) == K +1:
        print(warp[K])
        break

l = [i for i, x in enumerate(warp) if x == a]

# 何回ワープしたらループする街に戻ってくるか
width = l[1] - l[0]

#　ループのどこに行くか
d = (K - l[0]) % (l[1]-l[0])

#結果の出力
print(A[d + l[0]])

Buggy submission (verdict: Runtime Error):
#N,K入力
N,K= map(int,input().split())
#街の番号入力
A = [int(i) for i in input().split()]

# 重複した要素があるかどうかを判定
def has_duplicates(seq):
    return len(seq) == len(set(seq))

#移動経路
warp = [1]
a = 1

#同じ街にたどり着くまでループ
while has_duplicates(warp):
    a = A [a - 1]
    warp.append(a)
    #同じ街にたどり着かなかった場合はこっち
    if len(warp) == K +1:
        print(warp[K])
        break

l = [i for i, x in enumerate(warp) if x == a]

# 何回ワープしたらループする街に戻ってくるか
width = l[1] - l[0]

#　ループのどこに行くか
d = (K - l[0]) % (l[1]-l[0])

#結果の出力
print(d + l[0])
Problem p02995 (python)

Fixed submission:
import sys
import fractions
input = sys.stdin.readline
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)


A, B, C, D = map(int, input().split())
lcm=lcm(C,D)
ans = B-A+1 - (B//C-(A-1)//C) - (B//D-(A-1)//D) + (B//(lcm)-(A-1)//(lcm)) 


print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline
def lcm(x, y):
  return (x * y) // math.gcd(x, y)


A, B, C, D = map(int, input().split())
lcm=lcm(C,D)
ans = B-A+1 - (B//C-A//C) - (B//D-A//D) + (B//(lcm)-A//(lcm)) 


print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


A, B, C, D = map(int, input().split())
lcm=lcm(C,D)
ans = B-A+1 - (B//C-A//C) - (B//D-A//D) + (B//(lcm)-A//(lcm)) 


print(ans)
Problem p03131 (python)

Fixed submission:
import math
K, A, B = map(int, input().split())
ans = K+1
if B > 2 + A:
  N = K - A
  if N == 1:
    ans = B
  elif N%2==1:
    ans=B+(B-A)*math.floor((K-A)/2)
  elif N%2==0:
    ans=B+(B-A)*math.floor((K-A)/2-1)+1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
K, A, B = map(int, input.split())
ans = K+1
if B > 2 + A:
  N = K - A
  if N == 1:
    ans = B
  elif N%2==1:
    ans=B+(B-A)*math.floor((K-A)/2)
  elif N%2==0:
    ans=B+(B-A)*math.floor((K-A)/2-1)+1

print(ans)
Problem p03177 (python)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline

MOD=10**9+7
N, K = map(int, input().split())
grid = np.empty((0,N), dtype='O')
for i in range(N):
  array = list(map(int, input().strip().split()))
  array2 = np.array(array)
  grid = np.append(grid,[array2],axis=0)
#print(grid)
dp=[[grid]]
gridsave=np.eye(N,dtype="O")
#print(gridsave)
i=1
while K:
  if K & 1:
    gridsave=np.dot(grid,gridsave) % MOD
  grid=np.dot(grid,grid) % MOD
  K>>=1
ans=np.sum(gridsave)%MOD
#print(gridsave)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
input = sys.stdin.readline

MOD=10**9+7
N, K = map(int, input().split())
grid = np.empty((0,N), dtype=Object)
for i in range(N):
  array = list(map(int, input().strip().split()))
  array2 = np.array(array)
  grid = np.append(grid,[array2],axis=0)
#print(grid)
dp=[[grid]]
gridsave=grid
i=1
while 2**i<=K:
  #print(i)
  #dp.insert(1,grid*grid)
  gridsave=np.dot(dp[i-1][0],dp[i-1][0])
  gridsave=np.mod(gridsave,MOD)
  #print(gridsave)
  dp.append([gridsave])
  i+=1
i-=1
K-=2**i
i-=1
#print('dp',dp)
grid1=dp[len(dp)-1][0]
#print(grid1)
#print(i)
while K>0:
  if K>=2**i:
    #print('i',i)
    grid1=np.dot(grid1,dp[i][0])
    grid1=np.mod(grid1,MOD)
    K-=2**i
    #print('grid1',grid1)
  i-=1
  #print('K',K)
ans=0
#print(grid1)
for i in range(N):
  for j in range(N):
    ans=(ans+grid1[i][j])%MOD
print(ans)
Problem p02582 (python)

Fixed submission:
day = input()
resMax = 0
resTemp = 0
for i in range(len(day)):
  if day[i]=='S':
    resTemp=0
  elif day[i]=='R':
    resTemp=0
    while (i<len(day)) and (day[i]!='S'):
      resTemp+=1
      i+=1
    if resTemp>resMax:
      resMax=resTemp
print(resMax)

Buggy submission (verdict: Runtime Error):
day=input()
resMax=0
resTemp=0
for i in range(len(day)):
  if day[i]=='S':
    resTemp=0
  elif day[i]=='R':
    while(day[i]!='S'):
      resTemp+=1
      i+=1
  if resMax<resTemp:
    resMax=resTemp
print(resMax)
Problem p02583 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
res=0
if n<=2:
	print(0)
else:
	for i in range(n):
		for j in range(i,n):
			for k in range(j,n):
				if (l[i]!=l[j]) and (l[j]!=l[k]) and (l[i]!=l[k]) and (l[i]+l[j]>l[k]) and (l[j]+l[k]>l[i]) and (l[k]+l[i]>l[j]):
					#print(l[i],l[j],l[k])
					res+=1
	print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
if n<=2:
	print(0)
else:
	for i in range(n):
		for j in range(i,n):
			for k in range(j,n):
				if (l[i]!=l[j]) and (l[j]!=l[k]) and (l[i]+l[j]>l[k]) and (l[j]+l[k]>l[i]) and (l[k]+l[i]>l[j]):
					res+=1
	print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
res=0
if n<=2 :
  print(0)
else:
	for i in range(n):
  		for j in range(i,n):
    		for k in range(j,n):
      			if l[i]!=l[j] and l[j]!=l[k] and (l[i]+l[j]>l[k]) and (l[i]+l[k]>l[j]) and (l[j]+l[k]>l[i]):
        		res+=1
print(res)
Problem p02582 (python)

Fixed submission:
S = input()
s_num = len(S)

i=0
max_count = 0
count = 0

while i < s_num:
    if S[i] != "R":
        if max_count < count:
            max_count = count
            count = 0
    elif S[i] == "R":
        count += 1

    i+=1

if max_count < count:
    max_count = count

print(max_count)

Buggy submission (verdict: Runtime Error):
X, K, D = (int(x) for x in input().split())
X = abs(X)

straight = min(K, X // D)
K -= straight
X -= straight * D

if K % 2 == 0:
    print(X)
else:
    print(D-X)
Problem p02582 (python)

Fixed submission:
S = input()
if ("RRR" in S):
  print(3)
elif ("RR" in S):
  print(2)
elif ("R" in S):
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
if ("RRR" in S):
  print(3)
elif ("RR" in S):
  print(2)
elif ("R" in S):
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
S = input()
if ("RRR" in S):
  return 3
elif ("RR" in S):
  return 2
elif ("R" in S):
  return 1
else:
  return 0

Buggy submission (verdict: Runtime Error):
if ("RRR" in S):
  return 3
elif ("RR" in S):
  return 2
elif ("R" in S):
  return 1
else:
  return 0
Problem p02583 (python)

Fixed submission:
import itertools

N = int(input())
L = list(map(int,input().split()))
 
l_list = list(itertools.combinations(L, 3))

res = 0
 
for tri in l_list:
  l = list(tri)
  l.sort()
  if (len(l) != len(set(l))):
    continue
  if (l[0] + l[1] > l[2]):
  	res += 1
    
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))

l_list = list(itertools.combinations(L, 3))

res = 0

for tri in l_list:
  tri.sort()
  if tri[0] + tri[1] > tri[2]
  	res += 1
    
print(res)
Problem p03125 (python)

Fixed submission:
l =input().split()

A = int(l[0])
B = int(l[1])

if B%A == 0:
    print(A+B)
else:
    print(B-A)

Buggy submission (verdict: Runtime Error):
l =input().split()

l[0] = A
l[1] = B
if B%A == 0:
    print(A+B)
else:
    print(B-A)
Problem p02582 (python)

Fixed submission:
r,s=0,input()
for l in s:
  if l=='S' and r>0:
    break
  r+=1 if l=='R' else 0
print(r)

Buggy submission (verdict: Runtime Error):
r=0
for l in input():
  r+=1 if l='R' else 0
print(r)
Problem p02584 (python)

Fixed submission:
x,k,d = [int(i) for i in input().split()]
x=abs(x)
x=x-k*d if x>=k*d else abs(x%d-(k-x//d)%2*d)
print(x)

Buggy submission (verdict: Runtime Error):
x,k,d = [int(i) for i in input().split()]
x=x-k*d*x//abs(x) if abs(x)>=k*d else x-(abs(x)//d)*d*x//abs(x)-(d if abs(x)//d%2==1 else 0)*x//abs(x)
print(x)

Buggy submission (verdict: Runtime Error):
x,k,d = [int(i) for i in input().split()]
for i in range(k):
  x+=d if x<0 else -d
  if abs(x)<d:
    x=(abs(x)-d)*x/abs(x) if (k-1-i)&1==1 else x
    break
print(x)
Problem p03423 (python)

Fixed submission:
print(str(int(input())//3))

Buggy submission (verdict: Runtime Error):
n=input()
print(str(n//3))
Problem p02621 (python)

Fixed submission:
a=int(input())

print(a+a**2+a**3)

Buggy submission (verdict: Runtime Error):
S=input()
T=input()

count=0
for i in range(len(S)):
  if S[i]!=T[i]:
    count+=1
    
print(count)
Problem p02641 (python)

Fixed submission:
X, N =map(int, input().split())
p_list=list(map(int, input().split()))
#i=N
#1st Xがp_listにあるか
	#あれば+=!
	#なければ答え
#|X-i|=1がp_listにあるか
	#あれば+=!
	#なければ答え

i=N
j=0
while True:
	if X-j not in p_list:
		print(X-j)
		exit()
	elif X+j not in p_list:
		print(X+j)
		exit()
	else:
		j+=1

Buggy submission (verdict: Runtime Error):
N=int(input())
ans=""
check="abcdefghijklmnopqrstuvwxyz"

while N!=0:
	N-=1
	ans+=check[N%26]
	N=N//26

print(ans[::-1])
"""
while N>0:
	N-=1
	ans+=chr(ord("a")+ N%26)
	N//=26
print(ans[::-1])
"""
Problem p02719 (python)

Fixed submission:
N, K =map(int, input().split())
ans=N%K
print(min(ans, K-ans))

Buggy submission (verdict: Runtime Error):
N, K =map(int, input().split())
import math
lcm=math.lcm(N,K)
ans=min(lcm, K-lcm)

Buggy submission (verdict: Runtime Error):
N, K =map(int, input().split())
import math
gcd=math.gcd(N,K)
ans=min(gcd, K-gcd)

Buggy submission (verdict: Runtime Error):
N, K =map(int, input().split())
import math
print(math.gcd(N,K))
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
from collections import defaultdict, Counter
dd=defaultdict(int)
dd_count=defaultdict(int)
Flag=False #s=1 and c=0となる値があるかどうか
for _ in range(M):
	s, c = map(int, input().split())

	if N>=2 and s==1 and c==0:
		Flag=True

	#異なるものが2個以上ある
	if dd_count[s-1]>=1 and dd[s-1]!=c:
		exit(print(-1))
	else:
		dd[s-1]=c
		dd_count[s-1]+=1
	
if N>=2 and dd[0]==0 and not Flag:
	ans=10**(N-1)
	for i in range(1,N):
		ans+=dd[i]*10**(N-i-1)
	exit(print(ans))

if N>=2 and Flag:
	exit(print(-1))
else:
	ans=0
	for i in range(N):
		ans+=dd[i]*10**(N-i-1)
	print(int(ans))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
from collections import defaultdict, Counter
dd=defaultdict(int)
dd_count=defaultdict(int)
Flag=False #s=1 and c=0となる値があるかどうか
for _ in range(M):
	s, c = map(int, input().split())

	if N>=2 and s==1 and c==0:
		Flag=Trye

	#異なるものが2個以上ある
	if dd_count[s-1]>=1 and dd[s-1]!=c:
		exit(print(-1))
	else:
		dd[s-1]=c
		dd_count[s-1]+=1
	
if N>=2 and not Flag:
	ans=10**(N-1)
	for i in range(1,N):
		ans+=dd[i]*10**(N-i-1)
	print(int(ans))

elif N>=2 and dd[0]==0:
	exit(print(-1))
else:
	ans=0
	for i in range(N):
		ans+=dd[i]*10**(N-i-1)
	print(int(ans))
Problem p02767 (python)

Fixed submission:
N=int(input())
X=list(map(int, input().split()))
import numpy as np
p=np.floor(np.mean(X))
ans=min(np.sum([(x-p)**2 for x in X]), np.sum([(x-(p+1))**2 for x in X]))

print(int(ans))

Buggy submission (verdict: Runtime Error):
N=int(input())
X=list(map(int, input().split()))
import numpy as np
p=np.floor(np.mean(X))
ans=min(np.sum([(x-p)**2 for x in X]), np.sum([(x-(p+1))**2 for x in X]))

print(int(ans))
Problem p02837 (python)

Fixed submission:
N=int(input())
XY=[[] for _ in range(N)]
for i in range(N):
  A=int(input())
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY[i].append([x,y])

ans=0
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state).count("1"))
    
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
XY=[[]*N]
for i in range(N):
  A=int(input())
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY[i].append([x,y])


ans=0
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state).count("1"))
    
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
XY=[]
for i in range(N):
  A=int(input())
  XY_i=[]
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY_i.append([x,y])
  XY.append(XY_i)

ans=0
for bit_state in range(1<<N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state>>x).count("1"))
    
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
XY=[]
for i in range(N):
  A=int(input())
  XY_i=[]
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY_i.append([x,y])
  XY.append(XY_i)

ans=0
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state>>x).count("1"))
    
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
XY=[[] for _ in range(N)]
for i in range(N):
  A=int(input())
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY[i].append([x,y])

ans=0
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state>>x).count("1"))
    
print(ans)
Problem p02861 (python)

Fixed submission:
import numpy as np
import  itertools
N=int(input())
XY=[]
for _ in range(N):
  x, y = map(int, input().split())
  XY.append([x,y])

D=np.zeros((N, N))
for i in range(N-1):
  xi, yi=XY[i][0], XY[i][1]
  for j in range(i+1, N):
    xj, yj=XY[j][0], XY[j][1]
    distance=np.sqrt((xi-xj)**2 + (yi-yj)**2)
    D[i][j]=distance
    D[j][i]=distance

ans=0
for l in itertools.permutations(range(N)):
  dis=0
  for i in range(N-1):
    dis+=D[l[i]][l[i+1]]
  ans+=dis
print(ans/np.math.factorial(N))

Buggy submission (verdict: Runtime Error):
import numpy as np
import  itertools
N=int(input())
XY=[]
for _ in range(N):
  x, y = map(int, input().split())
  XY.append([x,y])

D=np.zeros((N, N))
for i in range(N-1):
  xi, yi=XY[i][0], XY[i][1]
  for j in range(i+1, N):
    xj, yj=XY[j][0], XY[j][1]
    distance=np.sqrt((xi-xj)**2 + (yi-yj)**2)
    D[i][j]=distance
    D[j][i]=distance

ans=0
for l in itertools.permutations(range(N)):
  dis=0
  for i in range(N-1):
    dis+=D[l[i]][l[i+1]]
  ans+=dis
print(ans/np.math.factorial(N))
Problem p03044 (python)

Fixed submission:
from collections import deque
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
	u, v, w = map(int, input().split())
	u,v=u-1,v-1
	G[u].append([v,w])
	G[v].append([u,w])
#print(G) #[[[1, 2]], [[0, 2], [2, 1]], [[1, 1]]]
color=[-1]*N
que=deque([0])
color[0]=0

while que:#dfs
	p=que.popleft()#直近で追加したグラフの頂点を取得
	for q, W in G[p]:#結合しているグラフの頂点を参照
		if color[q]==-1:#塗られていないなら
			color[q]=(color[p]+W)%2
			que.append(q)
print(*color, sep="\n")

Buggy submission (verdict: Runtime Error):
from collections import deque
N=int(input())
G=[[] for _ in range(N)]
G2=[[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  u-=1
  v-=1
  G[u].append([v, w])
  G[v].append([u, w])

color=[-1]*N
que=deque([0])
color[0]=0

while que:
  x=que.popleft()
  for y, W in G[x]:
    if color[y]==-1:
      color[y]=(color[x]+1)%2
      que.append([y])
print(*color, sep="\n")
Problem p03061 (python)

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

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N
 
for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])
  
ans = 0
 
for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)

Buggy submission (verdict: Runtime Error):
#これだとTLEする
from fractions import gcd
ans=0
for i in range(N):
	temp=0
	for idx, a in enumerate(A):
		if idx==i:
			continue
		temp=gcd(temp, a)
	ans=max(ans,temp)
print(ans)
Problem p03086 (python)

Fixed submission:
s=input()
temp=0
ans=0
tar="ACGT"
for ch in s:
  if ch in tar:
    temp+=1
  else:
    ans=max(ans, temp)
    temp=0

print(max(ans,temp))

Buggy submission (verdict: Runtime Error):
s=input()
temp=0
ans=0
tar="ACGT"
for ch in s:
  if ch in tar:
    temp+=1
  else:
    if ans=<temp:
      ans=temp
    temp=0

print(ans)
Problem p03161 (python)

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

dp=[float("inf")]*N
dp[0]=0

for i in range(1, N):
	if i==1:
		dp[i]=min(dp[i], abs(h[i]-h[i-1]))
	else:
		start=max(0, i-K)
		dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(start, i))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H=list(map(int, input().split() for _ in range(N)))

import numpy as np
dp=np.full(N+K, 1e+14, dtype=np.int64)
dp[0]=0
for i in range(1, N):
  dp[i:i+K]=np.minimum(dp[i:i+K], np.abs(H[i-1]-H[i:i+K])+dp[i-1])

print(dp[N - 1])  # 0-indexedに変換しておく
Problem p03163 (python)

Fixed submission:
N, W = map(int, input().split())
weight, value = [0]*N, [0]*N
for i in range(N):
	weight[i], value[i] = map(int, input().split())


dp=[[0]*(W+1) for _ in range(N+1)]
#初期条件
#dp[0]=0
for i in range(N):
	for w in range(W+1):
		if w>=weight[i]:
			dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
		else:
			dp[i+1][w]=dp[i][w]
print(dp[-1][-1])


"""
def solveDP(N, W, value, weight):
    dp = np.zeros((N+1, W+1))
    
    for i in range(N):
        for w in range(W+1):
            if w >= weight[i]:
                dp[i + 1, w] = max(dp[i, w - weight[i]] + value[i], dp[i, w])
            else:
                dp[i + 1, w] = dp[i, w]
    
    return dp[N , W]




import numpy as np
N,W = map(int,input().split())
 
dp=np.zeros(W-1, dtype=np.int64)
for _ in range(N):
	w, v = map(int, input().split())



for _ in range(N):
    w,v = map(int,input().split())
    np.maximum(dp[w:], dp[:-w] + v, out = dp[w:])
 
answer = dp.max()
print(answer)
"""

Buggy submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

dp=np.zeros((N+1, W+1), dtype=np.int64)

for i in range(1,N+1):
    w, v =list(map(int, input().split()))
     dp[i]=dp[i-1]
     dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v, dp[i-1][w:])
print(np.max(dp))
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
w=[]
v=[]
for i in range(N):
	a, b = map(int, input().split())
	w.append(a)
	v.append(b)
#dp[i+1][j] := i番目までの品物から総和がjとなるように選んだ時の重さの総和の最小値
dp=[[float("inf")]*(max(v)*N+1) for _ in range(N+1)]
#初期条件
dp[0][0]=0
for i in range(N):
	for j in range(max(v)*N+1):
		if v[i]>j:
			dp[i+1][j] = dp[i][j]
		else:
			dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])

ans=0
for j in range(max(v)*N+1):
	if dp[N][j]<=W:
		ans=j
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

dp=np.zeros((N+1, W+1), dtype=np.int64)

for i in range(1, N+1):
	w, v = list(map(int, input().split()))
	dp[i]=dp[i-1]
	dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v, dp[i-1][w:])
print(np.max(dp))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, W = map(int, input().split())

dp=np.zeros((N+1, W+1), dtype=np.int64)

for i in range(1, N+1):
	w, v = map(int, input().split())
	dp[i]=dp[i-1]
	dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v, dp[i-1][w:])
print(np.max(dp))