Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if(i*j*k > K): break
         else: tot.append(a[i] + b[j] + c[k])
tot.sort()
for i in range(K):
   print(tot[-(i+1)])


### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if((i+1)*(j+1)*(k+1) <= K): tot.append(a[i] + b[j] + c[k])
         else: break
tot.sort(reverse = True)
for i in range(K):print(tot[i])
### BUGGY CODE ###

from collections import defaultdict
N,K,L=list(input().split(" "))
N=int(N)
K=int(K)
L=int(L)
road=defaultdict(lambda:[])
train=defaultdict(lambda:[])
for i in range(K):
    p,q=map(int,list(input().split(" ")))
    road[p].append(q)
for i in range(L):
    r,s=map(int,list(input().split(" ")))
    train[r].append(s)

def deep_search(dict):
    stack=[] 
    mem=[]
    group={}
    for v in list(dict):
        if v not in mem:
            stack.append(v)
            while stack!=[]:
                w=stack.pop()
                mem.append(w)
                group[w]=v
                for ww in dict[w]:
                    if ww not in mem:
                        mem.append(ww)
                        group[ww]=v
                        stack.append(ww)
    return group

road_g=deep_search(road)
train_g=deep_search(train)
count=defaultdict(lambda:0)
for i in range(1,N+1):
    if i in road_g.keys() and i in train_g.keys():
        l=[road_g[i],train_g[i]]
        count[str(l)]+=1
for i in range(1,N+1):
    if i in road_g.keys() and i in train_g.keys():
        l=[road_g[i],train_g[i]]
        print(count[str(l)],end=" ")
    else:
        print(1,end=" ")

### FIXED CODE ###

from collections import defaultdict
class Unionfind:
    def __init__(self,n):
        self.n=n
        self.roots=[i for i in range(self.n)]


    def root(self,x):
        if self.roots[x]==x:
            return x
        else:
            self.roots[x]=self.root(self.roots[x])
            return self.roots[x]
    def unite(self,x,y):
        if self.root(x)==self.root(y):
            return
        else:
            if self.root(x)>self.root(y):
                self.roots[self.root(x)]=self.root(y)
            else:
                self.roots[self.root(y)]=self.root(x)
    
    def same(self,x,y):
        return self.root(x)==self.root(y)

N,K,L=list(input().split(" "))
N=int(N)
K=int(K)
L=int(L)
road=Unionfind(N)
train=Unionfind(N)
for i in range(K):
    p,q=map(int,list(input().split(" ")))
    road.unite(p-1,q-1)
for i in range(L):
    r,s=map(int,list(input().split(" ")))
    train.unite(r-1,s-1)



count=defaultdict(lambda:0)
point=[]
for i in range(N):
    a=road.root(i)
    b=train.root(i)
    l=[a,b]
    point.append(l)
    count[str(l)]+=1
for i in point:
    print(count[str(i)],end=" ")
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().strip().split()))
m=max(a)
n=min(a)
b=0
for i in range(n,m+1):
  b=max(b,(a.count(i+1)+a.count(i)+a.count(i-1)))
print(b)

### FIXED CODE ###

n=int(input())
a=list(map(int, input().strip().split()))
b=[0]*(10**5)
for i in range(n):
  b[a[i]]+=1
ma=0
for i in range(1,10**5-1):
    ma=max(b[i-1]+b[i]+b[i+1],ma)
print(ma)
### BUGGY CODE ###

#!/usr/bin/env python3

from collections import Counter


def solve(N: int, A: "List[int]", Q: int, BC: "List[(int,int)]"):
    A = Counter(A)
    answers = []
    for b, c in BC:
        if b != c:
            A[c] += A[b]
            del A[b]
        ans = sum((i * n for i, n in A.items()))
        answers.append(ans)
    return answers


def main():
    N = int(input())  # type: int
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [tuple(map(int, input().split())) for _ in range(Q)]
    answer = solve(N, A, Q, BC)
    for ans in answer:
        print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

from collections import Counter


def solve(N: int, A: "List[int]", Q: int, BC: "List[(int,int)]"):
    A = Counter(A)
    answers = []
    ans = ans = sum((i * n for i, n in A.items()))
    for b, c in BC:
        if b != c:
            ans += (c - b) * A[b]
            A[c] += A[b]
            del A[b]
        answers.append(ans)
    return answers


def main():
    N = int(input())  # type: int
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [tuple(map(int, input().split())) for _ in range(Q)]
    answer = solve(N, A, Q, BC)
    for ans in answer:
        print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse = True)
b = list(map(int,input().split()))
b = sorted(b,reverse = True)
c = list(map(int,input().split()))
c = sorted(c,reverse = True)

ls1= []
for i in range(min(x,k)):
    for j in range(min(y,k)):
        ls1.append(a[i]+b[j])

ls1 = sorted(ls1,reverse=True)

ls1 = ls1[:k]
ls2 = []
for i in range(min(z,k)):
    for j in range(len(ls1)):
        ls2.append(c[i]+ls1[j])

ls2 = sorted(ls2,reverse=True)

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


### FIXED CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse = True)
b = list(map(int,input().split()))
b = sorted(b,reverse = True)
c = list(map(int,input().split()))
c = sorted(c,reverse = True)

ls1= []
for i in range(min(x,k)):
    for j in range(min(y,k)):
        ls1.append(a[i]+b[j])

ls1 = sorted(ls1,reverse=True)

ls1 = ls1[:k]
ls2 = []
for i in range(min(z,k)):
    for j in range(len(ls1)):
        ls2.append(c[i]+ls1[j])

ls2 = sorted(ls2,reverse=True)

for i in range(k):
    print(ls2[i])
### BUGGY CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
A = list(set(A))
A.sort(reverse=True)

result = 0
while True:
    if len(A) == 1:
        break
    if A[-1] == 1:
        result = 1
        break
    A[0] = A[0] % A[1]
    if A[0] == 0:
        A.pop(0)
    A = list(set(A))
    A.sort(reverse=True)

if result != 0:
    print(result)
else:
    print(A[0])


### FIXED CODE ###

import fractions
from functools import reduce

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

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

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

print(gcd_list(A))
### BUGGY CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

dummy=set()
loop=[]
X=set(range(N))
while len(dummy)!=N:
  a=[]
  k=min(X-dummy)
  a.append(k)
  dummy.add(k)
  l=P[k]-1
  while l!=k:
    a.append(l)
    dummy.add(l)
    l=P[l]-1
  loop.append(a)

ans=-(10**300)
for l in loop:
  temp=0
  s=len(l)
  ssum=0
  k=0
  for i in range(s):
    ssum+=C[l[i]]
  if ssum>0:
    temp+=((K-1)//s)*ssum
    k=K-((K-1)//s)*s
  else:
    k=min(K,s)
  kmax=-(10**300)
  for ii in range(s):
    tempscore=temp
    for jj in range(1,k+1):
      tempscore+=C[l[(ii+jj)%s]]
      if tempscore>kmax:
        kmax=tempscore
  if kmax>ans:
    ans=kmax
print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

dummy=set()
loop=[]
X=set(range(N))
while len(dummy)!=N:
  a=[]
  k=min(X-dummy)
  a.append(k)
  dummy.add(k)
  l=P[k]-1
  while l!=k:
    a.append(l)
    dummy.add(l)
    l=P[l]-1
  loop.append(a)

ans=-(10**300)
for l in loop:
  temp=0
  s=len(l)
  ssum=0
  k=0
  for i in range(s):
    ssum+=C[l[i]]
  if ssum>0:
    temp+=((K-1)//s)*ssum
    k=K-((K-1)//s)*s
  else:
    k=min(K,s)
  kmax=-(10**300)
  for ii in range(s):
    tempscore=temp
    for jj in range(1,k+1):
      tempscore+=C[l[(ii+jj)%s]]
      if tempscore>kmax:
        kmax=tempscore
  if kmax>ans:
    ans=kmax
print(ans)
### BUGGY CODE ###

a,b,k = map(int, input().split())
for i in range(k):
    if a > 0:
        a -= 1
    elif b > 1:
        b -= 1
print(a,b)

### FIXED CODE ###

a,b,k = map(int, input().split())
if k >= a:
    k = k-a
    a = 0
else:
    a -= k
    k = 0

if k >= b:
    b = 0
else :
    b -= k
print(a,b)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
# chech with no break
finish = False
def check(A, cnt=0):
  N = len(A)
  #print(A)
  for i, a in enumerate(A):
    if a != N and i != N - 1:
      continue
    if a == N and i != N - 1:
      return False
    if A[N - 1] == N:
      #print("debug")
      if cnt == 0:
        print(0)
      return True
  return False
finish = check(A)
cnt = 0
while finish is False:
  # Miss break from the large number
  #m = max(A)
  #i = A.index(m)
  i = 0
  if finish is False and len(A) > 1:
    A.pop(i) # remove
    cnt += 1
    finish = check(A, cnt)
  else:
    break
  i += 1
if finish is True and cnt != 0:
  print(cnt)
if finish is False:
  print(-1)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
cnt, i = 0, 1
for a in A:
  if a == i:
    i += 1
  else:
    cnt += 1
print(cnt if cnt != N else -1)
### BUGGY CODE ###

k = int(input())
ans = 0

import math
from functools import reduce

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

import itertools
A = list(itertools.product(range(1,k+1), repeat=3))

for i in range(len(A)):
    ans += gcd_list(A[i])
    
if k == 1:
    print(1)
elif k == 2:
    print(9)
else:
    print(ans)

### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0

for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(x,y,z)
            
print(ans)
### BUGGY CODE ###

k = int(input())
s = '7'
result = -1
if not k % 2 == 0 and not k % 5 == 0:
    for i, _ in enumerate(range(k), 1):
        val = int(s) 
        if val % k == 0:
            result = i
            break
        else:
            s += '7'
print(result) 

### FIXED CODE ###

k = int(input())
target = 7; ans = -1
if not k % 2== 0:
    
    for i in range(1, k + 10):
        if target % k == 0:
            ans = i
            break
        target = (target * 10 + 7) % k
 
print(ans)
### BUGGY CODE ###

n, q = map(int, input().split(" "))
s = input()

place_of_AC = []
for i in range(len(s) - 1):
  if s[i:i+2] == "AC":
    place_of_AC.append(1)
  else:
    place_of_AC.append(0)
    
for _ in range(q):
  l, r = map(int, input().split(" "))
  out = sum(place_of_AC[l-1:r-1])
  print(out)

### FIXED CODE ###

import sys

input = sys.stdin.readline

n, q = map(int, input().split(" "))
s = input()
cnt = 0
place_of_AC = [0] * n

for i in range(len(s) - 1):
  place_of_AC[i]=cnt
  if s[i:i+2] == "AC":
    cnt += 1


#print(place_of_AC)
  
for _ in range(q):
  l, r = map(int, input().split(" "))
  out = place_of_AC[r-1] - place_of_AC[l-1]
  print(out)
### BUGGY CODE ###

n,m = map(int,input().split())
gates = [list(map(int,input().split())) for _ in range(m)]
answers = [i for i in range(1,n+1)]
for gate in gates:
    for ans in answers[:]:
        if ans < gate[0] or ans > gate[1]:
            answers.remove(ans)
print(len(answers))


### FIXED CODE ###

n,m = map(int,input().split())
gates = [list(map(int,input().split())) for _ in range(m)]
l = []
r = []
for gate in gates:
    l.append(gate[0])
    r.append(gate[1])
ans = min(r)+1 - max(l)
print(ans if ans > 0 else 0)
### BUGGY CODE ###

n = int(input())

a_list = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10 ** 5)+1)]

for i in a_list:
    ary[i] += i

ans = []
for _ in range(q):
    b, c = map(int, input().split())
    ary[c] += (ary[b]/b)*c
    ary[b] = 0
    ans.append(int(sum(ary)))

for a in ans:
    print(a)


### FIXED CODE ###

n = int(input())

a_list = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10**5) + 1)]

for i in a_list:
    ary[i] += 1

ans = []

f_ans = sum(a_list)
for _ in range(q):
    b, c = map(int, input().split())
    f_ans += (c-b)*ary[b]
    ary[c] += ary[b]
    ary[b] = 0

    ans.append(f_ans)

for a in ans:
    print(a)
### BUGGY CODE ###

I=9**9
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I]*h*w
d[~w+a*w+b]=1
q=[(a-1,b-1)]
for s,t in q:
 p=d[s*w+t]+1
 for y,x in(-1,0),(1,0),(0,-1),(0,1):
  for z in range(k):
   i,j=s+y*~z,t+x*~z
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[i*w+j]<p:break
   q+=(i,j),;d[i*w+j]=p
print(d[~w+f*w+g]%I-1)

### FIXED CODE ###

I=9**9
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I]*h*w
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if d[t]==I:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)
### BUGGY CODE ###

from collections import deque
import math
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))

S = [list(input()) for i in range(H)]

maze_visited = [[math.inf] * W for i in range(H)]

queue = deque([[C[0]-1, C[1]-1]])
maze_visited[C[0]-1][C[1]-1] = 0
while queue:
    y, x = queue.popleft()
    mv_cur = maze_visited[y][x]
    for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
        n_x, n_y = x + i, y + j
        if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
            mv_n = maze_visited[n_y][n_x]
            if mv_n > mv_cur:
                if S[n_y][n_x] == '.':
                    maze_visited[n_y][n_x] = mv_cur
                    queue.append([n_y, n_x])
    for i in range(-2, 3):
        for j in range(-2, 3):
            if abs(i) + abs(j) <= 1:
                continue
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur + 1:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur + 1
                        queue.append([n_y, n_x])

if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])

### FIXED CODE ###

from collections import deque
import math
 
def explore(C, D):
    queue = deque([(C[0]-1, C[1]-1)])
    maze_visited[C[0]-1][C[1]-1] = 0
    while queue:
        y, x = queue.popleft()
        mv_cur = maze_visited[y][x]
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur
                        queue.appendleft((n_y, n_x))
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    mv_n = maze_visited[n_y][n_x]
                    if mv_n > mv_cur + 1:
                        if S[n_y][n_x] == '.':
                            maze_visited[n_y][n_x] = mv_cur + 1
                            queue.append((n_y, n_x))
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
 
S = [list(input()) for i in range(H)]
 
maze_visited = [[math.inf] * W for i in range(H)]
 
explore(C,D)
 
if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])
### BUGGY CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))
m=[0]*(n-k+1)

for i in range(0,n-k+1):
    s=0
    for j in range(i,i+k):
        s=s+A[j]
    m[i]=s
print((max(m)+k)/2)

### FIXED CODE ###

n,k = map(int, input().split())
A = list(map(int, input().split()))
s=[0]*(n+1)
for i in range(1,n+1):
    s[i]=s[i-1]+A[i-1]
s1=[0]*(n-k+1)
for i in range(0,n-k+1):
    s1[i]=s[k+i]-s[i]
print((max(s1)+k)/2)
### BUGGY CODE ###

s = str(input())
length = len(s)
count = 0
for i in range(length - 2):
  if int(s[i]) ==0:
    continue
  for j in range(i+3, length + 1):
    if int(s[i:j])%2019 == 0:
      count += 1
print(count)

### FIXED CODE ###

s = input()[::-1]
counts = [0]*2019
counts[0] = 1
sum = 0
d = 1
for c in s:
  sum += int(c)*d
  remain = sum%2019
  d *= 10
  d %= 2019
  counts[remain] += 1

ans = 0
for count in counts:
  ans += count*(count - 1) / 2
print(int(ans))
### BUGGY CODE ###

n, ma, mb = map(int, input().split())
dp = [[[float('inf') for _ in range(401)] for _ in range(401)] for _ in range(n)]
dp[0][0][0] = 0
a0, b0, c0 = map(int, input().split())
dp[0][a0][b0] = c0

for i in range(1, n):
	dp[i][0][0] = 0
	a, b, c = map(int, input().split())
	for j in range(401):
		for k in range(401):
			if j >= a and k >= b:
				dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a][k-b] + c)
			else:
				dp[i][j][k] = dp[i-1][j][k]

ans = float("inf")
cnt = 400 // max(ma, mb)
for i in range(1, cnt + 1):
	ans = min(ans, dp[-1][ma * i][mb * i])

if ans <= 4000:
	print(ans)
else:
	print(-1)

### FIXED CODE ###

n, ma, mb = map(int, input().split())
dp = [[[float('inf') for _ in range(401)] for _ in range(401)] for _ in range(n)]
dp[0][0][0] = 0
a0, b0, c0 = map(int, input().split())
dp[0][a0][b0] = c0

for i in range(1, n):
	dp[i][0][0] = 0
	a, b, c = map(int, input().split())
	for j in range(401):
		for k in range(401):
			if j >= a and k >= b:
				dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a][k-b] + c)
			else:
				dp[i][j][k] = dp[i-1][j][k]

ans = float("inf")
cnt = 400 // max(ma, mb)
for i in range(1, cnt + 1):
	ans = min(ans, dp[-1][ma * i][mb * i])

if ans <= 4000:
	print(ans)
else:
	print(-1)
### BUGGY CODE ###

n = int(input())
a = [input() for _ in range(n)]
b = []
for i in range(n):
    if a[i] not in b:
        b.append(a[i])
b.sort()
c = [0]*len(b)
for i in range(len(b)):
    c[i] += a.count(b[i])
for i in range(len(b)):
    if c[i] == max(c):
        print(b[i])


### FIXED CODE ###

n = int(input())
a = [input() for _ in range(n)]
cnt = {}
for i in range(n):
    if a[i] not in cnt:
        cnt[a[i]] = 1
    else:
        cnt[a[i]] += 1
mx = max(cnt.values())
ans = []
for i in cnt.keys():
    if cnt[i] == mx:
        ans.append(i)
ans.sort()
for _ in ans:
    print(_)
### BUGGY CODE ###

s = input()
s = s[::-1]
n = len(s)
mod = 10**9 + 7

dp = [[0 for j in range(13)] for i in range(n)]
if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    num = int(s[0])
    dp[0][num] = 1

mul = 1
for i in range(1, n):
    mul = (mul*10) % 13
    if s[i] == '?':
        for m in range(10):
            num = (m * mul) % 13
            for j in range(13):
                dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod
    else:
        num = (int(s[i]) * mul) % 13
        for j in range(13):
            dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod

print(dp[n-1][5])

### FIXED CODE ###

s = input()
s = s[::-1]
n = len(s)
mod = 10**9 + 7

dp = [[0 for j in range(13)] for i in range(n)]
if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    num = int(s[0])
    dp[0][num] = 1

mul = 1
for i in range(1, n):
    mul = (mul*10) % 13
    if s[i] == '?':
        for m in range(10):
            num = (m * mul) % 13
            for j in range(13):
                dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod
    else:
        num = (int(s[i]) * mul) % 13
        for j in range(13):
            dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod

print(dp[n-1][5])
### BUGGY CODE ###

A, B, Q = map(int, input().split())
S, T =[None] * (A+1), [None] * (B+1)
S[0], T[0] = 0, 0
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S.append(10**20)
T.append(10**20)

def Bsearch(x, L):
    low, high = 0, len(L)
    while high-low > 1:
        mid = (low+high)//2
        if L[mid] > x:
            high = mid
        else: low = mid
    return low

def Length(x, i, L):
    if i == 0: return [10**30, L[1] - x]
    else: return [x - L[i], L[i+1] - x]

for _ in range(Q):
    x = int(input())
    sLength, tLength = Length(x, Bsearch(x, S), S), Length(x, Bsearch(x, T), T)
    Ans = min(max(sLength[0], tLength[0]), max(sLength[1], tLength[1]))
    Ans = min(Ans, min(sLength[0] + tLength[1] + min(sLength[0], tLength[1]), sLength[1] + tLength[0] + min(sLength[1], tLength[0])))
    print(Ans)

### FIXED CODE ###

from bisect import bisect
A, B, Q = map(int, input().split())
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S[A+1] = 10**20
T[B+1] = 10**20

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(input())
    si, ti = bisect(S, x, 0, lenS), bisect(T, x, 0, lenT)
    sLength0, sLength1 = x - S[si-1], S[si] - x
    tLength0, tLength1 = x - T[ti-1], T[ti] - x
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print(min(Ans))
### BUGGY CODE ###

n,m = map(int,input().split())
lst = []
for i in range(m):
  x,y = map(int,input().split())
  lst.append([x,y]) 
from collections import deque
d = ['t']*n
d[0] = 0
que = deque([1])
while que:
  p = que.popleft()
  for j in range(m):
    if lst[j][0] == p:
      q = lst[j][1]
      if d[q-1] == 't':
        d[q-1] = p
        que.append(q)
    if lst[j][1] == p:
      q = lst[j][0]
      if d[q-1] == 't':
        d[q-1] = p   
        que.append(q)
print('Yes')        
for i in range(1,n):
  print(d[i])
        
        

### FIXED CODE ###

from collections import deque

n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    a[x - 1].append(y - 1)
    a[y - 1].append(x - 1)
c = [0] * n
que = deque([])
que.append(0)
while len(que) > 0:
    e = que.popleft()
    for i in a[e]:
        if c[i] > 0:
            continue
        c[i] = e + 1
        que.append(i)
print("Yes")
for i in range(1, n):
    print(c[i])
### BUGGY CODE ###

X,Y,Z,K = map(int, input().split())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
a_b_total = [0 for _ in range(X*Y)]
for i in range(X):
    for j in range(Y):
        a_b_total[i*Y+j] = a_list[i] + b_list[j]
a_b_total.sort(reverse = True)
a_b_c_total = [0 for _ in range(K*Z)]
for i in range(min(K,X*Y)):
    for j in range(Z):
        a_b_c_total[i*Z+j] = a_b_total[i] + c_list[j]
a_b_c_total.sort(reverse = True)
for i in range(K):
    print(a_b_c_total[i])

### FIXED CODE ###

from heapq import heappush, heappop

# input
X,Y,Z,K = map(int, input().split())
a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]
c_list = [int(i) for i in input().split()]
a_list.sort(reverse = True)
b_list.sort(reverse = True)
c_list.sort(reverse = True)

#solve
hq = []
arg_hash = {}
val = a_list[0] + b_list[0] + c_list[0]
heappush(hq, (-val,0,0,0))

for i in range(K):
    ans, a, b, c = heappop(hq)
    print(-ans)

    arg_a = (a+1, b, c)
    arg_b = (a, b+1, c)
    arg_c = (a, b, c+1)

    if a < X-1 and arg_a not in arg_hash:
        arg_hash[arg_a] = 1
        heappush(hq, (-(a_list[a+1]+b_list[b]+c_list[c]),)+arg_a)
    if b < Y-1 and arg_b not in arg_hash:
        arg_hash[arg_b] = 1
        heappush(hq, (-(a_list[a]+b_list[b+1]+c_list[c]),)+arg_b)
    if c < Z-1 and arg_c not in arg_hash:
        arg_hash[arg_c] = 1
        heappush(hq, (-(a_list[a]+b_list[b]+c_list[c+1]),)+arg_c)