Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

if max(a) < k:
    print('IMPOSSIBLE')
elif k in a:
    print('POSSIBLE')
else:
    for i in a:
        if i %2 == 0:
            flag_e = True
        else:
            flag_o = True
    if flag_e is True and flag_o is True:
        for i in a:
            if i == min(a):
                continue
            else:
                if i %2 == 0:
                    if (i-min(a)) % min(a) != 0:
                        print('POSSIBLE')
                        exit()
                    else:
                        continue
                else:
                    if i % min(a) != 0:
                        print('POSSIBLE')
                        exit()
                    else:
                        continue
        print('IMPOSSIBLE')
        exit()
    elif flag_e is True:
        if k %2 == 0:
            print('POSSIBLE')
            exit()
        else:
            print('IMPOSSIBLE')
            exit()
    else:
        for i in a:
            if i == min(a):
                continue
            else:
                if i % min(a) != 0:
                    print('POSSIBLE')
                    exit()
                else:
                    continue
        print('IMPOSSIBLE')
        exit()


Fixed submission:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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

b = gcd_list(a)
if max(a) >= k and k % b == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

ans = 0

sum_list1 = np.zeros(n)
to_minus1 = np.zeros(n)
to_plus1 = np.zeros(n)
s = 0
for i in range(n):
    s += a[i]
    sum_list1[i] += s
    to_minus1[i] = sum_list1[i] + 1
    to_plus1[i] = sum_list1[i] - 1


def check(sum_list, to_minus, to_plus, t, ans):
    for i in range(n):
        if (i+t) % 2 == 0:
            if to_minus[i] <= 0:
                continue
            else:
                hiku = to_minus[i]
                to_minus[i::] -= hiku
                to_plus[i::] -= hiku
                ans += abs(hiku)
        else:
            if to_plus[i] >= 0:
                continue
            else:
                tasu = abs(to_plus[i])
                to_minus[i::] += tasu
                to_plus[i::] += tasu
                ans += abs(tasu)
    return ans

t = np.copy(to_minus1)
u = np.copy(to_plus1)

ans1 = check(sum_list1, to_minus1, to_plus1, 0, 0)
ans2 = check(sum_list1, t, u, 1, 0)

print(int(min(ans1, ans2)))


Fixed submission:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

def to_minus_one(num):
    return -1 - num

def to_plus_one(num):
    return 1 - num

s_list = np.zeros(n)
s = 0
for i in range(n):
    s += a[i]
    s_list[i] += s


def cal(sum_list, t, ans):
    hoge = 0
    for i in range(n):
        sum_list[i] += hoge
        if (i+t) % 2 == 0:
            if sum_list[i] >= 0:
                hiku = to_minus_one(sum_list[i])
                hoge += hiku
                ans += abs(hiku)
            else:
                continue
        else:
            if sum_list[i] <= 0:
                tasu = to_plus_one(sum_list[i])
                hoge += tasu
                ans += abs(tasu)
    return ans

q = np.copy(s_list)
w = np.copy(s_list)
num1 = cal(q, 0, 0)
num2 = cal(w, 1, 0)

print(int(min(num1, num2)))
Buggy python submission (verdict: Runtime Error):
a, b = map(input())
if a == 'H':
    if b == 'H':
        print('H')
    else:
        print('D')
else:
    if b == 'H':
        print('D')
    else:
        print('H')

Fixed submission:
a, b = input().split()
if a == 'H':
    if b == 'H':
        print('H')
    else:
        print('D')
else:
    if b == 'H':
        print('D')
    else:
        print('H')
Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

while li[0] != 1:
    for i in range(len(li)-1):
        if li[i] >= 3 and li[i] % 2 == 0:
            li[i] = 2
        elif li[i] >= 3 and li[i] % 2 != 0:
            li[i] = 1

        if li[i+1] == 2 and li[i] == 2:
            li[i+1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)

print(len(li))




Fixed submission:
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

for j in range(2):
    for i in range(len(li) - 1):
        if li[i] >= 3 and li[i] % 2 == 0:
            li[i] = 2
        elif li[i] >= 3 and li[i] % 2 != 0:
            li[i] = 1

        if li[i + 1] == 2 and li[i] == 2:
            li[i + 1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)


print(len(li))

Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

while li[0] != 1:
    for i in range(len(li)-1):
        if li[i] >= 3:
            li[i] -= 2
        if li[i+1] == 2 and li[i] == 2:
            li[i+1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)

print(len(li))




Fixed submission:
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

for j in range(2):
    for i in range(len(li) - 1):
        if li[i] >= 3 and li[i] % 2 == 0:
            li[i] = 2
        elif li[i] >= 3 and li[i] % 2 != 0:
            li[i] = 1

        if li[i + 1] == 2 and li[i] == 2:
            li[i + 1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)


print(len(li))
Buggy python submission (verdict: Runtime Error):
s = list(input())

if s[1] == '+':
  print(s[0]+s[2])
else:
  print(s[0]-s[2])

Fixed submission:
s = list(input().split())

if s[1] == '+':
    print(int(s[0])+int(s[2]))
else:
    print(int(s[0])-int(s[2]))
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil


n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        if a == b:
            x = max(votes)
            votes = [x, x]
        else:
            num = min(ceil(votes[0]/a), ceil(votes[1]/b))
            for i in range(num, 10000000):
                x = a * i
                y = b * i
                if x >= votes[0] and y >= votes[1]:
                    votes = [x, y]
                    break

print(sum(votes))


Fixed submission:
n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        num = max(-(-votes[0]//a), -(-votes[1]//b))
        x = a * num
        y = b * num
        votes = [x, y]
print(sum(votes))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

print((a+b)*h)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())

print((a+b)*c//2)
Buggy python submission (verdict: Runtime Error):
a = input()
ans = 0
for i in range(2**(len(a)-1)):
    b = format(i, 'b').zfill((len(a)-1))
    li = []
    num = [a[0]]
    for i in range(len(b)):
        if b[i] == '1':
            ans += int(''.join(num))
            num = [a[i+1]]
        else:
            num.append(a[i+1])
    ans += int(''.join(num))

print(ans)

Fixed submission:
a = input()
if len(a) == 1:
    print(int(a))
    exit()
ans = 0
for i in range(2**(len(a)-1)):
    b = format(i, 'b').zfill((len(a)-1))
    li = []
    num = [a[0]]
    for i in range(len(b)):
        if b[i] == '1':
            ans += int(''.join(num))
            num = [a[i+1]]
        else:
            num.append(a[i+1])
    ans += int(''.join(num))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys


def lcm(a, b):
  return a * b // math.gcd(a, b)


input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
  LCM = lcm(LCM, x)
for x in A:
  ans += LCM // x
  ans %= MOD

print(ans)

Fixed submission:
import math
import sys


def lcm(a, b):
  return a * b // math.gcd(a, b)


input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
  LCM = lcm(LCM, x)
for x in A:
  ans += LCM // x

print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys


def lcm(a, b):
  return a * b // math.gcd(a, b)


input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
  LCM = lcm(LCM, x)
for x in A:
  ans += LCM // x
  ans %= MOD

print(ans)

Fixed submission:
import math
import sys


def lcm(a, b):
  return a * b // math.gcd(a, b)


input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
  LCM = lcm(LCM, x)
for x in A:
  ans += LCM // x

print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

ans = 0
D = 0
while(D <= X):
    D += L[ans]
    ans += 1

print(ans)

Fixed submission:
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

ans = 1
ct = 0
D = 0
while True:
    D += L[ct]
    if D <= X:
        ct += 1
        ans += 1
    else:
        break
    if ct > N - 1:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
BC = [0]*M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))

BC.sort(key=lambda x: x[1], reverse=True)

idx, flg = 0, 0
for i in BC:
    B, C = i
    for i in range(B):
        if A[idx] >= C:
            flg = 1
            break
        else:
            A[idx] = C
            idx += 1
            B -= 1
            if B == 0:
                break
    if flg:
        break

print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
BC = [0]*M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))

BC.sort(key=lambda x: x[1], reverse=True)

idx, flg = 0, 0
for i in BC:
    B, C = i
    for i in range(B):
        if idx > N-1:
            flg = 1
            break
        if A[idx] >= C:
            flg = 1
            break
        else:
            A[idx] = C
            idx += 1
            B -= 1
            if B == 0:
                break
    if flg:
        break

print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
for _ in range(M):
    B, C = map(int, input().split())
    for i in range(N):
        if A[i] >= C:
            A.sort()
            break
        else:
            A[i] = C
            B -= 1
        if B == 0:
            A.sort()
            break

print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
BC = [0]*M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))

BC.sort(key=lambda x: x[1], reverse=True)

idx, flg = 0, 0
for i in BC:
    B, C = i
    for i in range(B):
        if idx > N-1:
            flg = 1
            break
        if A[idx] >= C:
            flg = 1
            break
        else:
            A[idx] = C
            idx += 1
            B -= 1
            if B == 0:
                break
    if flg:
        break

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dis = [0]*N
G = [[] for _ in range(N)]
for _ in range(N-1):
	u, v, w = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))

queue = [0]
V = [0]*N
idx = 1

while queue:
	u = queue.pop()
	for i in G[u]:
		v, w = i
		if v not in V:
			V[idx] = v
			idx += 1
			queue.append(v)
			dis[v] = dis[u] + w
		if idx == N:
			break
	if idx == N:
		break

for i in dis:
	print(1 if i % 2 else 0)

Fixed submission:
N = int(input())
INF = float('inf')
dis = [INF]*N
dis[0] = 0
G = [[] for _ in range(N)]
for _ in range(N-1):
	u, v, w = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))

queue = [0]

while queue:
	u = queue.pop()
	for v, w in G[u]:
		if dis[v] > dis[u] + w:
			queue.append(v)
			dis[v] = dis[u] + w

for i in dis:
	print(i % 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dis = [0]*N
G = [[] for _ in range(N)]
for _ in range(N-1):
	u, v, w = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))

queue = [0]
V = [0]*N
idx = 1

while queue:
	u = queue.pop()
	for i in G[u]:
		v, w = i
		if v not in V:
			V[idx] = v
			idx += 1
			queue.append(v)
			dis[v] = dis[u] + w

for i in dis:
	print(1 if i % 2 else 0)

Fixed submission:
N = int(input())
INF = float('inf')
dis = [INF]*N
dis[0] = 0
G = [[] for _ in range(N)]
for _ in range(N-1):
	u, v, w = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))

queue = [0]

while queue:
	u = queue.pop()
	for v, w in G[u]:
		if dis[v] > dis[u] + w:
			queue.append(v)
			dis[v] = dis[u] + w

for i in dis:
	print(i % 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dis = [0]*N
G = [[] for _ in range(N)]
for _ in range(N-1):
	u, v, w = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))

queue = [0]
V = [0]*N
idx = 1

while queue:
	u = queue.pop()
	for i in G[u]:
		v, w = i
		if v not in V:
			V[idx] = v
			idx += 1
			queue.append(v)
			dis[v] = dis[u] + w

for i in dis:
	print(1 if i % 2 else 0)

Fixed submission:
N = int(input())
INF = float('inf')
dis = [INF]*N
dis[0] = 0
G = [[] for _ in range(N)]
for _ in range(N-1):
	u, v, w = map(int, input().split())
	u -= 1
	v -= 1
	G[u].append((v, w))
	G[v].append((u, w))

queue = [0]

while queue:
	u = queue.pop()
	for v, w in G[u]:
		if dis[v] > dis[u] + w:
			queue.append(v)
			dis[v] = dis[u] + w

for i in dis:
	print(i % 2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


L = [A[0]]
R = [A[-1]]
for i in range(1, N):
    L.append(gcd(L[i-1], A[i]))
    R.insert(0, gcd(R[0], A[N-1-i]))


for i in range(N):
    if i == 0:
        ans = R[i+1]
    elif i == N-1:
        ans = max(ans, L[i-1])
    else:
        ans = max(ans, gcd(L[i-1], R[i+1]))

print(ans)


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


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


L = [0] * N
R = [0] * N
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i-1])
    R[N-i-1] = gcd(R[N-i], A[N-i])

for i in range(N):
    if i == 0:
        ans = R[i]
    elif i == N-1:
        ans = max(ans, L[i])
    else:
        ans = max(ans, gcd(L[i], R[i]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


ans = -1
for i in range(N):
    flg = 0
    tmp = A[:i] + A[i+1:]
    Gcd = tmp[0]
    for j in range(N-2):
        g = gcd(tmp[j], tmp[j+1])
        Gcd = gcd(Gcd, g)
        if Gcd < ans:
            flg = 1
            break
    if flg:
        continue
    ans = max(ans, Gcd)

print(ans)


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


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


L = [0] * N
R = [0] * N
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i-1])
    R[N-i-1] = gcd(R[N-i], A[N-i])

for i in range(N):
    if i == 0:
        ans = R[i]
    elif i == N-1:
        ans = max(ans, L[i])
    else:
        ans = max(ans, gcd(L[i], R[i]))

print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd

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


ans = -1
for i in range(N):
    flg = 0
    tmp = A[:i] + A[i+1:]
    Gcd = tmp[0]
    for j in range(N-2):
        g = gcd(tmp[j], tmp[j+1])
        Gcd = gcd(Gcd, g)
        if Gcd < ans:
            flg = 1
            break
    if flg:
        continue
    ans = max(ans, Gcd)

print(ans)


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


def gcd(a: int, b: int) -> int:
    while a % b != 0:
        r = a % b
        a = b
        b = r
    return b


L = [0] * N
R = [0] * N
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i-1])
    R[N-i-1] = gcd(R[N-i], A[N-i])

for i in range(N):
    if i == 0:
        ans = R[i]
    elif i == N-1:
        ans = max(ans, L[i])
    else:
        ans = max(ans, gcd(L[i], R[i]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [i for i in input()]

flg = 0
idx = 0
for i in S:
    if i == '#' and flg == 0:
        flg = 1
        break
    idx += 1

if flg == 1:
    a = S[idx+1:].count('.')
    b = S[idx:].count('#')
    if S[-1] == '#':
        for ct in range(1, N+1):
            if S[-ct] == '.':
                break
        b -= ct-1
    ans = min(a, b)
else:
    ans = 0
key = [0]
S = S[idx:]
for i in range(1, len(S)):
    if S[i] == '#' and S[i-1] == '.':
        key.append(i)
if len(key) > 2:
    for i in range(len(key)-1):
        c = S[:key[i+1]].count('#') + S[key[i+1]:].count('.')
        ans = min(ans, c)

print(ans)


Fixed submission:
N = int(input())
S = [i for i in input()]

flg = 0
idx = 0
for i in S:
    if i == '#':
        flg = 1
        break
    idx += 1

if flg == 1:
    a = S[idx+1:].count('.')
    b = S[idx:].count('#')
    if S[-1] == '#':
        for ct in range(1, N+1):
            if S[-ct] == '.':
                break
        b -= ct-1
    ans = min(a, b)
else:
    ans = 0

count_blk = []
count_wht = []

ct_blk = 0
ct_wht = 0
for i in S:
    if i == '#':
        ct_blk += 1
    else:
        ct_wht += 1
    count_blk.append(ct_blk)
    count_wht.append(ct_wht)

for i in range(N):
    ans = min(ans, count_blk[i] + ct_wht - count_wht[i])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()

n_sum = []

ct = 1
for i in range(N-1):
    if S[i+1] == S[i]:
        ct += 1
    else:
        n_sum.append(ct)
        ct += 1

n_sum.append(ct)

if len(n_sum) == 1:
    if S[0] == '0':
        for i in range(2*K+1):
            n_sum.append(ct)
            n_sum.insert(0, 0)
    else:
        for i in range(2*K):
            n_sum.append(0)
            n_sum.insert(0, 0)

else:
    if S[-1] == '0':
        n_sum.append(ct)
    if S[0] == '0':
        n_sum.insert(0, 0)

if K < len(n_sum)//2:
    Max = -1
    i = 0
    while i+2*K < len(n_sum):
        if i == 0:
            tmp = n_sum[i+2*K]
        else:
            tmp = n_sum[i+2*K] - n_sum[i-1]
        i += 2
        Max = max(Max, tmp)
else:
    Max = ct

print(Max)


Fixed submission:
import sys

N, K = map(int, input().split())
S = input()

n_sum = []

ct = 1
for i in range(N-1):
    if S[i+1] == S[i]:
        ct += 1
    else:
        n_sum.append(ct)
        ct += 1

n_sum.append(ct)

if len(n_sum) == 1:
    print(ct)
    sys.exit()

else:
    if S[-1] == '0':
        n_sum.append(ct)
    if S[0] == '0':
        n_sum.insert(0, 0)

if K < len(n_sum)//2:
    Max = -1
    i = 0
    while i+2*K < len(n_sum):
        if i == 0:
            tmp = n_sum[i+2*K]
        else:
            tmp = n_sum[i+2*K] - n_sum[i-1]
        i += 2
        Max = max(Max, tmp)
else:
    Max = ct

print(Max)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ae = [a, b, c, d, e]

time = 0

for i in ae:
    if i % 10 == 0:
        time += i

ae = [i for i in ae if i % 10 != 0]

idx = 0
for i in ae:
    time += i
    time += 10 - (i % 10)

one = []
for i in ae:
    i = [j for j in str(i)]
    one.append(int(i[-1]))

print(time-10+min(one))


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ae = [a, b, c, d, e]

time = 0

for i in ae:
    if i % 10 == 0:
        time += i

ae = [i for i in ae if i % 10 != 0]

if ae:
    idx = 0
    for i in ae:
        time += i
        time += 10 - (i % 10)

    one = []
    for i in ae:
        i = [j for j in str(i)]
        one.append(int(i[-1]))

    print(time-10+min(one))

else:
    print(time)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

X, Y, Z, K = map(int, input().split())
A = [-int(i) for i in input().split()]
B = [-int(i) for i in input().split()]
C = [-int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()

queue = [(A[0]+B[0]+C[0], 0, 0, 0)]
flg = [[[0 for i in range(Z)] for j in range(Y)] for k in range(X)]
flg[0][0][0] = 1

for i in range(K):
    cake, a, b, c = heapq.heappop(queue)
    print(-cake)
    for j in range(3):
        aa = a + [1, 0, 0][j]
        bb = b + [0, 1, 0][j]
        cc = c + [0, 0, 1][j]
        if aa < X and bb < Y and cc < Z:
            if flg[aa][bb][cc] == 0:
                flg[aa][bb][cc] = 1
                heapq.heappush(queue, (A[aa]+B[bb]+C[cc], aa, bb, cc))


Fixed submission:
X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

queue = [(A[0]+B[0]+C[0], 0, 0, 0)]
ans = [(A[0]+B[0]+C[0], 0, 0, 0)]

for i in range(K):
    cake = max(queue, key=lambda x: x[0])
    queue.remove(cake)
    a, b, c = cake[1], cake[2], cake[3]
    for j in range(3):
        aa = a + [1, 0, 0][j]
        bb = b + [0, 1, 0][j]
        cc = c + [0, 0, 1][j]
        if aa < X and bb < Y and cc < Z:
            tmp = A[aa]+B[bb]+C[cc]
            if (tmp, aa, bb, cc) not in ans:
                ans.append((tmp, aa, bb, cc))
                queue.append((tmp, aa, bb, cc))

ans.sort(reverse=True)
for i in range(K):
    print(ans[i][0])