Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h, n = list(map(int, input().split()))

hp_and_magic = [list(map(int, input().split())) for _ in range(n)]

arr = [10 ** 9] * (h+1)
# arr[k] := hpがkの敵を倒すのに必要な最小魔力
arr[0] = 0
arr[1] = min([ele[1] for ele in hp_and_magic])

for i in range(2, h+1):
    # arr[i] = 10 ** 9
    for ele in hp_and_magic:
        if i-ele[0] >= 0:
            arr[i] = min(arr[i], arr[i-ele[0]] + ele[1])
        else:
            arr[i] = min(arr[i], ele[1])

print(arr[h])

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

hp_and_magic = [list(map(int, input().split())) for _ in range(n)]

arr = [10 ** 9] * (h+1)
# arr[k] := hpがkの敵を倒すのに必要な最小魔力
arr[0] = 0
arr[1] = min([ele[1] for ele in hp_and_magic])

for i in range(2, h+1):
    # arr[i] = 10 ** 9
    for ele in hp_and_magic:
        if i-ele[0] >= 0:
            arr[i] = min(arr[i], arr[i-ele[0]] + ele[1])
        else:
            arr[i] = min(arr[i], ele[1])

print(arr[h])
Buggy python submission (verdict: Runtime Error):
youbi = ['SUN','MON','TUE','WED','THU','FRI','SAT']
y = input()

for i in range(1, 7):
  if y = youbi[i]:
    print(7-i)

Fixed submission:
youbi = ['SUN','MON','TUE','WED','THU','FRI','SAT']
y = input()

for i in range(7):
  if y == youbi[i]:
    print(7-i)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
if n % 2 == 0 and s[:n//2] == s[s//2:] :
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())
s = input()
if n % 2 == 0 and s[:n//2] == s[n//2:] :
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
# 2020年6月17日

# 修行という概念がない場合、消化コストを大から小に並べて食べにくさを小から大に並べて順にマッチングさせれば良い。
# そうでない状態から2つを交換したときに最大値が下がる方向にしか行かないため。

# 修行をするなら最大値を引き下げるところに修行をするのが最適なので、
# 無修行状態の結果を優先度付きキューに入れる→K回最大値を取り出してコストを引いて再投入→を繰り返す。
# 本当か? やってるうちに最適な組み合わせが変わらないか? →変わらない。食べにくさを昇順に並べたときに消化コストが降順になるのが最善手なので。
# あとKが大きいのでこれだと間に合わない。

# 決め打ち二分探索か?
# あ、それだわ。

n, k = map(int, input().split())
people = list(map(int, input().split()))
foods = list(map(int, input().split()))

# 食べにくさは昇順（小から大）、人間は降順（大から小）
foods.sort()
people.sort(reverse=True)

def is_valid(time):
    # k回以下の修行で実現可能か

    n_train = 0
    for i in range(n):
        if foods[i] * people[i] <= time:
            pass
        else:
            n_train += people[i] - time // foods[i]
    
    return n_train <= k


time_ok = 2 * 10 ** 12
time_ng = -1  # 計算上、is_valid(-1) = Trueになることはあるが、二分探索の方法から言ってこれで正しいはず

while (abs(time_ok - time_ng > 1)):
    mid = (time_ok + time_ng) // 2
    if is_valid(mid):
        time_ok = mid
    else:
        time_ng = mid

print(time_ok)


Fixed submission:
# 2020年6月17日

# 修行という概念がない場合、消化コストを大から小に並べて食べにくさを小から大に並べて順にマッチングさせれば良い。
# そうでない状態から2つを交換したときに最大値が下がる方向にしか行かないため。

# 修行をするなら最大値を引き下げるところに修行をするのが最適なので、
# 無修行状態の結果を優先度付きキューに入れる→K回最大値を取り出してコストを引いて再投入→を繰り返す。
# 本当か? やってるうちに最適な組み合わせが変わらないか? →変わらない。食べにくさを昇順に並べたときに消化コストが降順になるのが最善手なので。
# あとKが大きいのでこれだと間に合わない。

# 決め打ち二分探索か?
# あ、それだわ。

n, k = map(int, input().split())
people = list(map(int, input().split()))
foods = list(map(int, input().split()))

# 食べにくさは昇順（小から大）、人間は降順（大から小）
foods.sort()
people.sort(reverse=True)

def is_valid(time):
    # k回以下の修行で実現可能か

    n_train = 0
    for i in range(n):
        if foods[i] * people[i] <= time:
            pass
        else:
            n_train += people[i] - time // foods[i]
    
    return n_train <= k


time_ok = 2 * 10 ** 12
time_ng = -1  # 計算上、is_valid(-1) = Trueになることはあるが、二分探索の方法から言ってこれで正しいはず

while (abs(time_ok - time_ng > 1)):
    mid = (time_ok + time_ng) // 2
    if is_valid(mid):
        time_ok = mid
    else:
        time_ng = mid

print(time_ok)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
print(sum(a[i] == b[i] for i in range[3]))

Fixed submission:
a = input()
b = input()
print(sum(a[i] == b[i] for i in range(3)))
Buggy python submission (verdict: Time Limit Exceeded):
# 久々の幅優先探索……

n, k = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(n-1)]

def add_edge(u, v ):
	G[u].append(v)
	G[v].append(u)

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1)

n_colors = [-1] * n
n_colors[0] = k
queue = [0]

count = 0
for v in G[0]:
	queue.append(v)
	n_colors[v] = k - count - 1 #※
	count += 1

while(len(queue) > 0):
	now = queue[0]

	del queue[0]

	count = 0
	for v in G[now]:
		if n_colors[v] >= 0:
			pass
		else:
			queue.append(v)
			n_colors[v] = k - count - 2
			count += 1

			if n_colors[v] == 0:
				print(0)
				exit()

ans = 1
for i in range(n):
	ans *= n_colors[i]
	ans %= (10 ** 9 + 7)

print(ans)


Fixed submission:
# 久々の幅優先探索……

import queue

n, k = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(n-1)]

def add_edge(u, v ):
	G[u].append(v)
	G[v].append(u)

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1)

q = queue.Queue()
q.put(0)

n_colors = [-1] * n
n_colors[0] = k

count = 0
for v in G[0]:
	q.put(v)
	n_colors[v] = k - count - 1 #※
	count += 1

while(q.qsize() > 0):
	now = q.get()
	count = 0
	for v in G[now]:
		if n_colors[v] >= 0:
			pass
		else:
			q.put(v)
			n_colors[v] = k - count - 2
			count += 1

			if n_colors[v] == 0:
				print(0)
				exit()

ans = 1
for i in range(n):
	ans *= n_colors[i]
	ans %= (10 ** 9 + 7)

print(ans)
Buggy python submission (verdict: Runtime Error):
x, a = list(map(inte, input().split()))
if x < a:
  print (0)
else:
  print(10)

Fixed submission:
x, a = list(map(int, input().split()))
if x < a:
  print (0)
else:
  print(10)
Buggy python submission (verdict: Runtime Error):
a,b,c = list(map(input.split() ))
print (min(a+b, b+c, c+a))

Fixed submission:
a,b,c = list(map(int, input().split() ))
print (min(a+b, b+c, c+a))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split() ))
broken = [int(input()) for _ in range(m)]

mod = 10**9+7

num_way = [0] * (n+1)
num_way[0] = 1
if 1 in broken:
	num_way[1] = 0
else:
	num_way[1] = 1

for i in range(2, (n+1)):
	if i in broken:
		num_way[i] = 0
	else:
		num_way[i] = (num_way[i-1] + num_way[i-2]) % mod

print (num_way[n])

Fixed submission:
n, m = list(map(int, input().split() ))
broken = [int(input()) for _ in range(m)]
broken.append(-1) #番兵
broken_idx = 0

mod = 10**9+7

num_way = [0] * (n+1)
num_way[0] = 1
if broken[broken_idx] == 1:
	num_way[1] = 0
	broken_idx += 1
else:
	num_way[1] = 1

for i in range(2, (n+1)):
	if broken[broken_idx] == i:
		num_way[i] = 0
		broken_idx += 1
	else:
		num_way[i] = (num_way[i-1] + num_way[i-2]) % mod

print (num_way[n])
Buggy python submission (verdict: Time Limit Exceeded):
# L 以下の数のうち最大の2のべき数をtとする。t = 2 ** k とする。
# k は len(L)-1だね。

# a+bがt未満： 3 ** k 通り
# a+bがt以上L以下： いろいろ複雑！

L = input()
lenL = len(L) 
ans = 3 ** (lenL - 1)
mod = 10 ** 9 + 7

num_one_leftside = 1
for i in range(1, lenL):
	if L[i] == '1':
		ans += 2 ** num_one_leftside * 3 ** (lenL - i - 1)
		ans %= mod

#		print (num_one_leftside ,  (lenL - i - 1))
		num_one_leftside += 1

ans += 2 ** num_one_leftside 
ans %= mod

print(ans)

Fixed submission:
# L 以下の数のうち最大の2のべき数をtとする。t = 2 ** k とする。
# k は len(L)-1だね。

# a+bがt未満： 3 ** k 通り
# a+bがt以上L以下： いろいろ複雑！

L = input()
lenL = len(L) 
ans = 3 ** (lenL - 1)
mod = 10 ** 9 + 7

pow_2 = [1] * (lenL+1)
pow_3 = [1] * (lenL+1)

for i in range(1, lenL+1):
	pow_2[i] = pow_2[i-1] * 2 % mod
	pow_3[i] = pow_3[i-1] * 3 % mod

num_one_leftside = 1
for i in range(1, lenL):
	if L[i] == '1':
		ans += pow_2[num_one_leftside] * pow_3[lenL - i - 1]
		ans %= mod

#		print (num_one_leftside ,  (lenL - i - 1))
		num_one_leftside += 1

ans += pow_2[num_one_leftside]
ans %= mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# L 以下の数のうち最大の2のべき数をtとする。t = 2 ** k とする。
# k は len(L)-1だね。

# a+bがt未満： 3 ** k 通り
# a+bがt以上L以下： いろいろ複雑！

L = input()
lenL = len(L) 
ans = 3 ** (lenL - 1)
mod = 10 ** 9 + 7

num_one_leftside = 1
for i in range(1, len(L)):
	if L[i] == '1':
		ans += 2 ** num_one_leftside * 3 ** (lenL - i - 1)
		ans %= mod

#		print (num_one_leftside ,  (lenL - i - 1))
		num_one_leftside += 1

ans += 2 ** num_one_leftside 
ans %= mod

print(ans)

Fixed submission:
# L 以下の数のうち最大の2のべき数をtとする。t = 2 ** k とする。
# k は len(L)-1だね。

# a+bがt未満： 3 ** k 通り
# a+bがt以上L以下： いろいろ複雑！

L = input()
lenL = len(L) 
ans = 3 ** (lenL - 1)
mod = 10 ** 9 + 7

pow_2 = [1] * (lenL+1)
pow_3 = [1] * (lenL+1)

for i in range(1, lenL+1):
	pow_2[i] = pow_2[i-1] * 2 % mod
	pow_3[i] = pow_3[i-1] * 3 % mod

num_one_leftside = 1
for i in range(1, lenL):
	if L[i] == '1':
		ans += pow_2[num_one_leftside] * pow_3[lenL - i - 1]
		ans %= mod

#		print (num_one_leftside ,  (lenL - i - 1))
		num_one_leftside += 1

ans += pow_2[num_one_leftside]
ans %= mod

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

Fixed submission:
a, b = list(map(int, input().split()))
print((a*3+b)//2)
Buggy python submission (verdict: Runtime Error):
# 木の深さ優先探索

def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])


Fixed submission:
# 木の深さ優先探索
import sys

sys.setrecursionlimit(100000+10)


def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])

Buggy python submission (verdict: Runtime Error):
# 木の深さ優先探索

def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])


n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])


Fixed submission:
# 木の深さ優先探索
import sys

sys.setrecursionlimit(100000+10)


def add_edge(u, v, distance ):
	G[u].append([v, distance])
	G[v].append([u, distance])

def dfs(vertex, distance_from_start):
	global colors

	colors[vertex] = distance_from_start % 2

	for info in G[vertex]:
		v = info[0]
		if colors[v] >= 0: 
			#探索済み
			pass
		else:
			dfs(v, distance_from_start + info[1])

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
	add_edge(edge[0]-1, edge[1]-1, edge[2])

colors = [-1] * n
colors[0] = 0

dfs(0, 0)

for i in range(n):
	print(colors[i])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c, n = list(map(int, input().split() ))

ans = 0
for i in range(3001):
	for j in range(3001):
		rest = n - a*i - b*j
		if rest >= 0 and rest % c == 0:
			ans += 1

print(ans)

Fixed submission:
a,b,c, n = list(map(int, input().split() ))

ans = 0
for i in range(3001):
	for j in range(3001):
		rest = n - a*i - b*j
		if rest >= 0 and rest % c == 0:
			ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 長い間考えて分からなかったけど、ようやく方針が分かった。
# 始点を複数にした幅優先探索
# 距離1の点をキューに入れる、
# 距離1の点を出しながら距離2の点をキューに入れる、
# 以下略。でできるじゃん。

h, w = list(map(int, input().split()))

masu = [input() for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

distance = [[-1 for _ in range(w)] for _ in range(h)]

from collections import deque

queue = deque([])
for i in range(h):
    for j in range(w):
        if masu[i][j] == '#':
            distance[i][j] = 0
            queue.append((i, j))

ans = 0
while True:
    if len(queue) == 0:
        break
    now = queue.popleft()
    now_h = now[0]
    now_w = now[1]
    now_distance = distance[now_h][now_w]
    # print(now_h, now_w)

    for i in range(4):
        next_h = now_h + dx[i]
        next_w = now_w + dy[i]
        if not (0 <= next_h <= h-1 and 0 <= next_w <= w-1):
            continue
        if distance[next_h][next_w] == -1:
            distance[next_h][next_w] = now_distance + 1
            queue.append((next_h, next_w))
            ans = now_distance + 1
            # print("appended {} {}".format(next_h, next_w))

print(ans)


Fixed submission:
# 長い間考えて分からなかったけど、ようやく方針が分かった。
# 始点を複数にした幅優先探索
# 距離1の点をキューに入れる、
# 距離1の点を出しながら距離2の点をキューに入れる、
# 以下略。でできるじゃん。

h, w = list(map(int, input().split()))

masu = [input() for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

distance = [[-1 for _ in range(w)] for _ in range(h)]

from collections import deque

queue = deque([])
for i in range(h):
    for j in range(w):
        if masu[i][j] == '#':
            distance[i][j] = 0
            queue.append((i, j))

ans = 0
while True:
    if len(queue) == 0:
        break
    now = queue.popleft()
    now_h = now[0]
    now_w = now[1]
    now_distance = distance[now_h][now_w]
    # print(now_h, now_w)

    for i in range(4):
        next_h = now_h + dx[i]
        next_w = now_w + dy[i]
        if not (0 <= next_h <= h-1 and 0 <= next_w <= w-1):
            continue
        if distance[next_h][next_w] == -1:
            distance[next_h][next_w] = now_distance + 1
            queue.append((next_h, next_w))
            ans = now_distance + 1
            # print("appended {} {}".format(next_h, next_w))

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
mod = 998244353
# DP ナップサックぽいやつ
# DP[i][j] := a_0からa_iまでの部分集合で和がjになるものの個数
# 配るDPの方が場合分けがなくて簡潔に書ける 計算量増えるかも
# DP[i-1][j]→DP[i][j]とDP[i][j + a_i ]に配る

aaa = [int(input()) for _ in range(N)]
sum_aaa = sum(aaa)

sum_now = 0
DP = [[0] * (sum_aaa+1) for i in range(N)]
DP2 = [[0] * (sum_aaa+1) for i in range(N)]

a = aaa[0]
DP[0][0] = 2
DP[0][a] = 1

DP2[0][0] = 1
DP2[0][a] = 1

sum_now += a

for i in range(1, N):
	a = aaa[i]
	sum_now += a
	for j in range(sum_now + 1):

		if (j >= a):
			DP[i][j] = DP[i-1][j]*2 + DP[i-1][j-a]
		else:
			DP[i][j] = DP[i-1][j]*2

		while (DP[i][j] > mod):
			DP[i][j] -= mod

	for j in range(min(sum_now + 1, int(sum_aaa /2)+1)):
		if (j >= a):
			DP2[i][j] = DP2[i-1][j] + DP2[i-1][j-a]
		else:
			DP2[i][j] = DP2[i-1][j]

		while (DP2[i][j] > mod):
			DP2[i][j] -= mod

# print(DP2)
minimum_invalid_length = int((sum_now+1)//2)
num_too_long = sum (DP[N-1][minimum_invalid_length:])
if (sum_aaa %2 == 0):
	num_too_long -= DP2[N-1][int(sum_aaa /2)]
# print(num_too_long)
# print(sum(aaa))
print((3** N - num_too_long * 3) % mod )


Fixed submission:
N = int(input())
S = input()

# 白→黒　が許容される状態

ans = N + 1

# 所与→全黒
ans = S.count(".")
prev = ans

for i in range(N):
	if S[i] == "#":
		now = prev + 1
	else:
		now = prev - 1


	if now < ans:
		ans = now
	prev = now

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int(), input().split())
print("Yes" if (a-c)*(b-c) < 0 else "No")


Fixed submission:
a,b,c = map(int, input().split())
print("Yes" if (a-c)*(b-c) < 0 else "No")
Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
s = input()

end = []
start = []

if s[0] == "1":
	start.append(0)
	end.append(0)
else:
	#仮想的な1の区間を作る
	start.append(0)
	end.append(0)

for i in range(1, n-1):
	if s[i-1] == "0" and s[i] == "1":
		start.append(i)
	if s[i] == "1" and s[i+1] == "0":
		end.append(i)

if s[-1] == "1":
	start.append(n-1)
	end.append(n-1)
else:
	#仮想的な1の区間を作る
	start.append(n-1)
	end.append(n-1)

ans = 0

"""print(start, end, ans)
print(len(start), len(end), ans)
"""
for j in range(len(start) - k):
	temp = end[j+k] - start[j] + 1 
	if temp > ans:
		ans = temp

if len(start) <= k:
	ans = n

print(ans)


Fixed submission:
n, k = list(map(int, input().split()))
s = input()

end = []
start = []

if s[0] == "1":
	start.append(0)
else:
	#仮想的な1の区間を作る
	start.append(0)
	end.append(0)

for i in range(n-1):
	if s[i] == "1" and s[i+1] == "0":
		end.append(i)
for i in range(1, n):
	if s[i-1] == "0" and s[i] == "1":
		start.append(i)

if s[-1] == "1":
	end.append(n-1)
else:
	#仮想的な1の区間を作る
	start.append(n-1)
	end.append(n-1)

ans = 0

"""print(start, end, ans)
print(len(start), len(end), ans)"""

for j in range(len(start) - k):
	temp = end[j+k] - start[j] + 1 
	if temp > ans:
		ans = temp

if len(start) <= k:
	ans = n

print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
s = input()

end = []
start = []

if s[0] == "1":
	start.append(0)
else:
	#仮想的な1の区間を作る
	start.append(0)
	end.append(0)


for i in range(1, n-1):
	if s[i-1] == "0" and s[i] == "1":
		start.append(i)
	if s[i] == "1" and s[i+1] == "0":
		end.append(i)

if s[-1] == "1":
	end.append(n-1)
else:
	#仮想的な1の区間を作る
	start.append(n-1)
	end.append(n-1)

ans = 0
for j in range(len(start) - k):
	temp = end[j+k] - start[j] + 1 
	if temp > ans:
		ans = temp

if len(start) <= k:
	ans = n

print(ans)


Fixed submission:
n, k = list(map(int, input().split()))
s = input()

end = []
start = []

if s[0] == "1":
	start.append(0)
else:
	#仮想的な1の区間を作る
	start.append(0)
	end.append(0)

for i in range(n-1):
	if s[i] == "1" and s[i+1] == "0":
		end.append(i)
for i in range(1, n):
	if s[i-1] == "0" and s[i] == "1":
		start.append(i)

if s[-1] == "1":
	end.append(n-1)
else:
	#仮想的な1の区間を作る
	start.append(n-1)
	end.append(n-1)

ans = 0

"""print(start, end, ans)
print(len(start), len(end), ans)"""

for j in range(len(start) - k):
	temp = end[j+k] - start[j] + 1 
	if temp > ans:
		ans = temp

if len(start) <= k:
	ans = n

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# PDFで解法が4つも書いてある。これはその最初の解法

x,y,z,k =  list(map(int, input().split() ))

aa = list(map(int, input().split() ))
bb = list(map(int, input().split() ))
cc = list(map(int, input().split() ))

aa.sort(reverse = True)
bb.sort(reverse = True)
cc.sort(reverse = True)
# 降順＝大きい方から順

ab = []
for i in aa:
	for j in bb:
		ab.append(i + j)

# ab = [i + j for i in aa for j in bb]
# appendを使うと遅いので、二重の内包記法を使う 
# 外側でaaの要素、内側でbbの要素が動いていく。今回はどっちでも良いけど。
ab.sort(reverse = True)

max_len = min(k, len(ab))
abc = []
for i in ab[:max_len]:
	for j in cc:
		abc.append(i + j)

# abc = [i + j for i in ab[:max_len] for j in cc]
abc.sort(reverse = True)

for i in range(k):
	print(abc[i])


Fixed submission:
# PDFで解法が4つも書いてある

x,y,z,k =  list(map(int, input().split() ))

aa = list(map(int, input().split() ))
bb = list(map(int, input().split() ))
cc = list(map(int, input().split() ))

aa.sort(reverse = True)
bb.sort(reverse = True)
cc.sort(reverse = True)
# 降順＝大きい方から順

ab = [i + j for i in aa for j in bb]
# appendを使うと遅いので、二重の内包記法を使う 
# 外側でaaの要素、内側でbbの要素が動いていく。今回はどっちでも良いけど。
ab.sort(reverse = True)

max_len = min(k, len(ab))
abc = [i + j for i in ab[:max_len] for j in cc]
abc.sort(reverse = True)

for i in range(k):
	print(abc[i])
Buggy python submission (verdict: Runtime Error):
a,b,c =  map(int, input().split())
if a== b and b == c:
  print(Yes)
else:
  print(No)

Fixed submission:
a,b,c =  map(int, input().split())
if a== b and b == c:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
# 幅優先探索か深さ優先探索で、上下左右の隣接と異なる色ならば、連続する1つの領域とする
# 各領域ごとに、白マス数×黒マス数を計算し、その合計が答え

h, w = list(map(int, input().split()))
masu = [input() for _ in range(h)]
visited = [[False for _ in range(w)] for _ in range(h)]
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

# とりあえず周囲の番兵は使わずに書いてみよう……

# 再帰関数の呼び出し回数が多くなる時はこれが必要！！無いとruntime errorになる。
import sys
sys.setrecursionlimit(10)

def dfs(hi, wi, white, black):
    global colors
    global dx, dy
    global visited

    # print(hi, wi)

    visited[hi][wi] = True
    if masu[hi][wi] == '.':
        white += 1
    if masu[hi][wi] == '#':
        black += 1

    for neighbor in zip(dx, dy):
        h_new = hi + neighbor[0]
        w_new = wi + neighbor[1]
        # print("new: " , h_new, w_new)
        if 0 <= h_new <= h-1 and 0 <= w_new <= w-1:
            if not visited[h_new][w_new]:
                if masu[hi][wi] != masu[h_new][w_new]:
                    white, black = dfs(h_new, w_new, white, black)
    
    return white, black

ans = 0
for hi in range(h):
    for wi in range(w):
        if not visited[hi][wi]:
            white, black = dfs(hi, wi, 0, 0)
            ans += white * black

print(ans)


Fixed submission:
# 幅優先探索か深さ優先探索で、上下左右の隣接と異なる色ならば、連続する1つの領域とする
# 各領域ごとに、白マス数×黒マス数を計算し、その合計が答え

h, w = list(map(int, input().split()))
masu = [input() for _ in range(h)]
visited = [[False for _ in range(w)] for _ in range(h)]
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

# とりあえず周囲の番兵は使わずに書いてみよう……

# 再帰関数の呼び出し回数が多くなる時はこれが必要！！無いとruntime errorになる。
import sys
sys.setrecursionlimit(400*400 + 10)

def dfs(hi, wi, white, black):
    global colors
    global dx, dy
    global visited

    # print(hi, wi)

    visited[hi][wi] = True
    if masu[hi][wi] == '.':
        white += 1
    if masu[hi][wi] == '#':
        black += 1

    for neighbor in zip(dx, dy):
        h_new = hi + neighbor[0]
        w_new = wi + neighbor[1]
        # print("new: " , h_new, w_new)
        if 0 <= h_new <= h-1 and 0 <= w_new <= w-1:
            if not visited[h_new][w_new]:
                if masu[hi][wi] != masu[h_new][w_new]:
                    white, black = dfs(h_new, w_new, white, black)
    
    return white, black

ans = 0
for hi in range(h):
    for wi in range(w):
        if not visited[hi][wi]:
            white, black = dfs(hi, wi, 0, 0)
            ans += white * black

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n, start = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = abs(start - x[0])
for i in range(1, n):
	dist = abs(start - x[i])
	ans = math.gcd(ans, dist)
print(ans)

Fixed submission:
# import math
import fractions
n, start = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = abs(start - x[0])
for i in range(1, n):
	dist = abs(start - x[i])
	# ans = math.gcd(ans, dist)
	# Python 3.5以上では正解になるはずだが、AtCoderでは3.4.3なのでmath.gcdが使えず、ランタイムエラーになる
	# 3.4以前ではfractions.gcdを使う必要がある。fractions.gcdは3.5以降では非推奨である
	ans = fractions.gcd(ans, dist)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
l = len(s)

first = ''
for i in range(l):
	if s[i] != '1':
		first = s[i]
		pos = i
		break

print('1' if k <= pos else first)


Fixed submission:
s = input()
k = int(input())
l = len(s)

first = ''
pos = l
for i in range(l):
	if s[i] != '1':
		first = s[i]
		pos = i
		break

print('1' if k <= pos else first)