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

Fixed submission:
#import pandas as pd
n=int(input())
O=[]
#A=[]
#B=[]
for i in range(n):
    a,b=map(int, input().split(" "))
    O.append([a+b,a,b])
  
#O=sorted(O, key=lambda x: (x[0],x[1]))[::-1]
O=sorted(O, key=lambda x: (x[0]))[::-1]
#print(O)

count=0
for num in range(n):
    if num%2==0:
        count+=O[num][1]
    else:
        count-=O[num][2]

print(count)

Buggy submission (verdict: Runtime Error):
import pandas as pd
n=int(input())
O=[]
#A=[]
#B=[]
for i in range(n):
    a,b=map(int, input().split(" "))
    O.append([2*a-b,a,b])
  
O=sorted(O, key=lambda x: x[0])[::-1]
#print(O)

count=0
for num in range(n):
    if num%2==0:
        count+=O[num][1]
    else:
        count-=O[num][2]

print(count)

Buggy submission (verdict: Runtime Error):
import pandas as pd
n=int(input())
O=[]
A=[]
B=[]
for i in range(n):
    a,b=map(int, input().split(" "))
    O.append(a+a-b)
    A.append(a)
    B.append(b)

tmp=pd.DataFrame()
tmp["o"]=O
tmp["b"]=A
tmp["c"]=B

tmp=tmp.sort_values(by="o",ascending=False)

count=0
for num,(i,j) in enumerate(zip(tmp["b"].values,tmp["c"].values)):
    if num%2==0:
        count+=i
    else:
        count-=j
print(count)
Problem p03163 (python)

Fixed submission:
#import numpy as np
n,w=map(int,input().split())
#重さをdpにする
#dp=[[0]*n,[0]*w] #n番目の品,重さ。価値が値として入る
#dp=np.zeros((n+1,w+1))
dp=[[0] * (w+1) for i in range(n+1)]
#print(dp)
#print(len(dp[0]))
#print(len(dp[n][w]))
W=[]
V=[]
for i in range(n):
    a,b=map(int,input().split())
    W+=[a]
    V+=[b]

#print(dp[0][0])
#print(W)
for i in range(n):
    #print(i)
    for sum_w in range(w+1):
        #print(sum_w)
        #足した時に価値が上がるケース
        if sum_w>=W[i]:
            dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w - W[i]] + V[i])
    
        #選ばない時
        else:
            dp[i+1][sum_w]=dp[i][sum_w]

#print(dp)
print(int(dp[n][w]))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,w=map(int,input().split())
#重さをdpにする
#dp=[[0]*n,[0]*w] #n番目の品,重さ。価値が値として入る
dp=np.zeros((n+1,w+1))

W=[]
V=[]
for i in range(n):
    a,b=map(int,input().split())
    W+=[a]
    V+=[b]

#print(dp[0][0])
#print(W)
for i in range(n):
    #print(i)
    for sum_w in range(w+1):
        #print(sum_w)
        #足した時に価値が上がるケース
        if sum_w>=W[i]:
            dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w - W[i]] + V[i])
    
        #選ばない時
        else:
            dp[i+1][sum_w]=dp[i][sum_w]

#print(dp)
print(int(dp[n][w]))
Problem p03213 (python)

Fixed submission:
import math
#import sympy
n=int(input())
a=math.factorial(n)
#print(a)
#a=32400

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
ps=prime_factors(a)
sy={}
for i in ps:
    if i not in sy:
        sy[i]=1
    else:
        sy[i]+=1
#aaaaaaaaaaa
#sy=sympy.factorint(a)
count75=0
count25=0
count15=0
count5=0
count3=0
for k in sy.values():
    #print(k)
    if k+1>=75:
        count75+=1
    if k+1>=25:
        count25+=1
    if k+1>=15:
        count15+=1
    if k+1>=5:
        count5+=1
    if k+1>=3:
        count3+=1

#print(count75)
#print(count25*(count3-1))
#print(count15*(count5-1))
#print((count5*(count5-1)*(count3-2))/2)
print(int(count75+count25*(count3-1)+count15*(count5-1)+(count5*(count5-1)*(count3-2))/2))

Buggy submission (verdict: Runtime Error):
import math
import sympy
n=int(input())
a=math.factorial(n)
#print(a)
#a=32400

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
ps=prime_factors(a)
sy={}
for i in ps:
    if i not in sy:
        sy[i]=1
    else:
        sy[i]+=1
#aaaaaaaaaaa
#sy=sympy.factorint(a)
count75=0
count25=0
count15=0
count5=0
count3=0
for k in sy.values():
    #print(k)
    if k+1>=75:
        count75+=1
    if k+1>=25:
        count25+=1
    if k+1>=15:
        count15+=1
    if k+1>=5:
        count5+=1
    if k+1>=3:
        count3+=1

#print(count75)
#print(count25*(count3-1))
#print(count15*(count5-1))
#print((count5*(count5-1)*(count3-2))/2)
print(int(count75+count25*(count3-1)+count15*(count5-1)+(count5*(count5-1)*(count3-2))/2))

Buggy submission (verdict: Runtime Error):
import math
import sympy
n=int(input())
a=math.factorial(n)
#print(a)
#a=32400
sy=sympy.factorint(a)
count75=0
count25=0
count15=0
count5=0
count3=0
for k in sy.values():
    #print(k)
    if k+1>=75:
        count75+=1
    if k+1>=25:
        count25+=1
    if k+1>=15:
        count15+=1
    if k+1>=5:
        count5+=1
    if k+1>=3:
        count3+=1

#print(count75)
#print(count25*(count3-1))
#print(count15*(count5-1))
#print((count5*(count5-1)*(count3-2))/2)
print(int(count75+count25*(count3-1)+count15*(count5-1)+(count5*(count5-1)*(count3-2))/2))
Problem p03244 (python)

Fixed submission:
import copy
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(100000)]
for i in V[::2]:
    d1[i-1]+=1
d2=[0 for i in range(100000)]
for i in V[1::2]:
    d2[i-1]+=1

m1=max(d1)
m2=max(d2)
maxind1 = [i for i, x in enumerate(d1) if x == m1]
maxind2 = [i for i, x in enumerate(d2) if x == m2]

#in1=d1.index(max(d1))
#in2=d2.index(max(d2))



if (maxind1[0] == maxind2[0]) and (len(maxind1) == 1) and (len(maxind2) == 1):
    #if m1>m2:
    #d2[maxind2[0]]=0
    tmp=copy.copy(d2)
    tmp[maxind2[0]]=0
    result1=n-max(d1)-max(tmp)

    #else:
    #d1[maxind1[0]]=0
    tmp=copy.copy(d1)
    tmp[maxind1[0]]=0
    result2=n-max(tmp)-max(d2)
    print(int(min(result1,result2)))
else:
#print(d1[:5])
#print(d2[:5])
    tmp1=n/2-max(d1)
    tmp2=n/2-max(d2)
    print(int(tmp1+tmp2))

Buggy submission (verdict: Runtime Error):
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(10000)]
for i in V[::2]:
    d1[i]+=1
d2=[0 for i in range(10000)]
for i in V[1::2]:
    d2[i]+=1


if d1.index(max(d1)) == d2.index(max(d2)):
    if max(d1)>max(d2):
        d2[d2.index(max(d2))]=0
    else:
        d1[d1.index(max(d1))]=0

#print(d1[:5])
#print(d2[:5])
tmp1=n/2-max(d1)
tmp2=n/2-max(d2)
print(int(tmp1+tmp2))

Buggy submission (verdict: Runtime Error):
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(100000)]
for i in V[::2]:
    d1[i]+=1
d2=[0 for i in range(100000)]
for i in V[1::2]:
    d2[i]+=1


if d1.index(max(d1)) == d2.index(max(d2)):
    if max(d1)>max(d2):
        d2[d2.index(max(d2))]=0
    else:
        d1[d1.index(max(d1))]=0

#print(d1[:5])
#print(d2[:5])
tmp1=n/2-max(d1)
tmp2=n/2-max(d2)
print(int(tmp1+tmp2))
Problem p03274 (python)

Fixed submission:
n,k=map(int, input().split(" "))
X=list(map(int, input().split(" ")))
#import bisect
maxvalue=100000000000000000000000
#place=bisect.bisect_left(X,0)

#if k<place:
#    X=X[place-k:]
#if k<n-place:
#    X=X[:-(n-place-k)]

#print(X)
#print(place)
for i in range(n-k+1):
    low=X[i]
    high=X[i+k-1]
    if high*low<0:
        low=abs(low)
        high=abs(high)
        value=min(low,high)*2+max(low,high)
    else:
        low=abs(low)
        high=abs(high)
        value=max(low,high)
    #print(value)
    if value<maxvalue:
        maxvalue=value
print(maxvalue)

Buggy submission (verdict: Runtime Error):
n,k=map(int, input().split(" "))
X=list(map(int, input().split(" ")))
import bisect
maxvalue=100000000000000000000000
place=bisect.bisect_left(X,0)

if k<place:
    X=X[place-k:]
elif k<n-place:
    X=X[:place-n]

#print(place)
for i in range(n-k+1):
    low=X[i]
    high=X[i+k-1]
    if high*low<0:
        low=abs(low)
        high=abs(high)
        value=min(low,high)*2+max(low,high)
    else:
        low=abs(low)
        high=abs(high)
        value=low+high
    #print(value)
    if value<maxvalue:
        maxvalue=value
print(maxvalue)
Problem p03623 (python)

Fixed submission:
tmp=map(int, raw_input().split(" "))
a=abs(tmp[0]-tmp[1])
b=abs(tmp[0]-tmp[2])
if a<b:
    print("A")
else:
    print("B")

Buggy submission (verdict: Runtime Error):
tmp=map(int, raw_input().split(" "))
a=abs(tmp[0]-tmp[1])
b=abs(tmp[0]-tmp[2])
if a<b:
    print("A")
else:
    print("B")
Problem p03624 (python)

Fixed submission:
a_list=("abcdefghijklmnopqrstuvwxyz")
word=(raw_input())
flag=0
out="None"
for i in a_list:
    for n,k in enumerate(word):
        if i==k:
            break
        if n==len(word)-1:
            out=i
            flag=1
    if flag==1:
        break
print(out)

Buggy submission (verdict: Runtime Error):
a_list=("abcdefghijklmnopqrstuvwxyz")
word=(raw_input())
flag=0
out="None"
for i in a_list:
    for n,k in enumerate(word):
        if i==k:
            break
        if n==len(word)-1:
            out=i
            flag=1
    if flag==1:
        break
print(out)
Problem p03626 (python)

Fixed submission:
num=raw_input()
tmp=raw_input()
tmp2=raw_input()
bef="none"
n_state=0
af_state=0
if len(tmp)==1:
    out=3
else:
    if tmp[0]==tmp[1]:
        out=6
        n_state=1
        init=2
    else:
        out=3
        init=1
    #out=3

    for i in range(init,len(tmp)):
        if tmp[i]!=bef:
            #print "aaa"
            if i<int(num)-1:
                if tmp[i]==tmp[i+1]:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*3
                        n_state=0
                else:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*1
                        n_state=0
            else:
                if n_state==0:
                    out=out*2
                else:
                    out=out*1
                    n_state=0
        else:
            n_state=1
        bef=tmp[i]
print out % 1000000007

Buggy submission (verdict: Runtime Error):
num=raw_input()
tmp=raw_input()
tmp2=raw_input()
bef="none"
n_state=0
af_state=0
if tmp[0]==tmp[1]:
    out=6
else:
    out=3

for i in range(1,len(tmp)):
    if tmp[i]!=bef:
        if i<int(num)-1:
            if tmp[i]==tmp[i+1]:
                if n_state==0:
                    out=out*2
                else:
                    out=out*3
                    n_state=0
            else:
                if n_state==0:
                    out=out*2
                else:
                    out=out*1
                    n_state=0
        else:
            if n_state==0:
                out=out*2
            else:
                out=out*1
                n_state=0
    else:
        n_state=1
    bef=tmp[i]
print out % 1000000007
Problem p02924 (python)

Fixed submission:
N =int(input())
print(int(N*(N-1)//2))

Buggy submission (verdict: Runtime Error):
N = int(input())
print(int(N*(N-1)//2)
Problem p03290 (python)

Fixed submission:
N = input().split()
N = [int(i) for i in N]
pi = [0 for i in range(N[0])]
ci = [0 for i in range(N[0])]
for i in range(N[0]):
    buf = input().split()
    pi[i] = int(buf[0])
    ci[i] = int(buf[1])

num_min = 10*100
G_new = N[1]

flag= [0 for i in range(N[0])]
for i in range(0, pow(2, N[0])):
    G_new = N[1]
    count = 0
    #print(bin(i))
    for j in range(N[0]):
        flag[j] = (i>>j & 1)
        if(flag[j]==1):
            G_new -= ci[j]
            G_new -= 100*(j+1)*pi[j]
            count += pi[j]
    #print(flag)

    if(G_new<=0):
        #print(i, flag)
        if(count < num_min):
            #print(count)
            num_min = count
            #print(count)
    else:
        for j in range(N[0]):
            if((flag[N[0]-1-j])==0):
                #print(i, flag, N[0]-1-j, G_new, pi[N[0]-1-j], count, -(-G_new//(100*(N[0]-j)))   )
                if(G_new - 100*(N[0]-j)*pi[N[0]-1-j] < 0):
                    count += -(-G_new//(100*(N[0]-j)))
                    if(count < num_min):
                       # print(count)
                        num_min = count
                break

    
print(num_min)

Buggy submission (verdict: Runtime Error):
N = input().split()
N = [int(i) for i in N]
pi = [0 for i in range(N[0])]
ci = [0 for i in range(N[0])]
for i in range(N[0]):
    buf = input().split()
    pi[i] = int(buf[0])
    ci[i] = int(buf[1])

num_min = 10*100
G_new = N[1]

flag= [0 for i in range(N[0])]
for i in range(0, pow(2, N[0])):
    G_new = N[1]
    count = 0
    #print(bin(i))
    for j in range(N[0]):
        flag[j] = (i>>j & 1)
        if(flag[j]==1):
            G_new -= ci[j]
            G_new -= 100*(j+1)*pi[j]
            count += pi[j]
    #print(flag)

    if(G_new<=0):
        #print(i, flag)
        if(count < num_min):
            #print(count)
            num_min = count
            #print(count)
    else:
        for j in range(N[0]):
            if((flag[N[0]-1-j])==0):
                #print(i, flag, N[0]-1-j, G_new, pi[N[0]-1-j], count, -(-G_new//(100*(N[0]-j)))   )
                if(G_new - 100*(N[0]-j)*pi[N[0]-1-j] < 0):
                    count += -(-G_new//(100*(N[0]-j)))
                    if(count < num_min):
                       # print(count)
                        num_min = count
                		break

    
print(num_min)
Problem p02909 (python)

Fixed submission:
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
elif S == 'Rainy':
    print('Sunny')

Buggy submission (verdict: Runtime Error):
if input() == 'Sunny':
    print('Cloudy')
elif input() == 'Cloudy':
    print('Rainy')
elif input() == 'Rainy':
    print('Sunny')
Problem p02975 (python)

Fixed submission:
import sys
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    if set(A) == {0}:
        print('Yes')
        sys.exit()
    
    if N%3 != 0:
        print('No')
        sys.exit()
    A.sort()

    n = int(N/3)
    if 1 == len(set(A[0:n])) and 1 == len(set(A[n:2*n])) and 1 == len(set(A[2*n:3*n])) and A[0] == A[n] ^ A[2*n]:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
import sys

if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    if N%3 != 0:
        print('No')
        sys.exit()
    A.sort()

    n = N/3
    if 1 == len(set(A[0:n])) and 1 == len(set(A[n:2*n])) and 1 == len(set(A[2*n:3*n])) and A[0] == A[n] ^ A[2*n]:
        print('Yes')
    else:
        print('No')
Problem p02803 (python)

Fixed submission:
# coding: utf-8

import queue

def main():
	H, W = (int(x) for x in input().split())
	S = [[] for x in range(H)]

	for i in range(H):
		S[i] = [x for x in input()]

	max_d = [[-1 for x in range(W)] for y in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			d = [[-1 for x in range(W)] for y in range(H)]
			q = queue.Queue()
			q.put([i, j])
			d[i][j] = 0
			while not q.empty():
				n = q.get()
				for y, x in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
					if (n[0] == 0   and y == -1) or\
					   (n[0] == H-1 and y ==  1) or\
					   (n[1] == 0   and x == -1) or\
					   (n[1] == W-1 and x ==  1) or\
					   S[n[0]+y][n[1]+x] == "#"  or\
					   d[n[0]+y][n[1]+x] != -1:
						continue
					d[n[0]+y][n[1]+x] = d[n[0]][n[1]] + 1
					q.put([n[0]+y, n[1]+x])
			for y in range(H):
				for x in range(W):
					if max_d[i][j] < d[y][x]:
						max_d[i][j] = d[y][x]

	max = 0
	for i in range(H):
		for j in range(W):
			if max < max_d[i][j]:
				max = max_d[i][j]

	print(str(max))

if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
 
def main():
	H, W = (int(x) for x in input().split())
	S = [[] for x in range(H)]
 
	for i in range(H):
		S[i] = [x for x in input()]
 
	# 隣接行列の作成
	inf = 1000000
 
	nodes = []
	for i in range(H):
		for j in range(W):
			if S[i][j] == ".":
				nodes.append([i, j])
	
	g = [[inf for j in range(len(nodes))] for i in range(len(nodes))]
	for i in range(len(nodes)):
		for j in range(len(nodes)):
			if   nodes[i][0] == nodes[j][0] and nodes[i][1] == nodes[j][1]:
				g[i][j] = 0
			elif abs(nodes[i][0]-nodes[j][0]) + abs(nodes[i][1]-nodes[j][1]) == 1:
				g[i][j] = 1
 
	max = 0
	for k in range(len(g[0])):
		for i in range(len(g[0])):
			for j in range(len(g[0])):
				g[i][j] = min(g[i][j], g[i][k] + g[k][j])
                if max < g[i][j]:
					max = g[i][j]

	print(max)
 
if __name__ == "__main__":
	main()
Problem p02804 (python)

Fixed submission:
# coding: utf-8

import math

N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
A.sort()

p = 10**9 + 7
facts = [1, 1]
for i in range(2, N+1):
	facts.append((facts[i-1] * i) % p)

invs = [1 for i in range(N+1)]
invs[N] = pow(facts[N], p-2, p)
for i in range(N, 1, -1):
	invs[i-1] = invs[i] * i % p

sum_max_s = 0
for i in range(K, N+1):
	sum_max_s += A[i-1] * (facts[i-1] * invs[K-1] * invs[i-K] % p) % p

sum_min_s = 0
for i in range(1, N-K+2):
	sum_min_s += A[i-1] * (facts[N-i] * invs[K-1] * invs[N-i-K+1] % p) % p

print(str(int(sum_max_s - sum_min_s) % p))

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import math

N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
A.sort()

print(A)

fact = [0 for i in range(N+1)]
for i in range(N+1):
	fact[i] = math.factorial(i)

sum_max_s = 0
for i in range(K, N+1):
	sum_max_s += A[i-1] * (fact[i-1] / (fact[K-1] * fact[i-K]))

sum_min_s = 0
for i in range(1, N-K+2):
	sum_min_s += A[i-1] * (fact[N-i] / (fact[K-1] * fact[N-i-K+1]))

print(str(int(sum_max_s - sum_min_s) % (10**9 + 7)))
Problem p02814 (python)

Fixed submission:
# coding: utf-8

import sys
import fractions
import functools

K, M = (int(x) for x in input().split())

A = [int(x) for x in input().split()]

A = [x for x in set(A)]
A.sort()

#print("A = " + str(A))#

# A[0]を素因数分解して2で割り切れる回数を数える
div = 0
a_0 = A[0]
while a_0 % 2 == 0:
	a_0 /= 2
	div += 1

#print("count = " + str(div))#

# Aのすべての整数がA[0]と同じ回数2で割り切れるか調べる
for i in range(1, len(A)):
	div2 = 0
	a = A[i]
	while a % 2 == 0:
		a /= 2
		div2 += 1
	#print("A[" + str(i) + "] count = " + str(div2))#
	if div2 != div:
		print("0")
		sys.exit()

# Aのすべての整数の最小公倍数を計算する
A = [a // 2 for a in A]
lcm = functools.reduce(lambda a, b: a * b // fractions.gcd(a, b), A, 1)
#print("lcm = " + str(lcm))#

# 1以上M以下の最小公倍数の奇数倍の整数の個数を数える
print(-(-(M // lcm) // 2))

Buggy submission (verdict: Runtime Error):
# coding: utf-8

K, M = (int(x) for x in input().split())

A = [int(x) for x in input().split()]

A = [x for x in set(A)]
A.sort()
A.reverse()

X = list(range(1, M + 1))

for a in A:
	X = [x for x in X if (x - int(a / 2)) % a == 0]

print(len(X))
Problem p03044 (python)

Fixed submission:
# coding: utf-8

def paint():
	while len(stack) > 0:
		node = stack.pop()
		for n in adj_list[node]:
			if color_list[n[0]] != "-1":
				continue

			stack.append(n[0])

			if n[1] % 2 == 0:
				color_list[n[0]] = color_list[node]
			else:
				if color_list[node] == "0":
					color_list[n[0]] = "1"
				else:
					color_list[n[0]] = "0"

N = int(input())
adj_list = [[] for i in range(N)]

for i in range(N - 1):
	elm = [int(x) for x in input().split()]
	adj_list[elm[0] - 1].append([elm[1] - 1, elm[2]])
	adj_list[elm[1] - 1].append([elm[0] - 1, elm[2]])

color_list = ["-1"] * N
color_list[0] = "0"

import sys
sys.setrecursionlimit(10000)

stack = [0]
paint()

for c in color_list:
	print(c)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

def paint(node):
	for n in adj_list[node]:
		if color_list[n[0]] != "-1":
			continue

		if n[1] % 2 == 0:
			color_list[n[0]] = color_list[node]
		else:
			if color_list[node] == "0":
				color_list[n[0]] = "1"
			else:
				color_list[n[0]] = "0"

		paint(n[0])

N = int(input())
adj_list = [[] for i in range(N)]

for i in range(N - 1):
	elm = [int(x) for x in input().split()]
	adj_list[elm[0] - 1].append([elm[1] - 1, elm[2]])
	adj_list[elm[1] - 1].append([elm[0] - 1, elm[2]])

color_list = ["-1"] * N
color_list[0] = "0"

import sys
sys.setrecursionlimit(10000)
paint(0)

for c in color_list:
	print(c)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

def paint(node):
	for n in adj_list[node]:
		if color_list[n[0]] != "-1":
			continue

		if n[1] % 2 == 0:
			color_list[n[0]] = color_list[node]
		else:
			if color_list[node] == "0":
				color_list[n[0]] = "1"
			else:
				color_list[n[0]] = "0"

		paint(n[0])

N = int(input())
adj_list = [[] for i in range(N)]

for i in range(N - 1):
	elm = [int(x) for x in input().split()]
	adj_list[elm[0] - 1].append([elm[1] - 1, elm[2]])
	adj_list[elm[1] - 1].append([elm[0] - 1, elm[2]])

color_list = ["-1"] * N

color_list[0] = "0"
paint(0)

for c in color_list:
	print(c)
Problem p03854 (python)

Fixed submission:
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if i + 4 < len(S) and S[i : i + 5] == "dream":
		if i + 6 < len(S) and S[i + 5 : i + 7] == "er":
			if i + 9 < len(S) and S[i + 7 : i + 10] == "ase":
				if i + 10 < len(S) and S[i + 10] == "r":
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if i + 4 < len(S) and S[i : i + 5] == "erase":
			if i + 5 < len(S) and S[i + 5] == "r":
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if S[i : i + 5] == "dream":
		if S[i + 5 : i + 7] == "er":
			if S[i + 7 : i + 10] == "ase":
				if S[i + 10] == "r":
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if S[i : i + 5] == "erase":
			if S[i + 5] == "r":
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if S[i : i + 5] == "dream":
		if S[i + 5 : i + 7] == "er":
			if S[i + 7 : i + 10] == "ase":
				if S[i + 10] == "r":
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if S[i : i + 5] == "erase":
			if S[i + 5] == "r":
				i += 6
			else:
				i += 5
		else:
			sys.exit()

print("YES")

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import sys

S = input()

i = 0
while i < len(S):
	if S[i : i + 5] == "dream":
		print("dream")
		if S[i + 5 : i + 7] == "er":
			print("er")
			if S[i + 7 : i + 10] == "ase":
				print("ase")
				if S[i + 10] == "r":
					print("r")
					i += 11
				else:
					i += 10
			else:
				i += 7
		else:
			i += 5
	else:
		if S[i : i + 5] == "erase":
			print("erase")
			if S[i + 5] == "r":
				print("r")
				i += 6
			else:
				i += 5
		else:
			print("NO")
			sys.exit()

print("YES")