Harryxun/stf_run huggingface dataset:
import math

N, M = map(int, input().split())
S = input()
T = input()
gcd = math.gcd(N, M)
lcm = N*M//gcd
if N%M==0 or M%N==0:
    exist = True
    if N>M:
        for i in range(M):
            if S[N//M*i]!=T[i]:
                exist = False
                break
    else:
        for i in range(N):
            if T[M//N*i]!=S[i]:
                exist = False
                break
    if exist:
        print(max(N, M))
    else:
        print(-1)
else:
    print(lcm)


### FIXED CODE ###

import math

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N, M = list(map(int, input().split()))
S = input()
T = input()
g = gcd(N, M)
lcm = N*M//g
if N%M==0 or M%N==0:
    exist = True
    if N>M:
        for i in range(M):
            if S[N//M*i]!=T[i]:
                exist = False
                break
    else:
        for i in range(N):
            if T[M//N*i]!=S[i]:
                exist = False
                break
    if exist:
        print(max(N, M))
    else:
        print(-1)
else:
    n_s = lcm//N
    n_t = lcm//M
    mul = n_s*n_t
    exist = True
    for i in range(0, lcm, mul):
        if S[i//n_s]!=T[i//n_t]:
            exist = False
            break
    if exist:
        print(lcm)
    else:
        print(-1)
class UnionFind():
    def __init__(self, n):
        self.par = [-1]*n

    def root(self, x):
        if self.par[x] < 0:
            return x
        return self.root(self.par[x])

    def unite(self, x, y):
        if x > y:
            x, y = y, x
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx

    def size(self, x):
        return -self.par[self.root(x)]

    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    def return_par(self):
        return self.par

n, m = map(int, input().split())
uf = UnionFind(n)
for i in m:
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)


### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

q = deque()
s = set()
ans = 0
for i in range(1, n+1):
    if i not in s:
        q.append(i)
        s.add(i)
        tmp = [i]
        while q:
            v = q.popleft()
            for ti in t[v]:
                if ti not in s:
                    tmp.append(ti)
                    q.append(ti)
                    s.add(ti)
    ans = max(ans, len(tmp))
print(ans)
N=int(input())
A = [int(i) for i in input().split()]
multiple = 1

for i in range(N):
        if A[i]==0:
        break
    multiple = multiple * A[i]
    if (multiple > 18 ** 10):
        break
    
if multiple > 10 ** 18:
    print(-1)
else:
    print(multiple)

### FIXED CODE ###

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

if 0 in A:
    multiple = 0
else:
    multiple = 1
    for i in range(N):
        multiple = multiple * A[i]
        if multiple > 1000000000000000000:
            multiple = -1
            break

print(multiple)
import numpy as np


A, B, M = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a)
b = list(map(int, input().split()))
b = np.array(b)
z = [list(map(int, input().split())) for _ in range(M)]
z = np.array(z)


# for i in range(len(a)):
#     for j in range(len(b)):
#         mem.append(a[i] + b[j])

xx, yy = np.meshgrid(a, b)
xx1 = xx.flatten()
yy1 = yy.flatten()

xxyy = np.c_[xx1, yy1]
mem = xxyy.sum(axis=1)
mem = list(mem)

for x, y, c in z:
    mem.append(a[x - 1] + b[y - 1] - c)
    # np.append(mem, (a[x - 1] + b[y - 1] - c))

print(min(mem))
# print(mem)


### FIXED CODE ###

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = [[int(x) for x in input().split()] for _ in range(M)]

reg = min(a) + min(b)
for x, y, c in L:
    tmp = a[x-1] + b[y-1] - c
    reg = min(reg, tmp)
print(reg)
N, M = map(int, raw_input().split())

for i in range(M/N+1, 0, -1):
    if M % i == 0:
        print i
        exit()


### FIXED CODE ###

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

output = 1
for i in range(M//N, 0, -1):
    if M % i == 0 and output < i:
        output = i
        break
print(output)
n = input()
a = list(map(int, input().split()))
a.sort()
print(a[-1] - a[0])


### FIXED CODE ###

n = int(input())

if n%2==0:
    print(n)

else:
    print(2 * n)
k = int(input())
    s = str(input())
    if len(s) <= k:
        print(str(s))
    else:
        print(s[:k])

### FIXED CODE ###

k = int(input())
s = input()
if k >= len(s):
  print(s)
else:
  print(s[:k]+"...")
N = int(input())
H = map(int,input().split())

for i in range(N-1):
  if H(N-i-1) < H(N-i-2):
    H(N-i-2) -= 1
    
f = 0
for i in range(N-1):
  if H(N-i-1) < H(N-i-2):
    f = 1
    
if f == 0:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))

for i in range(N-1):
  if H[N-i-1] < H[N-i-2]:
    H[N-i-2] -= 1
    
f = 0
for i in range(N-1):
  if H[N-i-1] < H[N-i-2]:
    f = 1
    
if f == 0:
  print("Yes")
else:
  print("No")
while True:
    a=map(int,raw_input().split())
    if not a:break
    b=map(int,raw_input().split())
    hit,blow=0,0
    for i in range(4):
        if a[i]==b[i]:hit+=1
        if a[i] in b :blow+=1
    print hit,blow-hit

### FIXED CODE ###

import sys
line=sys.stdin.readlines()
for A,B in zip(line[0::2],line[1::2]):
    a=map(int,A.strip().split())
    b=map(int,B.strip().split())
    hit,blow=0,0
    for i in xrange(4):
        if a[i]==b[i]:hit+=1
        elif a[i] in b : blow+=1
    print hit,blow
def print_character(str1, str2):
  str outputWord
  outputWord = str1 + str2
  return(outputWord)


### FIXED CODE ###

s = input()
ls = s.split()
print(ls[1] + ls[0])
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

R = {}
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if a not in R: R[a] = [[b, i]]
  else: R[a].append([b, i])
  if b not in R: R[b] = [[a, i]]
  else: R[b].append([a, i])

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M
LL = [-1] * N
for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x] == -1:
      for n, m in R[x]:
        if n >= N: exit()
        LL[n] = x
        if D[n] == D[x] or L[n] != 0:
          H[m] = h
          if L[n] == 1:
            L[n] = 1
            L[x] = 2
          else:
            L[n] = 2
            L[x] = 1
          break
      else:
        print(-1)
        exit()
    else:
      n, m = R[x][LL[x]]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

t = ""
for i in range(N):
  if L[i] == 1:
    t += "B"
  else:
    t += "W"
print(t)
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
D = list(map(int, input().split()))
UB = [list(map(int, input().split())) for _ in range(M)]

LL = [[-1] * 2 for _ in range(N)]
for i in range(M):
  a, b = UB[i]
  a -= 1
  b -= 1
  if D[a] < D[b]:
    LL[b] = [a, i]
  elif D[a] > D[b]:
    LL[a] = [b, i]
  else:
    LL[a] = [b, i]
    LL[b] = [a, i]

DD = [[0] * 2 for _ in range(N)]
for i in range(N):
  DD[i][0] = D[i]
  DD[i][1] = i
DD.sort()
L = [0] * N
H = [0] * M

for i in range(N):
  h, x = DD[i]
  if L[x] == 0:
    if LL[x][0] == -1:
      print(-1)
      exit()
    else:
      n, m = LL[x]
      H[m] = h
      if L[n] == 1:
        L[n] = 1
        L[x] = 2
      else:
        L[n] = 2
        L[x] = 1

for i in range(N):
  if L[i] == 1:
    L[i] = "B"
  else:
    L[i] = "W"
print("".join(list(map(str, L))))
for i in range(M):
  if H[i] == 0:
    print(10 ** 9)
  else:
    print(H[i])
N, K = map(int, input().split())
S = input().replace('\n', '')


def solve(S, K):
    record = []
    temp = []
    for i in range(len(S) - 1):
        if S[i:i+2] == '01':
            temp.append(i + 1)
        elif S[i:i+2] == '10':
            if not temp: temp = [0, i]
            else: temp.append(i)
            record.append(temp)
            temp = []
    if len(temp) > 0:
        temp.append(len(S) - 1)
        record.append(temp)
    if S[0] == '0':
        record = [[0, record[0][0] - 1]] + record
    if S[-1] == '0':
        record = record + [[record[-1][-1] + 1, len(S) - 1]]
    print(record)
    if len(record) <= K + 1: return(len(S))
    else:
        cnt = 0
        for i in range(len(record) - K):
            cnt = max(cnt, record[i + K][1] - record[i][0] + 1)
        return(cnt)
print(solve(S, K))

### FIXED CODE ###

N, K = map(int, input().split())
S = input().replace('\n', '')


def solve(S, K):
    record = []
    temp = []
    for i in range(len(S) - 1):
        if S[i:i+2] == '01':
            temp.append(i + 1)
        elif S[i:i+2] == '10':
            if not temp: temp = [0, i]
            else: temp.append(i)
            record.append(temp)
            temp = []
    if len(temp) > 0:
        temp.append(len(S) - 1)
        record.append(temp)
    if S[0] == '0':
        record = [[0, 0]] + record
    if S[-1] == '0':
        record = record + [[len(S) - 1, len(S) - 1]]
    if len(record) <= K + 1: return(len(S))
    else:
        cnt = 0
        for i in range(len(record) - K):
            cnt = max(cnt, record[i + K][1] - record[i][0] + 1)
        return(cnt)
print(solve(S, K))
import sys
sys.setrecursionlimit(10**9)

def search_max_gcd(M, possible):
    if possible == 1:
        return 1
    elif (M % possible) == 0:
        return possible
    else:
        return search_max_gcd(M, possible-1)

def main():
    N, M = map(int, input().split())
    first_possible = M//N
    print(search_max_gcd(M, first_possible))

main()

### FIXED CODE ###

from math import *

def main():
    N, M = map(int, input().split())
    if N==1:
        print(M)
        return
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M/j for j in divisor_set)
    print(int(max([i for i in divisor_set if special_value >= i])))
    return

main()
s = input()
if(s[2]==s[3]):
  if(s[4]==s[5]):
    print('Yes')
  else:
    print('No')
else:    
print('No')

### FIXED CODE ###

s = input()
if(s[2]==s[3]):
  if(s[4]==s[5]):
    print('Yes')
  else:
    print('No')
else:
  print('No')
import sys
x, y = map(int, sys.stdin.readlines())
if x > y:
    print("GREATER")
elif x == y:
    print("EQUAL")
else:
    print("LESS")

### FIXED CODE ###

import sys

data = sys.stdin.readline().split(" ")
print("".join([x[0].upper() for x in data]))
import math

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
l = a[0]
for i in range(n):
    if i == 0:
        continue
    l = lcm(l, a[i])
sum = 0
for i in range(n):
    sum += l / a[i]
    sum %= 1000000007
print(sum)


### FIXED CODE ###

import sys
from fractions import gcd
input = sys.stdin.readline

def lcm(x, y):
    return (x * y) // gcd(x, y)
def main():
    n = int(sys.stdin.readline())
    a = list(map(int,input().split()))
    
    l = a[0]
    for i in range(n):
        l = lcm(l, a[i])
    sum = 0
    for i in range(n):
        sum += l // a[i]
    print(sum % 1000000007)
main()
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(max(a*b, c*d))

### FIXED CODE ###

a, b, c, d = map(int, input().split())
print(max(a*b, c*d))
N = int(input())
a = list(map(int, input().split()))
ans = 0

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

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(0,N,2):
    if a[i] ==1:
        ans += 1
    elif a[i]%2 ==1:
        ans += 1
print(ans)
def Judge(a, b, c):
    if a > c:
        return 'No'
    elif c > b:
        return 'No'
    else:
        return 'Yes'

Judge(map(int, raw_input().split()))


### FIXED CODE ###

# -*- coding: utf-8 -*-

def Judge(a, b, c):
    if a > c:
        return 'No'
    elif c > b:
        return 'No'
    else:
        return 'Yes'

a,b,c = map(int, input().split())
print(Judge(a,b,c))
s = input()
while(1):
    print(s)
    if s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
        print("NO")
        quit()
    if s == '':
        break
print("YES")

### FIXED CODE ###

s = input()
while(1):
    if s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
        print("NO")
        quit()
    if s == '':
        break
print("YES")
import sys
N = sys.stdin.readline().rstrip(); N = int(N)
A = []
cnt = 0
while cnt < N:
  element = sys.stdin.readline().rstrip()
  element = int(element)
  A.append(element)
  cnt += 1

ans = 0
while True:
  # check
  bool_check=True
  for i in xrange(N):
    if A[i] % 2 == 1:
      bool_check = False
      break
  if bool_check == False: break
  
  # update
  for i in xrange(N):
    A[i] /= 2
  ans += 1
print ans

### FIXED CODE ###

import sys
A = map(int, list(sys.stdin.readline().rstrip()))
ans = 0
for i in xrange(len(A)): ans += A[i]
print ans
H, W = [int(i) for i in input().split()]
S = [[j for j in input()]for i in range(H)]

INF = int(1e12)

def dfs(h, w, p):
    b_cnt = 0
    w_cnt = 0
    if h < 0 or h >= H or w < 0 or w >= W:
        return 0, 0
    if S[h][w] == p or S[h][w] == 'x':
        return 0, 0
    if S[h][w] == '#':
        b_cnt += 1
    elif S[h][w] == '.':
        w_cnt += 1
    t = S[h][w]
    S[h][w] = 'x'

    for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        res = dfs(h + dh, w + dw, t)
        b_cnt += res[0]
        w_cnt += res[1]

    return (b_cnt, w_cnt)

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            b_cnt, w_cnt = dfs(h, w, '.')
            ans += b_cnt * w_cnt

print(ans)

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

H, W = [int(i) for i in input().split()]
S = [[j for j in input()]for i in range(H)]

INF = int(1e12)

def dfs(h, w, p):
    b_cnt = 0
    w_cnt = 0
    if h < 0 or h >= H or w < 0 or w >= W:
        return 0, 0
    if S[h][w] == p or S[h][w] == 'x':
        return 0, 0
    if S[h][w] == '#':
        b_cnt += 1
    elif S[h][w] == '.':
        w_cnt += 1
    t = S[h][w]
    S[h][w] = 'x'

    for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        res = dfs(h + dh, w + dw, t)
        b_cnt += res[0]
        w_cnt += res[1]

    return (b_cnt, w_cnt)

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            b_cnt, w_cnt = dfs(h, w, '.')
            ans += b_cnt * w_cnt

print(ans)
s = list(input())
t = [chr(i) for i in range(ord("a"), ord("z") + 1)]
for i in s:
  t.remove(i)
print(t[0])

### FIXED CODE ###

s = list(input())
for i in range(ord("a"), ord("z") + 1):
  if chr(i) not in s:
    print(chr(i))
    break
else:
  print("None")
def insertionSort(A, n, g):
    global cnt 

    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt+=1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    g = 4
    G = [1]
    m = 1
    for i in range(1,101):
        if g**i <= n:
            m = i+1
            G.append(g**i)
            g += 1
        else:
            break
    G.reverse() 
    print(m)  # 1行目
    print(" ".join(list(map(str,G))))  # 2行目
    for i in range(0,m):
        insertionSort(A, n, G[i])
    print(cnt)  # 3行目
    for i in range(0,len(A)):
        print(A[i]) # 4行目以降

cnt = 0
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))

shellSort(A,n)


### FIXED CODE ###

def insertionSort(A, n, g):
    global cnt 

    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt+=1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    g = 1
    G = [1]
    m = 1
    for i in range(1,101):
        tmp = G[i-1]+(3)**i
        if tmp <= n:
            m = i+1
            G.append(tmp)
            g += 1
        else:
            break
    G.reverse() 
    print(m)  # 1行目
    print(" ".join(list(map(str,G))))  # 2行目

    for i in range(0,m):
        insertionSort(A, n, G[i])
    print(cnt)  # 3行目
    for i in range(0,len(A)):
        print(A[i]) # 4行目以降

cnt = 0
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
shellSort(A,n)
a,b = int(input().split())
if a > b:
   return ("a > b")
elif a < b:
   return ("a < b ")
else:
   return ("a == b")

### FIXED CODE ###

a,b = map(int,input().split())

if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")
#ABC072-C
import collections
import itertools

n = int(input())
a = list(map(int,input().split()))
 
cnt = [0] * 100000


for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1
    
    

    
        
print(max(cnt))


### FIXED CODE ###

#ABC072-C
n = int(input())
a = list(map(int,input().split()))
 
cnt = [0] * 100002


for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1
    
    

    
        
print(max(cnt))
N, X = map(int, input().split())
L = list(map(int, input().split()))
a = 0
for i in range(N+1):
    a += L[i]
    if a > X:
        break
print(i+1)

### FIXED CODE ###

N, X = map(int, input().split())
L = list(map(int, input().split()))
a = 0
ans = 1
for i in range(N):
    a += L[i]
    if a <= X:
        ans += 1
print(ans)
s = input()
f = 0
a = 0; b = 0; c = 0
if len(s)==3 and s[0]==s[2]:
    print('Yes')
else :
    
    for i in range(len(s)//2):
        if s[i]==s[-1-i]:
            a += 1
        if a == len(s)//2:
            f += 1
    for i in range(len(s)//4):
        if s[i]==s[(len(s)-1)//2-1-i]:
            b += 1
        if b == len(s)//4:
            f += 1
        if s[(len(s)+3)//2-1+i]==s[len(s)-1+i]:
            c += 1
        if c == len(s)//4:
            f += 1
    print('Yes' if f == 3 else 'No')

### FIXED CODE ###

s = input()
f = 0
a = 0; b = 0; c = 0
if len(s)==3 and s[0]==s[2]:
    print('Yes')
else :
    
    for i in range(len(s)//2):
        if s[i]==s[-1-i]:
            a += 1
        if a == len(s)//2:
            f += 1
    for i in range(len(s)//4):
        if s[i]==s[(len(s)-1)//2-1-i]:
            b += 1
        if b == len(s)//4:
            f += 1
        if s[(len(s)+3)//2-1+i]==s[len(s)-1-i]:
            c += 1
        if c == len(s)//4:
            f += 1
    print('Yes' if f == 3 else 'No')
n,q=list(map(int,input().split()))

ab=[[] for _ in range(n)]
arr=[0 for _ in range(n)]

for _ in range(n-1):
  a,b=map(int,input().split())
  ab[a-1].append(b-1)

px=[list(map(int,input().split())) for _ in range(q)]
  
  
def search(tree, root):
  arr=[]
  children=tree[root]
  if children == []:
    return None
  else:
    arr.extend(children)
    for child in children:
      ret=search(tree, child)
      if ret is not None:
        arr.extend(ret)    
  return arr
      
for p,x in px:
  children=search(ab,p-1)
  if children is not None:
    children=[p-1]+children
  else:
    children=[p-1]
  for child in children:
    arr[child]+=x
print(*arr)
    

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


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

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])
n, m = map(int, input().split())
a = [-1]
for i in range(m):
    a.append(int(input()))
a.append(n+1)

stairs = [0, 1, 1]
for i in range(3, n+1):
    stairs.append(stairs[i-1] + stairs[i-2])

def ans():
    mod = 10 ** 9 + 7
    count = 1
    for i in range(m+1):
        diff = a[i+1] - a[i] - 1
        if diff == 0:
            print("0")
            return
        else:
            count *= stairs[diff]
    print(count % mod)
    return

ans()


### FIXED CODE ###

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

ways = [1, 1]
for i in range(2, n + 1):
    ways.append(ways[i-2] + ways[i-1])

stairs = []
now = 0
for i in range(m):
    stairs.append(a[i] - 1 - now)
    now = a[i] + 1

stairs.append(n - now)

ans = 1
for ele in stairs:
    if ele == -1:
        ans *= 0
    else:
        ans *= ways[ele]

mod = 10 ** 9 + 7
print(ans % mod)
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(K):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])

### FIXED CODE ###

x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(min([len(ab),K])):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])