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

Fixed submission:
from heapq import heappop, heapify, heappush


x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [-i for i in C]
A.sort(reverse=True)
B.sort(reverse=True)
AB = A[:x] + (B[:y])

heapify(AB)
heapify(D)
ans = 0
for _ in range(c):
    d = -heappop(D)
    ab = heappop(AB)
    if ab > d:
        heappush(AB, ab)
        break
    heappush(AB, d)
ans = sum(AB)
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heapify, heappush
import sys

input = sys.stdin.buffer.readline()

x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
AB = A[:x] + (B[:y])

heapify(AB)
heapify(C)
ans = 0
for _ in range(len(C)):
    c = heappop(C)
    ab = heappop(AB)
    if ab > c:
        heappush(AB, ab)
        break
    heappush(AB, c)
ans = sum(AB)
print(ans)
Problem p02768 (python)

Fixed submission:
n,a,b=map(int,input().split())
mod=10**9+7
bunbo=1
bunshi=1
for i in range(1,max(a+1, b+1)):
    bunbo*=i
    bunshi*=n-i+1
    bunshi%=mod
    bunbo%=mod
    if i==a:
        comba=bunshi*(pow(bunbo,mod-2,mod))
    if i==b:
        combb=bunshi*(pow(bunbo,mod-2,mod))
print((2**n-1-comba-combb)%mod)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
for i in range(n+4, -1, -1)
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
gyaku[n+3]=
for i in range(n+4, -1, -1)
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)
Problem p02782 (python)

Fixed submission:
a,p,b,q=map(int,input().split())

n=2*(10**6)+3
mod=10**9+7
kaidan=[1]*(n+1)
gyaku=[1]*(n+1)
for i in range(1,n+1):
    kaidan[i]=i*kaidan[i-1]%mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(n,r):
    if n-r>=0 and n>=0 and r>=0:
        return (kaidan[n]*gyaku[n-r]*gyaku[r])%mod
    else:
        return 0

def ans(a,b):
    return comb(a+b+2,a+1) -(a+b+2) 

print((ans(b,q)-ans(b,p-1)-ans(a-1,q)+ans(a-1,p-1))%mod)

Buggy submission (verdict: Runtime Error):
a,p,b,q=map(int,input().split())

n=2*(10**6)+1
mod=10**9+7
kaidan=[1]*(n+1)
gyaku=[1]*(n+1)
for i in range(1,n+1):
    kaidan[i]=i*kaidan[i-1]%mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(n,r):
    if n-r>=0 and n>=0 and r>=0:
        return (kaidan[n]*gyaku[n-r]*gyaku[r])%mod
    else:
        return 0

def ans(a,b):
    return comb(a+b+2,a+1) -(a+b+2) 

print((ans(b,q)-ans(b,p-1)-ans(a-1,q)+ans(a-1,p-1))%mod)
Problem p02787 (python)

Fixed submission:
import sys
input = sys.stdin.readline
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]
#i-1番目までの魔法で、j以上のだめを得与えるのに最低限必要な魔力
infi=10**12
dp=[[infi]*(h+1) for i in range(n+1)]
#shoki化
for i in range(n+1):
    dp[i][0]=0
for i in range(n):
    if AB[i][0]+1<h+1:
        for j in range(AB[i][0]+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
        for j in range(AB[i][0]+1, h+1):
            dp[i+1][j]=min(dp[i][j], dp[i+1][j-AB[i][0]]+AB[i][1])
    else:
        for j in range(h+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
print(dp[n][h])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]
#i-1番目までの魔法で、j以上のだめを得与えるのに最低限必要な魔力
infi=10**12
dp=[[infi]*(h+1) for i in range(n+1)]
#shoki化
for i in range(n+1):
    dp[i][0]=0
for i in range(n):
    if AB[i][0]+1<h+1:
        for j in range(AB[i][0]+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
        for j in range(AB[i][0]+1, h+1):
            dp[i+1][j]=min(dp[i][j], dp[i+1][j-AB[i][0]]+AB[i][1])
    else:
        for j in range(AB[i][0]+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
print(dp[n][h])
Problem p02788 (python)

Fixed submission:
from heapq import heappush, heappop

n, d, a = map(int, input().split())
actions = []
for _ in range(n):
    x, h = map(int, input().split())
    heappush(actions, (x, 0, (h + a - 1) // a))
cnt = 0
bomb = 0
current_bomb = 0
while cnt < n:
    a, c, b = heappop(actions)
    if c:
        current_bomb -= b
        continue
    else:
        HP = b
        if HP <= current_bomb:
            cnt += 1
            continue
        else:
            HP -= current_bomb
            cnt += 1
            current_bomb += HP
            bomb += HP
            heappush(actions, (a + 2 * d, 1, HP))
print(bomb)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,d,a=map(int,input().split())
flag=np.zeros(10**9+1)
XH=[list(map(int,input().split())) for _ in range(n)]
XH.sort(key=lambda A:A[0])
cnt=0
for i in range(n):
    kaisu=0
    x,h=XH[i]
    if flag[x]==0:
        kaisu=(h+a-1)//a
        flag[x:min((x+2*d+1),10**9+1)]+=kaisu*a
        cnt+=kaisu
    else:
        if flag[x]<h:
            h-=flag[x]
            kaisu=(h+a-1)//a
            flag[x:min((x+2*d+1),10**9+1)]+=kaisu*a
            cnt+=kaisu
print(int(cnt))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,d,a=map(int,input().split())
flag=np.zeros(10**9+1)
XH=[list(map(int,input().split())) for _ in range(n)]
XH.sort(key=lambda A:A[0])
cnt=0
for i in range(n):
    kaisu=0
    x,h=XH[i]
    if flag[x]==0:
        kaisu=(h+a-1)//a
        flag[x:min((x+2*d+1),10**9+1)]+=kaisu*a
        cnt+=kaisu
    else:
        if flag[x]<h:
            h-=flag[x]
            kaisu=(h+a-1)//a
            flag[x:min((x+2*d+1),10**9+1)]+=kaisu*a
            cnt+=kaisu
print(int(cnt))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,d,a=map(int,input().split())
flag=np.zeros(10**9+1)
XH=[list(map(int,input().split())) for _ in range(n)]
XH.sort(key=lambda A:A[0])
cnt=0
for i in range(n):
    kaisu=0
    x,h=XH[i]
    if flag[x]==0:
        kaisu=(h+a-1)//a
        flag[x:min((x+2*d+1),10**9+1)]+=kaisu*a
        cnt+=kaisu
    else:
        if flag[x]<h:
            h-=flag[x]
            kaisu=(h+a-1)//a
            flag[x:min((x+2*d+1),10**9+1)]+=kaisu*a
            cnt+=kaisu
print(cnt)
Problem p02797 (python)

Fixed submission:
#sになるのがちょうどk個
n,k,s=map(int,input().split())
ans=[0]*n
if s==10**9:
    ans = [s]*k +[10**9-1]*(n-k)
else:
    ans = [s]*k + [10**9]*(n-k)
print(*ans, sep=' ')

Buggy submission (verdict: Runtime Error):
#sになるのがちょうどk個
n,k,s=map(int,input().split())
ans=0
n_max=10**5
ans=[0]*n
moto=[]
detarame=10**5-1
if s<n:
    ans = [n]*k +[n+1]*(n-k)
    print(ans)
else:
    flag=0
    remain=s
    for i in range(n):
        moto.append(min(n_max,remain))
        if moto[-1]<n_max:
            flag=1
            break
        remain-=moto[-1]
    nagasa=len(moto)
    for i in range(nagasa+k-1):
        ans[i]=moto[i%nagasa]
    for i in range(nagasa+k-1,n):
        ans[i]=detarame
    print(ans)
Problem p02805 (python)

Fixed submission:
n = int(input())
XY = []
for i in range(n):
    x, y = map(int, input().split())
    XY.append((x, y))


# 外積、平行判定
def cross(a, b):
    return a.real * b.imag - b.real * a.imag


# 内積、直行判定
def dot(a, b):
    return a.real * b.real + a.imag * b.imag


# 外心の中心
def circumcenter(a, b, c):
    bunshi = (a - b) * dot(c, c) + (b - c) * dot(a, a) + (c - a) * dot(b, b)
    bunbo = (a - b) * c.conjugate() + (b - c) * a.conjugate() + (c - a) * b.conjugate()
    if bunbo == 0:
        return False, 0
    return True, bunshi / bunbo


kouho = []
for i in range(n - 1):
    a, b = XY[i]
    z1 = complex(a, b)
    for j in range(i + 1, n):
        c, d = XY[j]
        z2 = complex(c, d)
        kouho.append((z1 + z2) / 2)
if n >= 3:
    for i in range(n - 2):
        a, b = XY[i]
        z1 = complex(a, b)
        for j in range(i + 1, n - 1):
            c, d = XY[j]
            z2 = complex(c, d)
            for k in range(j + 1, n):
                e, f = XY[k]
                z3 = complex(e, f)
                flag, gaishin = circumcenter(z1, z2, z3)
                if flag:
                    kouho.append(gaishin)
ans = 10 ** 10
for z in kouho:
    temp = 0
    for i in range(n):
        x, y = XY[i]
        z1 = complex(x, y)
        temp = max(temp, abs(z - z1))
    ans = min(ans, temp)
print(ans)

Buggy submission (verdict: Runtime Error):
def distance(a,b,c,d):
    return ((c-a)**2+(d-b)**2)**(1/2)
def sankaku(a,b,c,d,e,f):
    S=1/2*abs((c-a)*(f-b)-(e-a)*(d-b))
    return (distance(a,b,c,d)*distance(c,d,e,f)*distance(e,f,a,b))/(4*S)
from itertools import combinations
n=int(input())
XY=[list(map(int,input().split()))for i in range(n)]
if n>=3:
    kumiawase=list(combinations(range(n),3))
    ans=0
    for tu in kumiawase:
        p,q = XY[tu[0]]
        r,s = XY[tu[1]]
        t,u = XY[tu[2]]
        ans=max(ans,sankaku(p,q,r,s,t,u))
    print(ans)
else:
    ans=distance(XY[0][0],XY[0][1],XY[1][0],XY[1][1])
    print(ans)

Buggy submission (verdict: Runtime Error):
def distance(a,b,c,d):
    return ((c-a)**2+(d-b)**2)**(1/2)
def sankaku(a,b,c,d,e,f):
    if ac+bd==0:
        return 1/2*distance(a,b,c,d)
    elif ce+df==0:
        return 1/2*distance(c,d,e,f)
    elif ea+bf==0:
        return 1/2 * distance(e,f,a,b)
    else:
        S=1/2*abs((c-a)*(f-b)-(e-a)*(d-b))
        return (2*S)/((distance(a,b,c,d)+distance(c,d,e,f)+distance(e,f,a,b)))
from itertools import combinations
n=int(input())
XY=[list(map(int,input().split()))for i in range(n)]
if n>=3:
    kumiawase=list(combinations(range(n),3))
    ans=0
    for tu in kumiawase:
        p,q = XY[tu[0]]
        r,s = XY[tu[1]]
        t,u = XY[tu[2]]
        ans=max(ans,sankaku(p,q,r,s,t,u))
    print(ans)
else:
    ans=distance(XY[0][0],XY[0][1],XY[1][0],XY[1][1])
    print(ans)
Problem p02818 (python)

Fixed submission:
a,b,k=map(int,input().split())
if k>=0 and k <=a:
  print(a-k,b)
elif k>a and k<=a+b:
  print(0, b-(k-a))
else:
  print(0,0)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
if k>=0 and k <=a:
  print(a-k,b)
elif k>a, k<=a+b:
  print(0, b-(k-a))
else:
  print(0,0)
Problem p02883 (python)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng=mid
    else:
        ok=mid

print(ok)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng
    else:
        right=center
temp=0
for i in range(n):
    a=center//F[i]
    if a>A[i]:
        continue
    else:
        temp+=A[i]-a
if temp<=k:
    ans=left
else:
    ans=right
print(ans)
Problem p02886 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(n):
    for j in range(i+1,n):
        ans.append(A[i]*A[j])
print(sum(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
  for j in range(i+1,n):
    ans.append(A[i]*A[j])
print(sum(ans))
Problem p02898 (python)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
    if A[i]>=k:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
  if A[i]>=K:
    c+=1
print(c)
Problem p02901 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n, m = map(int, input().split())
A = [0] * m
B = [0] * m
C = [[] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
    c = list(map(int, input().split()))
    C[i] = c
D = [0] * m
for i in range(m):
    d = 0
    for j in C[i]:
        d |= 1 << (j - 1)
    D[i] = d
# dp[i][s], i番目までの鍵を使ってSを作る最小コスト
infi = 10 ** 20
dp = [[infi for i in range(2 ** n + 1)] for _ in range(m + 1)]
dp[0][0] = 0
for i in range(m):
    for s in range(2 ** n):
        ni = i + 1
        ns = s
        # 使わないとき
        dp[ni][ns] = min(dp[i][s], dp[ni][ns])
        # 使うとき
        ns = s | D[i]
        dp[ni][ns] = min(dp[ni][ns], dp[i][s] + A[i])
ans = dp[m][2 ** n - 1]
print(ans if ans < infi else -1)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
A=[0]*m
B=[0]*m
C=[[] for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
    c=list(map(int,input().split()))
    C[i]=c
#dp[i][s], i番目までの鍵を使ってSを作る最小コスト
infi=10**20
dp=[[infi for i in range(2**(n)+1)]for _ in range(m+1)]
dp[0][0]=0
for i in range(m):
    for s in range(2**(n-1)):
        ni=i+1
        ns=s
        #使わないとき
        dp[ni][ns]=min(dp[i][s], dp[ni][ns])
        #使うとき
        for c in C[i]:
            ns = s | 1<<(c-1)
        dp[ni][ns]=min(dp[ni][ns], dp[i][s]+A[i])
ans=dp[n][2**n-1]
print(ans if ans<infi else -1)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
A=[0]*m
B=[0]*m
C=[[] for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
    c=list(map(int,input().split()))
    C[i]=c
#dp[i][s], i番目までの鍵を使ってSを作る最小コスト
infi=10**20
dp=[[infi for i in range(2**(n)+1)]for _ in range(n+1)]
dp[0][0]=0
for i in range(m):
    for s in range(2**(n-1)):
        ni=i+1
        ns=s
        #使わないとき
        dp[ni][ns]=min(dp[i][s], dp[ni][ns])
        #使うとき
        for c in C[i]:
            ns = s | 1<<(c-1)
        dp[ni][ns]=min(dp[ni][ns], dp[i][s]+A[i])
ans=dp[n][2**n-1]
print(ans if ans<infi else -1)
Problem p02917 (python)

Fixed submission:
n=int(input())
B=list(map(int,input().split()))
c=B[0]+B[-1]
if n>=3:
    for i in range(n-2):
        c+=min(B[i],B[i+1])
print(c)

Buggy submission (verdict: Runtime Error):
n=int(input())
B=map(list(int,input().split()))
c=A[0]+A[-1]
if n>=3:
	for i in range(n-2):
      c+=min(B[i],B[i+1])
print(c)
Problem p02973 (python)

Fixed submission:
from bisect import bisect_left, bisect_right
from collections import deque
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
infi = 10 ** 20

# 長さがi+1のときの最長部分増加列の末尾の最小値。
n, *A = map(int, read().split())
LIS = deque([10 ** 10])
for a in A:
    a *= -1
    pos1 = bisect_left(LIS, a)
    pos2 = bisect_right(LIS, a)
    if LIS[-1] <= a:
        LIS.append(a)
    else:
        if LIS[pos1] == a:
            LIS[pos2] = a
        else:
            LIS[pos1] = a

print(len(LIS))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

LIS = [1]
n, *A = map(int, read().split())

for a in A:
    a *= -1
    if LIS[-1] <= a:
        LIS.append(a)
    else:
        LIS[bisect_right(LIS, a)] = a
print(len(LIS))
Problem p02995 (python)

Fixed submission:
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-n//d-n//c+n//koubai
print(warikiri(b,c,d)-warikiri(a-1,c,d))

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)


def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-n//d-n//c+n//koubai)
print(warikiri(b,c,d)-warikiri(a-1,c,d))
Problem p02997 (python)

Fixed submission:
from itertools import combinations

n, k = map(int, input().split())
star = []
max_k = (n - 1) * (n - 2) // 2
delta = max_k - k
cnt = 0
if k <= max_k:
    ans = []
    for i in range(2, n + 1):
        star.append((1, i))
        cnt += 1

    if delta > 0:
        kumiawase = list(combinations(range(2, n+1), 2))
        for j in range(delta):
            kumi = kumiawase[j]
            star.append(kumi)
            cnt += 1
    print(cnt)
    for pair in star:
        print(*pair, sep=" ")
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from itertools import combinations

n, k = map(int, input().split())
star = []
max_k = (n - 1) * (n - 2) // 2
delta = max_k - k
cnt = 0
if k <= max_k:
    ans = []
    for i in range(2, n + 1):
        star.append((1, i))
        cnt += 1

    if delta > 0:
        kumiawase = list(combinations(range(2, n), 2))
        for j in range(delta):
            kumi = kumiawase[j]
            star.append(kumi)
            cnt += 1
    print(cnt)
    for pair in star:
        print(*pair, sep=" ")
else:
    print(-1)
Problem p03001 (python)

Fixed submission:
w,h,x,y=map(int,input().split())
square = w*h/2
if 2*x==w and 2*y==h:
  flag=1
else:
  flag=0
print(square,flag)

Buggy submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
square = w*h/2
if 2x==w and 2y==h:
  flag=1
else:
  flag=0
print(square,flag)
Problem p03029 (python)

Fixed submission:
a,p=map(int, input().split())
print((3*a+p)//2)

Buggy submission (verdict: Runtime Error):
a,p=list(map(int, input().split()))
print((3a+p)//2)

Buggy submission (verdict: Runtime Error):
a,p=map(int, input().split())
print((3a+p)//2)

Buggy submission (verdict: Runtime Error):
a,p=map(int,input().split())
print((3a+p)//2)

Buggy submission (verdict: Runtime Error):
a,p=map(int,input().split())
pritn((3a+p)//2)
Problem p03044 (python)

Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append((v, w))
    graph[v].append((u, w))


def dfs(a):
    dist = [-1] * (n + 1)
    stack = [a]
    dist[a] = 0
    while stack:
        v = stack.pop()
        for b, w in graph[v]:
            if dist[b] == -1:
                dist[b] = (dist[v] + w) % 2
                stack.append(b)
            else:
                continue
    return dist


dist = dfs(1)
print(*dist[1:], sep="\n")

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

n = int(input())
graph = [[] for i in range(n + 1)]
cost = [[] * (n + 1) for j in range(n + 1)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)
    cost[u][v] = w
    cost[v][u] = w
ans = [] * (n + 1)


def dfs(a):
    dist = [-1] * (n + 1)
    stack = [a]
    dist[a] = 0
    while stack:
        v = stack.pop()
        for w in graph[v]:
            if dist[w] == -1:
                dist[w] = dist[v] + cost[w][v]
                dist[w] %= 2
                stack.append(w)
            else:
                continue
    return dist


dist = dfs(1)
print(*dist[1:], sep="\n")

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

n = int(input())
graph = [[] for i in range(n + 1)]
cost = [[] * (n + 1) for j in range(n + 1)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)
    cost[u][v] = w
    cost[v][u] = w
ans = [] * (n + 1)


def dfs(a):
    dist = [-1] * (n + 1)
    stack = [a]
    dist[a] = 0
    while stack:
        v = stack.pop()
        for w in graph[v]:
            if dist[w] == -1:
                dist[w] = dist[v] + cost[w][v]
                dist[w] %= 2
                stack.append(w)
            else:
                continue
    return dist


dist = dfs(1)
print(*dist[1:], sep="\n")
Problem p03076 (python)

Fixed submission:
a=int(input())
p=a%10
b=int(input())
q=b%10
c=int(input())
r=c%10
d=int(input())
s=d%10
e=int(input())
t=e%10
l=[a,b,c,d,e]
m=[p,q,r,s,t]
ans=0
if set(m)==set([0]):
    minimum=10
else:
    minimum=min(list(set(m)-set([0])))
def func(n):
    if n%10==0:
        return n
    else:
        return (n//10)*10+10
for i in range(5):
    ans+=func(l[i])
ans=ans-10+minimum
print(ans)

Buggy submission (verdict: Runtime Error):
a=int(input())
p=a%10
b=int(input())
q=b%10
c=int(input())
r=c%10
d=int(input())
s=d%10
e=int(input())
t=e%10
l=[a,b,c,d,e]
m=[p,q,r,s,t]
ans=0
minimum=min(list(set(m)-set([0])))
def func(n):
    if n%10==0:
        return n
    else:
        return (n//10)*10+10
for i in range(5):
    ans+=func(l[i])
ans=ans-10+minimum
print(ans)

Buggy submission (verdict: Runtime Error):
A=int(input())
a=A%10
B=int(input())
b=B%10
C=int(input())
c=C%10
D=int(input())
d=D%10
E=int(input())
e=E%10
if a=b=c=d=e=0:
  print(A-a+B-b+C-c+D-d+E-e+4*10-10*[a,b,c,d,e].count(0))
else:
  print(A-a+B-b+C-c+D-d+E-e+4*10+min(set([a,b,c,d,e])-set([0]))-10*[a,b,c,d,e].count(0))

Buggy submission (verdict: Runtime Error):
A=int(input())
a=A%10
B=int(input())
b=B%10
C=int(input())
c=C%10
D=int(input())
d=D%10
E=int(input())
e=E%10
print(A-a+B-b+C-c+D-d+E-e+4*10+min(set([a,b,c,d,e])-set([0]))-10*[a,b,c,d,e].count(0))
Problem p03149 (python)

Fixed submission:
A=list(map(int,input().split()))
L=[1,9,7,4]
print('YES' if set(A)==set(L) else 'NO')

Buggy submission (verdict: Runtime Error):
A=set(list(map(int,input().split())))
print('YES' if A==set(list(1,9,7,4)) else 'NO')
Problem p03150 (python)

Fixed submission:
s=input()
word='keyence'
flag=0
if s[:6]==word:
    flag=1
if s[-7:]==word:
    flag=1
for i in range(7):
    if s[:i]+s[-(7-i):]==word:
        flag=1
print('YES' if flag else 'NO')

Buggy submission (verdict: Runtime Error):
s=input()
word='keyence'
basho=0
for i in s:
  if word[basho]==i:
    basho+=1
print('YES' if basho==7 else 'NO')
Problem p03173 (python)

Fixed submission:
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
infi = 10 ** 20
SA = list(accumulate([0] + A))

dp = [[infi] * (n + 1) for _ in range(n + 1)]
# dp[i]左からi個決めた時の最小値とする。
if n >= 3:
    for i in range(n):
        dp[i][i] = 0
        dp[i][i + 1] = 0
        if i <= n - 2:
            dp[i][i + 2] = A[i] + A[i + 1]
    for d in range(n + 1):
        for i in range(n):
            j = i + d
            if j > n:
                continue
            if d >= 2:
                for m in range(i + 1, j + 1):
                    dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + SA[j] - SA[i])
    print(dp[0][n])
else:
    print(sum(A))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
infi = 10 ** 20
SA = list(accumulate([0] + A))

dp = [[infi] * (n + 1) for _ in range(n + 1)]
# dp[i]左からi個決めた時の最小値とする。
if n >= 3:
    for i in range(n):
        dp[i][i] = 0
        dp[i][i + 1] = 0
        if i <= n - 2:
            dp[i][i + 2] = A[i] + A[i + 1]
    for d in range(n + 1):
        for i in range(n):
            j = i + d
            if j > n:
                continue
            if d >= 2:
                for m in range(i + 1, j + 1):
                    dp[i][j] = min(dp[i][j], dp[i][m] + dp[m][j] + SA[j] - SA[i])
    print(dp[0][n])
else:
Problem p03206 (python)

Fixed submission:
dict={25:'Christmas',24:'Christmas Eve',23:'Christmas Eve Eve',22:'Christmas Eve Eve Eve'}
print(dict[int(input())])

Buggy submission (verdict: Runtime Error):
dict={25:'Christmas',24:'Christmas Eve',23:'Christmas Eve Eve',22:'Christmas Eve Eve Eve'}
print(dict[input()])

Buggy submission (verdict: Runtime Error):
dict={25:'Christmas',24:'Christmas Eve',23:'Christmas Eve Eve',22;'Christmas Eve Eve Eve'}
print(dict[input()])