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

Fixed submission:

N,W = map(int, input().split())

w = [0 for i in range(N)]
v = [0 for i in range(N)]
Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

for i in range(N):
    w[i],v[i] = map(int, input().split())
Wmin = min(w)

w.insert(0,"0")
v.insert(0,"0")


for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]


nap_memo = {}

#i番目の品物まで含み制約W2のナップサック問題の最適解
def nap(i,W2):
    #重複計算を避けるためnap(i,W2)を保持
    key = str(i) + ':' + str(W2)
    if key in nap_memo:
        return nap_memo[key]
    #品物0個のときは価値は0
    elif i == 0:
        r = 0
    #制約0のときも価値は0
    elif W2 < Wmin:
        r = 0
    #w[i]がW2を超えるときはi番目の品物は不必要
    elif W2 < w[i]:
        r = nap(i-1,W2)
    #品物の重さ全部足して制約以下なら全部足したものが価値で良い
    elif Wsum[i] <= W2:
        r = Vsum[i]
    #i番目の品物をナップサックに入れるか入れないか
    else:
        r = max( nap(i-1,W2-w[i])+v[i] , nap(i-1,W2) )
    
    nap_memo[key] = r
    return r
    
            
print(nap(N,W))

Buggy submission (verdict: Runtime Error):

N,W = map(int, input().split())

w = [0 for i in range(N+1)]
v = [0 for i in range(N+1)]
Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

#品物、重み→1〜N番目
for i in range(N):
    w[i+1],v[i+1] = map(int, input().split())

for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]

#i番目の品物まで含み制約W2のナップサック問題の最適解
def nap(i,W2):
    #品物0個のときは価値は0
    if i == 0:
        return 0
    #制約0のときも価値は0
    if W == 0:
        return 0
    #w[i]がW2を超えるときはi番目の品物は不必要
    if W2 < w[i]:
        return nap(i-1,W2)
    #品物の重さ全部足して制約以下なら全部足したものが価値で良い
    if Wsum[i] <= W2:
        return Vsum[i]
        
    #i番目の品物をナップサックに入れるか入れないか
    return max( nap(i-1,W2-w[i])+v[i] , nap(i-1,W2) )
    
            
print(nap(N,W), flush = True))

Buggy submission (verdict: Runtime Error):

N,W = map(int, input().split())

w = [0 for i in range(N+1)]
v = [0 for i in range(N+1)]
Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

#品物、重み→1〜N番目
for i in range(N):
    w[i+1],v[i+1] = map(int, input().split())

for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]

#i番目の品物まで含み制約W2のナップサック問題の最適解
def nap(i,W2):
    #品物0個のときは価値は0
    if i == 0:
        return 0
    #制約0のときも価値は0
    if W == 0:
        return 0
    #w[i]がW2を超えるときはi番目の品物は不必要
    if W2 < w[i]:
        return nap(i-1,W2)
    #品物の重さ全部足して制約以下なら全部足したものが価値で良い
    if Wsum[i] <= W2:
        return Vsum[i]
        
    #i番目の品物をナップサックに入れるか入れないか
    return max( nap(i-1,W2-w[i])+v[i] , nap(i-1,W2) )
    
            
print(nap(N,W), flush = True))
Problem p03023 (python)

Fixed submission:
a = int(input())
print((a-2)*180)

Buggy submission (verdict: Runtime Error):
print((input()-2)*180)
Problem p03030 (python)

Fixed submission:
n=int(input())
i = 1
alllist = []
while i < n+1 :
  a,b=map(str, input().split())
  c = [a ,int(b),i]
  alllist.append(c)
  i += 1
alllist.sort(key=lambda x:(x[0],-x[1]),reverse=True)
alllist.reverse()
j = 0
while j < n :
  print(alllist[j][2])
  j += 1

Buggy submission (verdict: Runtime Error):
n=int(input())
i = 1
alllist = []
while i < n :
  a,b=map(str, input().split())
  c = [a ,int(b),i]
  alllist.append(c)
  i += 1
alllist.sort(key=lambda x:-x[1],reverse=True)
#print(alllist[0][2])
j = 0
while j < n :
  print(alllist[j][2])
  j += 1

Buggy submission (verdict: Runtime Error):
n=int(input())
i = 1
alllist = []
while i < n :
  a,b=map(str, input().split())
  c = [a ,int(b),i]
  alllist.append(c)
  i += 1
alllist.sort(key=lambda x:-x[1],reverse=True)
#print(alllist[0][2])
j = 0
while j < n :
  print(alllist[j-1][2])
  j += 1
Problem p03006 (python)

Fixed submission:
from collections import Counter
N = int(input())
ball = [[int(i) for i in input().split()] for k in range(N)]
ball.sort(key=lambda x: x[1])
ball.sort()
diff = []
if N == 1:
    print(1)
else:
    for i in range(N-1):
        for j in range(i+1, N):
            diff.append([(ball[j][n]-ball[i][n]) for n in range(2)])
    k = Counter(map(tuple, diff)).most_common()[0][1]
#    print(diff)
    print(max(1,N-k))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
ball = [[int(i) for i in input().split()] for k in range(N)]
diff = []
for i in range(N):
    for j in range(i+1, N):
        diff.append((abs(ball[i][n]-ball[j][n]) for n in range(2)))
k = Counter(diff).most_common()[0][1]
print(max(1,N-1-k))
Problem p03029 (python)

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

Buggy submission (verdict: Runtime Error):
A, P = map(int,input().split())
print((3A+P)//2)
Problem p03087 (python)

Fixed submission:
N , Q = map(int, input().split())
S = input()
LR = [[int(i)-1 for i in input().split()] for j in range(Q)]
T = list(S)
ACtimes = [0] * len(T)

for i in range(1,len(T)):
    if T[i-1] == "A" and T[i] == "C":
        ACtimes[i] = ACtimes[i-1] + 1
    else:
        ACtimes[i] = ACtimes[i-1]

for k in LR:
    print(ACtimes[k[1]] - ACtimes[k[0]])

Buggy submission (verdict: Runtime Error):
N , Q = map(int, input().split())
S = input()
LR = [[int(i) for i in input().split()] for j in range(Q)]
T = list(S)
AC_list = []

for i in range(len(T)):
    if T[i] == "A" and T[i+1] == "C":
        AC_list.append(i)

for i in LR:
    n = len([k for k in AC_list if k>=i[0]-1 and k<i[1]-1])
    print(n)
Problem p03140 (python)

Fixed submission:
N = int(input())
A = input()
B = input()
C = input()

ans = 0

for i in range(N):
  S = {A[i], B[i], C[i]}
  ans += S.__len__() - 1

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input()
B = input()
C = input()

ans = 0

for i in range(N):
  S = set(A[i], B[i], C[i])
  ans += S.__len__() - 1

print(ans)
Problem p03229 (python)

Fixed submission:
import math as mt
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
#print(A)
S = 0
P2 = mt.floor(N/2 - 1)
if N % 2 == 0:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S += A[P2+1] - A[P2]
    print(S)
elif N % 2 == 1:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S1 = A[N-P2-2] + A[N-P2-1] - 2 * A[P2]
    S2 = 2 * A[N-1-P2] - A[P2] - A[P2+1]
    if S1 >= S2:
        print(S1+S)
    else:
        print(S2+S)

Buggy submission (verdict: Runtime Error):
import math as mt
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
#print(A)
S = 0
P2 = mt.floor(N/2 - 1)
if N % 2 == 0:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S += A[P2+1] - A[P2]
    print(S)
elif N % 2 == 1:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S1 = A[N-P2-1] + A[N-P2] - 2 * A[P2]
    S2 = 2 * A[N-1-P2] - A[P2] - A[P2+1]
    if S1 >= S2:
        print(S1+S)
    else:
        print(S2+S)

Buggy submission (verdict: Runtime Error):
import math as mt
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
#print(A)
S = 0
P2 = mt.floor(N/2 - 1)
if N % 2 == 0:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S += A[P2+1] - A[P2]
    print(S)
elif N % 2 == 1:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S1 = A[N-P2-1] + A[N-P2] - 2 * A[P2]
    S2 = 2 * A[N-1-P2] - A[P2] - A[P2+1]
    if S1 >= S2:
        print(S1)
    else:
        print(S2)

Buggy submission (verdict: Runtime Error):
import math as mt
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
#print(A)
S = 0
P2 = mt.floor(N/2 - 1)
if N % 2 == 0:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S += A[P2+1] - A[P2]
elif N % 4 == 1:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S += 2 * A[N-1-P2] - A[P2] - A[P2+1]
else:
    for i in range(0,P2,1):
        S += 2 * (A[N-i-1] - A[i])
    S += A[N-P2-1] + A[N-P2] - 2 * A[P2]
print(S)
Problem p03251 (python)

Fixed submission:
N, M, X, Y = map(int, input().split())
L_X = [int(i) for i in input().split()]
L_Y = [int(i) for i in input().split()]

if max(L_X) < min(L_Y) and X < min(L_Y) and max(L_X) < Y:
    print("No War")
else:
    print("War")

Buggy submission (verdict: Runtime Error):
N, M, X, Y = map(int, input().split())
L_X = [int(i) for i in input().split()]
L_Y = [int(i) for i in input().split()]

S = set(L_X, )
S.add(L_Y, )
if X in S or Y in S:
    print("War")
elif max(L_X) < min(L_Y) and X < min(L_Y) and max(L_X) < Y:
    print("No War")
else:
    print("War")
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
l = [int(i) for i in S]
for i in range(min(S.__len__(), K)):
    if l[i] != 1:
        print(l[i])
        break
else:
    print(1)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
l = [int(s) for s in S if s != "1"]
print(l[0])
Problem p03294 (python)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

print(sum(a) - N)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i input().split()]
print(sum(a) - N)
Problem p03624 (python)

Fixed submission:
S = input()
S = set(S)
alp = [chr(ord('a') + i) for i in range(26)]
for i in alp:
  if i not in S:
    print(i)
    break
else:
  print("None")

Buggy submission (verdict: Runtime Error):
S = input()
S.set()
alp = [chr(ord('a') + i) for i in range(26)]
for i in alp:
  if i not in S:
    print(i)
    break
Problem p03636 (python)

Fixed submission:
S = input()
l = S.__len__()
print('%s%s%s' % (S[0], l-2, S[l-1]))

Buggy submission (verdict: Runtime Error):
S = input()
l = S.__len__()
print('%s%s%s' % [S[0], l-2, S[l-1]]
Problem p03671 (python)

Fixed submission:
L = [int(i) for i in input().split()]
L.sort()
print(L[0] + L[1])

Buggy submission (verdict: Runtime Error):
L = [int(i) for i in input().split()]
L.sorted()
print(L[0] + L[1])
Problem p03799 (python)

Fixed submission:
N, M = map(int, input().split())
ans = 0
if N > M//2:
  print(M//2)
else:
  p = M - 2*N
  print(N + p//4)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = 0
if N > M//2:
  print(M//2)
else:
  p = M - 2*N
  print(N + p//4
Problem p03817 (python)

Fixed submission:
N = int(input())
if N % 11 > 6:
  print((N+10)//11*2)
elif N % 11 == 0:
  print(N//11*2)
else:
  print(N//11*2+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 11 > 6:
  print(N+10//11*2)
elif n % 11 == 0:
  print(N//11*2)
else:
  print(N//11*2+1)
Problem p03826 (python)

Fixed submission:
a, b, c, d = map(int,input().split())
L = [a*b, c*d]
L.sort()
print(L[1])

Buggy submission (verdict: Runtime Error):
a, b, c, d = input().split()
L = [a*b, c*d]
L.sort()
print(L[1])
Problem p03860 (python)

Fixed submission:
A,S,C = input().split()
print ('A%sC' % S[0])

Buggy submission (verdict: Runtime Error):
S = input()
print'A%sC' % s[0]
Problem p03963 (python)

Fixed submission:
N, K = map(int, input().split())
print(K * ((K-1) ** (N-1)))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
print(K * ((K-1)**(N-1))
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print(int((a+b)*h/2))

Buggy submission (verdict: Runtime Error):
a, b, h = map(int, input().split())
print((a+b) * (h/2))
Problem p03998 (python)

Fixed submission:
S_A = [i for i in input()+'A']
S_B = [i for i in input()+'B']
S_C = [i for i in input()+'C']
T = S_A
l = T.__len__()
while(l > 1):
    t = T.pop(0)
    if t == 'a':
        T = S_A
    elif t == 'b':
        T = S_B
    elif t == 'c':
        T = S_C
    l = T.__len__()
print(T[0])

Buggy submission (verdict: Runtime Error):
S_A = [i for i in input()]
S_B = [i for i in input()]
S_C = [i for i in input()]
T = S_A
l = T.__len__()
while(l > 0):
    if T.pop(0) == 'a':
        T = S_A
    elif T.pop(0) == 'b':
        T = S_B
    else:
        T = S_C
    l = T.__len__()
if 0 == S_A.__len__():
    print("A")
elif 0 == S_B.__len__():
    print("B")
else:
    print("C")
Problem p04045 (python)

Fixed submission:
n, k = map(int, input().split())
d = set([int(i) for i in input().split()])

while True:
  N = set([int(i) for i in str(n)])
  if len(N.intersection(d)) == 0:
    print(n)
    break
  else:
    n += 1

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
d = [int(i) for i in input().split()]

for i in range(100000):
  m = n + i
  N = []
  while(m > 0):
    N.append(m%10)
    m //= 10
  N.reverse()
  if N.intersection(d) == []:
    print(N)
    exit()
  else:
    continue
Problem p02909 (python)

Fixed submission:
str = input()

if str == "Sunny":
  print("Cloudy")
elif str == "Cloudy":
  print("Rainy")
else:
  print("Sunny")

Buggy submission (verdict: Runtime Error):
str = input()

split = str.split(" ")

N = int(split[0])
M = int(split[1])

HowMuch = [0 for i in range(N)]

split = input().split(" ")
for i in range(N):
  HowMuch[i] = int(split[i])
  
sortHow = HowMuch.sort(reverse = True)

if sortHow is None:
  sortHow = HowMuch[0]

if type(sortHow) is int:
  for i in range(M):
    sortHow //= 2
  print(sortHow)
else:
  for i in range(M):
    maxInd = sortHow.index(max(sortHow))
    sortHow[maxInd] //= 2
  print(sum(HowMuch))
Problem p02911 (python)

Fixed submission:
str = input()

split = str.split(" ")

Member = int(split[0])
Point = int(split[1])
Ans = int(split[2])
MemPoint = [0 for i in range(Member)]

for i in range(Ans):
  MemPoint[int(input())-1] += 1

for i in range(Member):
  if Point - (Ans - MemPoint[i]) > 0:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
str = input()

split = str.split(" ")

Member = int(split[0])
Point = int(split[1])
Ans = int(split[2])
MemPoint = [0 for i in range(Member)]

for i in range(Ans):
  MemPoint[int(input())] += 1

maxNum = max(MemPoint)
for i in range(Menber):
  if maxNum == MemPoint[i]:
    print("Yes")
  else:
    print("No")
Problem p03047 (python)

Fixed submission:
import sys

if __name__ == "__main__":
	s = input().split(" ")
	print(int(s[0]) - (int(s[1]) - 1))

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
  s = input().split(" ")
  R = int(s[0])
  G = int(s[1])
  B = int(s[2])
  N = int(s[3])
  
  count = 0
  for i in range(N/R+1):
    sumR = R * i
    if sumR == N:
      count += 1
      break
    elif sumR > N:
      break
    else:
      for j in range(N/G+1):
        sumG = G * j
        if sumR + sumG == N:
          count += 1
          break
        elif sumR + sumG > N:
          break
        else:
          for k in range(N/B+1):
            sumB = B * k
            if sumR + sumG + sumB == N:
              count += 1
              break
            elif sumR + sumG + sumB > N:
              break
  print(count)

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
  s = input().split(" ")
  R = int(s[0])
  G = int(s[1])
  B = int(s[2])
  N = int(s[3])
  
  count = 0
  for i in range(R):
    sumR = R * i
      for j in range(G):
        sumG = G * j
        for k in range(B):
          sumB = sumB * k
          if sumR + sumG + sumB == N:
            count += 1
            break
  print(count)

Buggy submission (verdict: Runtime Error):
import sys

s = input().split(" ")

print(int(s[0]) - (int(s[1]) - 1)
Problem p02947 (python)

Fixed submission:
# -*- coding: UTF-8 -*-

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)

Buggy submission (verdict: Runtime Error):
# -*- coding: UTF-8 -*-
import math

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 0
f = 0

for i in range(n):
    if l[i] == l[i+1]:
        s =+ 1
        f = 1
    elif l[i] != l[i+1] and f == 1:
        s += 1
        f = 0
        p += math.factorial(s)/(2 * math.factorial(s-2))


print(p)
Problem p02953 (python)

Fixed submission:
# -*- coding: UTF-8 -*-

n = int(input())
l = list(map(int, input().split()))
l.reverse()
f = 0

for i in range(len(l)-1):
    if l[i] >= l[i+1]:
        continue
    else:
        if l[i] >= l[i+1] - 1:
            l[i+1] -= 1
        else:
            f = 1

    if f == 1:
        break

if f == 1:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
*- coding: UTF-8 -*-

n = int(input())
l = list(map(int, input().split()))
l.reverse()
f = 0

for i in range(len(l)-1):
    if l[i] >= l[i+1]:
        continue
    else:
        if l[i] >= l[i+1] - 1:
            l[i+1] -= 1
        else:
            f = 1

    if f == 1:
        break


if f == 1:
    print("No")
else:
    print("Yes")
Problem p02813 (python)

Fixed submission:
n=int(input())
fact=[1]*13
for i in range(2,13):
	fact[i]=i*fact[i-1]
p=list(map(int,input().split()))
q=list(map(int,input().split()))
a=0
b=0
for i in range(n):
	a=a+((p[i]-1)*(fact[n-i-1]))
	b=b+((q[i]-1)*(fact[n-i-1]))
	for j in range(i+1,n):
		if(p[j]>p[i]):
			p[j]=p[j]-1
		if(q[j]>q[i]):
			q[j]=q[j]-1
print(abs(a-b))

Buggy submission (verdict: Runtime Error):
n=map(int,input())
fact=[1,1,2,6,24,120,720,5040,40320]
p=list(map(int,input().split()))
q=list(map(int,input().split()))
a=0
b=0
for i in range(n):
	a=a+((p[i]-1)*(fact[n-i-1]))
	b=b+((q[i]-1)*(fact[n-i-1]))
	for j in range(i+1,n):
		if(p[j]>p[i]):
			p[j]=p[j]-1
		if(q[j]>q[i]):
			q[j]=q[j]-1
print(abs(a-b))
Problem p03469 (python)

Fixed submission:
s=list(input().split('/'))
s[0]="2018"
o=s[0]+'/'+s[1]+'/'+s[2]
print(o)

Buggy submission (verdict: Runtime Error):
s=input()
s[3]='8'
print(s)
Problem p03494 (python)

Fixed submission:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    cnt = 0
    while True:
        loop = True
        for i in range(N):
            if A[i] % 2 == 1:
                loop = False
                break
            A[i] /= 2
        if not loop:
            break
        cnt += 1
    print(cnt)

input = lambda: stdin.readline().rstrip()
main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin
 
def main():
    N = map(int, input().split())
    A = [int(x) for x in input.split()]
    cnt = 0
    while True:
        for i in range(N):
            A[i] /= 2
            if A[i] % 2 == 1:
                break
        cnt += 1
    print(cnt)
 
input = lambda: stdin.readline().rstrip()
main()
Problem p02957 (python)

Fixed submission:
A, B = map(int, input().split())
if (A + B) % 2 != 0:
    print("IMPOSSIBLE")
else:
    print((A + B) // 2)

Buggy submission (verdict: Runtime Error):
s = input()
dp = [0 for _ in range(13)]
dp[0] = 1
c = 1000000007
m = 1
r13 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
r10 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
for i in range(len(s) - 1, -1, -1):
    ndp = [0 for _ in r13]
    if s[i] == "?":
        for j in r10:
            jm = j * m
            for k in r13:
                index = (jm + k) % 13
                ndp[index] = (ndp[index] + dp[k]) % c
    else:
        jm = int(s[i]) * m
        for k in r13:
            index = (jm + k) % 13
            ndp[index] = (ndp[index] + dp[k]) % c
    dp = ndp[:]
    m = m * 10 % 13
print(dp[5])
Problem p02922 (python)

Fixed submission:
A, B = map(int, input().split(' '))
sum = 1
ans = 0
while sum < B:
    ans += 1
    sum += A - 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split(' '))
sum = 0
ans = 0
while sum =< B:
    ans +=1
    sum += A
print(ans)
Problem p03044 (python)

Fixed submission:
"""Even Relation
https://atcoder.jp/contests/abc126/tasks/abc126_d
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5 + 1)


class Node:
    def __init__(self, node_id, color):
        self.node_id = node_id
        self.color = color
        self.edges = []

class Edge:
    def __init__(self, to, length):
        self.to = to
        self.length = length


def dfs(node, p):
    for edge in node.edges:
        # 親への枝は何もしない
        if edge.to == p:
            continue
        # 枝が偶数なら子を同じ色で塗る
        if edge.length % 2 == 0:
            graph[edge.to].color = node.color
        else:
            if node.color == 1:
                graph[edge.to].color = 0
            else:
                graph[edge.to].color = 1

        dfs(graph[edge.to], node.node_id)


N = int(input())

# グラフ初期化
graph = [Node(node_id=i, color=-1) for i in range(N + 1)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    graph[u].edges.append(Edge(v, w))
    graph[v].edges.append(Edge(u, w))

# 最初は0始まり
graph[1].color = 0

dfs(graph[1], -1)


for i in range(1, N + 1):
    print(graph[i].color)

Buggy submission (verdict: Runtime Error):
"""Even Relation
https://atcoder.jp/contests/abc126/tasks/abc126_d
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)


class Node:
    def __init__(self, node_id, color):
        self.node_id = node_id
        self.color = color
        self.edges = []

class Edge:
    def __init__(self, to, length):
        self.to = to
        self.length = length


def dfs(node, p):
    for edge in node.edges:
        # 親への枝は何もしない
        if edge.to == p:
            continue
        # 枝が偶数なら子を同じ色で塗る
        if edge.length % 2 == 0:
            graph[edge.to].color = node.color
        else:
            if node.color == 1:
                graph[edge.to].color = 0
            else:
                graph[edge.to].color = 1

        dfs(graph[edge.to], node.node_id)


N = int(input())

# グラフ初期化
graph = [Node(node_id=i, color=-1) for i in range(N + 1)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    graph[u].edges.append(Edge(v, w))
    graph[v].edges.append(Edge(u, w))

# 最初は0始まり
graph[1].color = 0

dfs(graph[1], -1)


for i in range(1, N + 1):
    print(graph[i].color)
Problem p02802 (python)

Fixed submission:
N, M = map(int, input().split())
p = [0] * M
S = [0] * M
count_AC = [0] * N
count_WA = [0] * N
for i in range(M):
    p[i],S[i] =  input().split()
    p[i] = int(p[i]) - 1

    if S[i] == 'AC':
        if count_AC[p[i]] == 0:
            count_AC[p[i]] = 1
            
    if S[i] == 'WA':
        if count_AC[p[i]] == 0:
            count_WA[p[i]] = count_WA[p[i]] + 1
            
print(sum(count_AC) , sum([x * y for (x, y) in zip(count_AC, count_WA)]))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
p = [0] * M
S = [0] * M
count_AC = [0] * N
count_WA = [0] * N
for i in range(M):
    p[i],S[i] =  input().split()
    p[i] = int(p[i])

    if S[i] == 'AC':
        if count_AC[p[i]] == 0:
            count_AC[p[i]] = 1
            
    if S[i] == 'WA':
        if count_AC[p[i]] == 0:
            count_WA[p[i]] += 1
            
print(sum(count_AC) , sum(count_WA))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
p = [0] * M
S = [0] * M
count_AC = [0] * M
count_WA = [0] * M
for i in range(M):
    p[i],S[i] =  input().split()
    p[i] = int(p[i])

    if S[i] == 'AC':
        if count_AC[p[i]] == 0:
            count_AC[p[i]] = 1
            
    if S[i] == 'WA':
        if count_AC[p[i]] == 0:
            count_WA[p[i]] += 1
            
print(sum(count_AC) , sum(count_WA))