Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	if K <= 10 ** 5:
		loc = 0
		for i in range(K):
			loc = A[loc] - 1
		print(loc + 1)
		return

	loc = 0
	for i in range(10 ** 5):
			loc = A[loc] - 1

	start = loc
	loop = [loc]
	loc = A[loc] - 1
	while loc != start:
		loop.append(loc)
		loc = A[loc] - 1

	M = len(loop)
	ans = loop[(K - 10 ** 5) % M]
	print(ans + 1)
	
	




if __name__ == '__main__':
	main()

Fixed submission:
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	if K <= 2 * (10 ** 5):
		loc = 0
		for i in range(K):
			loc = A[loc] - 1
		print(loc + 1)
		return

	loc = 0
	for i in range(2 * (10 ** 5)):
			loc = A[loc] - 1

	start = loc
	loop = [loc]
	loc = A[loc] - 1
	while loc != start:
		loop.append(loc)
		loc = A[loc] - 1

	M = len(loop)
	ans = loop[(K - 2 * (10 ** 5)) % M]
	print(ans + 1)
	
	




if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	S = input()
	Q = int(input())
	cnt = 0
	s_start = ""
	s_end = ""
	for i in range(Q):
		q = list(input().split())
		if q[0] == "1":
			cnt += 1
		else:
			if q[1] == "1":
				if cnt % 2 == 0:
					s_start += q[2]
				else:
					s_end += q[2]
			else:
				if cnt % 2 == 0:
					s_end += q[2]
				else:
					s_start += q[2]

	if cnt % 2 == 0:
		ans = s_start[::-1] + S + s_end

	else:
		ans = s_end[::-1] + S[::-1] + s_start

	print(ans)

if __name__ == '__main__':
	main()

Fixed submission:

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	S = input()
	Q = int(input())
	cnt = 0
	s_start = ""
	s_end = ""
	for i in range(Q):
		q = list(input().split())
		if q[0] == "1":
			cnt += 1
		else:
			if q[1] == "1":
				if cnt % 2 == 0:
					s_start += q[2]
				else:
					s_end += q[2]
			else:
				if cnt % 2 == 0:
					s_end += q[2]
				else:
					s_start += q[2]

	if cnt % 2 == 0:
		ans = s_start[::-1] + S + s_end

	else:
		ans = s_end[::-1] + S[::-1] + s_start

	print(ans)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34


Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A = []
	for i in range(3):
		a = getlist()
		A.append(a)
	bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

	N = int(input())
	for k in range(N):
		b = int(input())
		for i in range(3):
			for j in range(3):
				if A[i][j] == b:
					bingo[i][j] = 1
	
	judge = "No"
	for i in range(3):
		if bingo[i][0] == 1 and bingo[i][1] == 1 and bingo[i][2] == 1:
			judge = "Yes"
	for i in range(3):
		if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
			judge = "Yes"

	if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
		judge = "Yes"
	if bingo[2][0] == 1 and bingo[1][1] == 1 and bingo[0][2] == 1:
		judge = "Yes"

	print(judge)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
from fractions import gcd

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	A = getlist()
	B = [int(A[i] // 2) for i in range(N)]
	LCM = B[0]
	for i in range(N - 1):
		GCD = gcd(LCM, B[i + 1])
		LCM = int(LCM * B[i + 1] / GCD)
		if LCM >= 10 ** 10:
			break

	if LCM > M:
		print(0)
	else:
		ans = (M - LCM) // (2 * LCM) + 1
		D = defaultdict(int)
		for i in range(N):
			x = B[i]
			val = 0
			while True:
				if x % 2 == 0:
					val += 1
				else:
					break
			D[val] += 1

		if D[val] != N:
			ans = 0
			
		print(ans)


if __name__ == '__main__':
	main()

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
from fractions import gcd

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	A = getlist()
	B = [int(A[i] // 2) for i in range(N)]
	LCM = B[0]
	for i in range(N - 1):
		GCD = gcd(LCM, B[i + 1])
		LCM = int(LCM * B[i + 1] / GCD)
		if LCM >= 10 ** 10:
			break

	if LCM > M:
		print(0)
	else:
		ans = (M - LCM) // (2 * LCM) + 1
		D = defaultdict(int)
		for i in range(N):
			x = B[i]
			val = 0
			while True:
				if x % 2 == 0:
					val += 1
					x = int(x // 2)
				else:
					break
			D[val] += 1

		if D[val] != N:
			ans = 0

		print(ans)


if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	R, S, P = getlist()
	T = input()
	ans = 0
	for k in range(K):
		DPr = [0] * N
		DPs = [0] * N
		DPp = [0] * N
		#初期化
		if T[k] == "r":
			DPp[k] = P
		elif T[k] == "s":
			DPr[k] = R
		else:
			DPs[k] = S

		for i in range(1, N + 1):
			now = i * K + k
			pre = (i - 1) * K + k
			if now >= N:
				ans += max(DPr[pre], DPs[pre], DPp[pre])
				break
			if T[now] == "r":
				DPr[now] = max(DPs[pre], DPp[pre])
				DPs[now] = max(DPr[pre], DPp[pre])
				DPp[now] = max(DPr[pre] + P, DPs[pre] + P)
			elif T[now] == "s":
				DPr[now] = max(DPs[pre] + R, DPp[pre] + R)
				DPs[now] = max(DPr[pre], DPp[pre])
				DPp[now] = max(DPr[pre], DPs[pre])
			else:
				DPr[now] = max(DPs[pre], DPp[pre])
				DPs[now] = max(DPr[pre] + S, DPp[pre] + S)
				DPp[now] = max(DPr[pre], DPs[pre])
		# print(DPr)
		# print(DPs)
		# print(DPp)

	print(ans)

if __name__ == '__main__':
	main()

Fixed submission:
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	R, S, P = getlist()
	T = input()
	ans = 0
	DPr = [0] * N
	DPs = [0] * N
	DPp = [0] * N
	#初期化
	for k in range(K):	
		if T[k] == "r":
			DPp[k] = P
		elif T[k] == "s":
			DPr[k] = R
		else:
			DPs[k] = S
	for i in range(K, N):
		now = i
		pre = i - K
	
		if T[now] == "r":
			DPr[now] = max(DPs[pre], DPp[pre])
			DPs[now] = max(DPr[pre], DPp[pre])
			DPp[now] = max(DPr[pre] + P, DPs[pre] + P)
		elif T[now] == "s":
			DPr[now] = max(DPs[pre] + R, DPp[pre] + R)
			DPs[now] = max(DPr[pre], DPp[pre])
			DPp[now] = max(DPr[pre], DPs[pre])
		else:
			DPr[now] = max(DPs[pre], DPp[pre])
			DPs[now] = max(DPr[pre] + S, DPp[pre] + S)
			DPp[now] = max(DPr[pre], DPs[pre])
	# print(DPr)
	# print(DPs)
	# print(DPp)
	for i in range(K):
		ans += max(DPr[N - 1 - i], DPs[N - 1 - i], DPp[N - 1 - i])

	print(ans)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
#ライブラリインポート
from collections import defaultdict
import bisect

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	S = list(input())
	nibu = []
	for i in range(N + 1):
		if S[i] == "0":
			nibu.append(i)
	DP = [0] * (N + 1)
	prev = [None] * (N + 1)
	for i in range(1, N + 1):
		if S[i] == "0":
			s = bisect.bisect_left(nibu, i - M)
			x = nibu[s]
			if x != i:
				prev[i] = x
				DP[i] = DP[x] + 1
	# print(nibu)
	# print(DP)
	# print(prev)
	if prev[N] == None:
		print(-1)
	else:
		ans = []
		x = N
		while True:
			ans.append(x - prev[x])
			x = prev[x]
			if x == 0:
				break
		ans = ans[::-1]
		print(" ".join(list(map(str, ans))))

if __name__ == '__main__':
	main()

Fixed submission:
#ライブラリインポート
from collections import defaultdict
import bisect

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	S = list(input())
	nibu = []
	for i in range(N + 1):
		if S[i] == "0":
			nibu.append(i)

	prev = [None] * (N + 1)
	for i in range(1, N + 1):
		if S[i] == "0":
			s = bisect.bisect_left(nibu, i - M)
			x = nibu[s]
			if x != i:
				prev[i] = x
	# print(nibu)
	# print(prev)
	if prev[N] == None:
		print(-1)
	else:
		ans = []
		x = N
		while True:
			ans.append(x - prev[x])
			x = prev[x]
			if prev[x] == None:
				break
		if x == 0:
			ans = ans[::-1]
			print(" ".join(list(map(str, ans))))
		else:
			print(-1)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))


#処理内容
def main():
	N, T = getlist()
	K = []
	for i in range(N):
		A, B = getlist()
		K.append([A, B])
	DP = [[0 for i in range(T)] for j in range(N + 1)]
	for i in range(N):
		W, V = K[i][0], K[i][1]
		for j in range(T):
			if j < W:
				DP[i + 1][j] = DP[i][j]
			else:
				DP[i + 1][j] = max(DP[i][j], DP[i][j - W] + V)
	ans = DP[-1][-1]
	use = [0] * N
	Y = T - 1
	for i in range(N):
		if DP[N - i][Y] != DP[N - i - 1][Y]:
			use[N - 1 - i] = 1
			Y -= K[-1 - i][0]
	lis = []
	for i in range(N):
		if use[i] == 0:
			lis.append(K[i][1])
	lis = sorted(lis)
	ans += lis[-1]
	print(ans)



if __name__ == '__main__':
	main()

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))


#処理内容
def main():
	N, T = getlist()
	K = []
	for i in range(N):
		A, B = getlist()
		K.append([A, B])
	DP = [[0 for i in range(T)] for j in range(N + 1)]
	for i in range(N):
		W, V = K[i][0], K[i][1]
		for j in range(T):
			if j < W:
				DP[i + 1][j] = DP[i][j]
			else:
				DP[i + 1][j] = max(DP[i][j], DP[i][j - W] + V)
	ans = DP[-1][-1]
	use = [0] * N
	Y = T - 1
	for i in range(N):
		if DP[N - i][Y] != DP[N - i - 1][Y]:
			use[N - 1 - i] = 1
			Y -= K[-1 - i][0]
	lis = []
	for i in range(N):
		if use[i] == 0:
			lis.append(K[i][1])
	lis = sorted(lis)
	if len(lis) >= 1:
		ans += lis[-1]
	print(ans)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
#設定
import sys
input = sys.stdin.buffer.readline

from heapq import heappop, heappush

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	F = getlist()
	A = sorted(A)
	F = sorted(F)
	Q = []
	for i in range(N):
		heappush(Q, [ (-A[i]) * F[N - 1 - i], -A[i], -F[N - 1 - i]])
	#print(Q)
	#処理
	for i in range(K):
		if Q[0][0] == 0:
			break
		else:
			s, a, f = heappop(Q)
			a += 1
			s = -(a * f)
			heappush(Q, [s, a, f])
	#print(Q)
	ans = 0
	for i in range(N):
		ans = max(ans, -Q[i][0])
	print(ans)

if __name__ == '__main__':
	main()

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#二分探索基本形 L:リスト x:値 n:リスト長
def Binary_Search(A, F, N, K):
	#初期化
	left = 0
	right = 10 ** 12
	ans = INF
	
	#二分探索
	while left <= right:
		mid = (left + right) // 2
		cnt = 0
		for i in range(N):
			if A[i] * F[i] > mid:
				cnt += (A[i] - int(mid // F[i]))
		if cnt <= K:
			right = mid - 1
			ans = min(ans, mid)
		else:
			left = mid + 1

	return ans

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	F = getlist()
	A = sorted(A)
	F = sorted(F)[::-1]
	ans = Binary_Search(A, F, N, K)
	print(ans)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import queue

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.judge = "Yes"
		self.g = graph.graph
		self.Q = queue.Queue()
		self.dist = [INF] * N
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		self.dist[s] = 0
		self.Q.put(s)
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.Q.put(i)
					self.visit[i] = "Yes"
				else:
					if (self.dist[i] - self.dist[v]) % 2 == 0:
						self.judge = "No"

	def ans(self):
		return max(self.dist)

#処理内容
def main():
	#初期化
	N = int(input())
	L = []
	for i in range(N):
		S = list(input())
		L.append(S)
	G = Graph()
	for i in range(N):
		for j in range(i + 1, N):
			if L[i][j] == "1":
				G.add_edge(i, j)
				G.add_edge(j, i)
	#BFS
	jud = "Yes"
	A = - INF
	for i in range(N):
		bfs = BFS(G, i, N)
		A = max(bfs.ans(), A)
		if bfs.judge == "No":
			jud = "No"
	if jud == "No":
		print(-1)
	else:
		print(A + 1)

if __name__ == '__main__':
	main()

Fixed submission:
from collections import defaultdict
import queue

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.judge = "Yes"
		self.g = graph.graph
		self.Q = queue.Queue()
		self.dist = [INF] * N
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		self.dist[s] = 0
		self.Q.put(s)
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.Q.put(i)
					self.visit[i] = "Yes"
				else:
					if (self.dist[i] - self.dist[v]) % 2 == 0:
						self.judge = "No"

	def ans(self):
		return max(self.dist)

#処理内容
def main():
	#初期化
	N = int(input())
	L = []
	for i in range(N):
		S = list(input())
		L.append(S)
	G = Graph()
	for i in range(N):
		for j in range(i + 1, N):
			if L[i][j] == "1":
				G.add_edge(i, j)
				G.add_edge(j, i)
	#BFS
	jud = "Yes"
	A = - INF
	for i in range(N):
		bfs = BFS(G, i, N)
		A = max(bfs.ans(), A)
		if bfs.judge == "No":
			jud = "No"
	if jud == "No":
		print(-1)
	else:
		print(A + 1)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
def getlist():
	return list(map(int, input().split()))

a = int(input())
x = input()

if a >= 3200:
	print(s)
else:
	print("red")


Fixed submission:
def getlist():
	return list(map(int, input().split()))

a = int(input())
s = input()

if a >= 3200:
	print(s)
else:
	print("red")
Buggy python submission (verdict: Runtime Error):
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(N - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)

Fixed submission:
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(n - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)
Buggy python submission (verdict: Runtime Error):
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
S = getlist()
T = getlist()

L = [[1 for i in range(N + 1)] for j in range(M + 1)]
for i in range(1, N + 1):
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = max(L[j - 1][i - 1] * 2, L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1])

print(L[M][N] %  % 1000000007)

Fixed submission:
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
S = getlist()
T = getlist()

L = [[1 for i in range(N + 1)] for j in range(M + 1)]
for i in range(1, N + 1):
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007

print(L[M][N] % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
def getlist():
	return map(int, input().split())

L = []

H, W = getlist()
for i in range(H):
	S = list(input())
	L.append(S)

ans1 = [[0 for i in range(W)] for j in range(H)]
ans2 = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
	val = 0
	l = []
	for j in range(W):
		if L[i][j] == "#":
			for k in l:
				ans1[i][k] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans1[i][k] = val

for i in range(W):
	val = 0
	l = []
	for j in range(H):
		if L[j][i] == "#":
			for k in l:
				ans2[k][i] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans2[k][i] = val


ans = -1
for i in range(H):
	for j in range(W):
		x = ans1[i][j] + ans2[i][j] - 1
		if x > ans:
			ans = x

print(ans)

Fixed submission:
def getlist():
	return map(int, input().split())

L = []

H, W = getlist()
for i in range(H):
	S = list(input())
	L.append(S)

ans1 = [[0 for i in range(W)] for j in range(H)]
ans2 = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
	val = 0
	l = []
	for j in range(W):
		if L[i][j] == "#":
			for k in l:
				ans1[i][k] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans1[i][k] = val

for i in range(W):
	val = 0
	l = []
	for j in range(H):
		if L[j][i] == "#":
			for k in l:
				ans2[k][i] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans2[k][i] = val


ans = -1
for i in range(H):
	for j in range(W):
		x = ans1[i][j] + ans2[i][j] - 1
		if x > ans:
			ans = x

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import queue

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b, w):
        self.graph[a].append([b, w])

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
    def __init__(self, graph, N):
        self.g = graph.graph
        self.dist = [0] * (N + 1)
        self.visit = [0] * (N + 1)
        self.Q = queue.Queue()
        self.Q.put(1)

        while not self.Q.empty():
            v = self.Q.get()
            for i, w in self.g[v]:
            	if self.visit[i] == 0:
            		self.dist[i] = self.dist[v] + w

            	self.Q.put(i)
            	self.visit[i] = 1

    def weight(self):
        return self.dist

N = int(input())
G = Graph()
for i in range(N - 1):
	u, v, w = getlist()
	G.add_edge(u, v, w)
XX = BFS(G, W, N)
ans = XX.weight()

for i in range(1, N + 1):
	if ans[i] % 2 == 0:
		print(0)
	else:
		print(1)

Fixed submission:
from collections import defaultdict
import queue

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b, w):
        self.graph[a].append([b, w])

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
    def __init__(self, graph, N):
        self.g = graph.graph
        self.dist = [0] * (N + 1)
        self.visit = [0] * (N + 1)
        self.Q = queue.Queue()
        self.Q.put(1)

        while not self.Q.empty():
            v = self.Q.get()
            for i, w in self.g[v]:
            	if self.visit[i] == 0:
            		self.dist[i] = self.dist[v] + w
            		self.Q.put(i)
            		self.visit[i] = 1

    def weight(self):
        return self.dist

N = int(input())
G = Graph()
for i in range(N - 1):
    u, v, w = getlist()
    G.add_edge(u, v, w)
    G.add_edge(v, u, w)

XX = BFS(G, N)
ans = XX.weight()
for i in range(1, N + 1):
	if ans[i] % 2 == 0:
		print(0)
	else:
		print(1)
Buggy python submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))

ba = B - A 
if A % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if B % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a = A
b = B
a2 = ""
b2 = ""

if a == 0:
	a2 = "0"
else:
	while True:
		if a % 2 == 0:
			a2 += "0"
		else:
			a2 += "1"
		a = int(a // 2)
		if a == 1:
			a2 += "1"
			break
if b == 0:
	b2 = "0"
else:
	while True:
		if b % 2 == 0:
			b2 += "0"
		else:
			b2 += "1"
		b = int(b // 2)
		if b == 1:
			b2 += "1"
			break

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1
	else:
		c2 += 0

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1
	else:
		c2 += 0

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 0:
		c2 += 0
	else:
		c2 += 2 ** i

print(c2)


Fixed submission:
H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
print((H - h) * (W - w))
Buggy python submission (verdict: Runtime Error):
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import copy

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	B = copy.copy(A)
	num = 0
	n = K.bit_length()
	numL = [0] * 35
	for i in range(N):
		for j in range(35):
			if B[i] & 1 == 1:
				numL[j] += 1
			B[i] = B[i] >> 1
			if B[i] == 0:
				break
	for i in range(n):
		if 2 * numL[i] < N:
			num += 2 ** i
	ans = 0
	for i in range(N):
		ans += num ^ A[i]
	print(ans)

if __name__ == '__main__':
	main()

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	if K == 0:
		print(sum(A))
		sys.exit()	
	dp = [0] * 41
	j = 0
	while True:
		if K % 2 == 1:
			dp[-1 - j] = 1
		K = K // 2
		if K == 0:
			break
		j += 1
	#print(dp)

	p1 = [0] * 41
	p0 = [N] * 41
	for i in range(N):
		a = A[i]
		j = 0
		while True:
			if a % 2 == 1:
				p1[-1 - j] += 1
			a = a // 2
			if a == 0:
				break
			j += 1
	for i in range(41):
		p0[i] -= p1[i]
	#print(p1)
	#print(p0)

	#DP
	DP0 = [0] * 41
	DP1 = [0] * 41
	s = dp.index(1)
	DP0[0] = (2 ** 40) * p1[0]
	DP1[0] = (2 ** 40) * p1[0]
	for i in range(1, s):
		DP0[i] += DP0[i - 1] + (2 ** (40 - i)) * p1[i]
		DP1[i] += DP1[i - 1] + (2 ** (40 - i)) * p1[i]
	if s != 0:
		DP0[s] = DP0[s - 1] + (2 ** (40 - s)) * p0[s]
		DP1[s] = DP1[s - 1] + (2 ** (40 - s)) * p1[s]
	else:
		DP0[s] = (2 ** (40 - s)) * p0[s]
		DP1[s] = (2 ** (40 - s)) * p1[s]
	for i in range(s + 1, 41):
		if dp[i] == 1:
			DP0[i] = DP0[i - 1] + (2 ** (40 - i)) * p0[i]
			DP1[i] = max(DP1[i - 1] + (2 ** (40 - i)) * max(p0[i], p1[i]), DP0[i - 1] + (2 ** (40 - i)) * p1[i])
		else:
			DP0[i] = DP0[i - 1] + (2 ** (40 - i)) * p1[i]
			DP1[i] = DP1[i - 1] + (2 ** (40 - i)) * max(p0[i], p1[i])
	# print(DP0)
	# print(DP1)
	print(max(DP0[-1], DP1[-1]))

if __name__ == '__main__':
	main()