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

X, Y, Z, K = map(int, input().split())
A, B, C = [sorted(list(map(int, input().split())))[:: -1][: K] for _ in range(3)]
D = []
for ai in A:
    for bi in B:
        D.append(ai + bi)

D = sorted(D)[:: -1][: K]

res = []
for di in D:
    for ci in C:
        res.append(di + ci)

res = sorted(res)[:: -1][: K]

for ans in res:
    print(ans)


### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A, B, C = [sorted(list(map(int, input().split())))[:: -1][: K] for _ in range(3)]
D = []
for ai in A:
    for bi in B:
        D.append(ai + bi)

D = sorted(D)[:: -1][: K]

res = []
for di in D:
    for ci in C:
        res.append(di + ci)

res = sorted(res)[:: -1][: K]

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

import json

n = int(input())
str = []
for i in range(n):
  str.append(input())

ana = []
for i in range(n):
  alpha = {}
  for j in range(10):
    if alpha.get(str[i][j]) == None:
      alpha[str[i][j]] = 1
    else:
      alpha[str[i][j]] += 1
  ana.append(sorted(alpha.items(), key=lambda x:x[0]))

anastr = []
for i in range(n):
  anastr.append(json.dumps(ana[i]))

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    if anastr[i] == anastr[j]:
      ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
map = {}
for i in range(n):
  str = ''.join(sorted(input()))
  if str in map:
    map[str] += 1
  else:
    map[str] = 1

ans = 0
for value in map.values():
  ans += value * (value - 1) // 2

print(ans)
### BUGGY CODE ###

n = int(input())
A = tuple(map(int, input().split()))
A = sorted(A)
ans = [True] * n

for i in range(n):
    ai = A[i]
    if not ans[i]:
        continue
    try:
        if ai == A[i+1]:
            ans[i] = False
    except:
        pass

    for j in range(i+1, n):
        if A[j]%ai == 0:
            ans[j] = False
print(sum(ans))

### FIXED CODE ###

from collections import Counter
n = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)
A = list(set(A))
ok = [True] * (10**6+1)

for a in A:
    temp = a+a
    while temp < 10**6+1:
        ok[temp] = False
        temp += a

c = 0
for a in A:
    if C[a] == 1 and ok[a] == True:
        c += 1
print(c)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
k, n = map(int, input().split())

def calc_x(K, N):
	return (pow(K, N+1)-K) // (K-1)
def lexico(K, N, X):
	global ans
	if X == 0:
		return
	q = (calc_x(K, N-1)+1)
	if N > 1:
		ans.append((X//q) + 1)
	else:
		ans.append((X//q))
	lexico(K, N-1, (X-1)%q)

if k == 1:
	print(*[1 for _ in range((n+1)//2)])
elif n == 1:
	print((k+1)//2)
elif k%2 == 0:
	ans = [k//2] + [k] * (n-1)
	print(*ans)
else:
	x = calc_x(k, n)
	ans = []
	lexico(k, n, (x+1)//2)
	print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
k, n = map(int, input().split())

def calc_x(K, N):
	return (pow(K, N+1)-K) // (K-1)
def lexico(K, N, X):
	#print(K, N, X)
	global ans
	if X == 0:
		return
	q = (calc_x(K, N-1)+1)
	if N > 1:
		ans.append((X//q) + 1)
	else:
		ans.append((X//q))
	lexico(K, N-1, (X-1)%q)

if k == 1:
	print(*[1 for _ in range((n+1)//2)])
elif n == 1:
	print((k+1)//2)
elif k%2 == 0:
	ans = [k//2] + [k] * (n-1)
	print(*ans)
else:
	if n%2 == 1:
		cur, i = 1, n
	else:
		cur, i = 0, n
	while cur <= i:
		i -= 1
		cur += pow(k, n-i)
	ans = [(k+1)//2] * i
	ind = (cur-i) // 2
	lexico(k, n-i, ind)
	print(*ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

S = input().rstrip()
N = len(S)
mod = 10**9 + 7
cnt = 0
A = B = C = 0
for c in S:
    if c == 'A':
        A += 3**cnt
    if c == 'B':
        B += A
    if c == 'C':
        C += B
    if c == '?':
        C = C * 3 + B
        B = B * 3 + A
        A = A * 3 + pow(3, cnt, mod)
        cnt += 1
    A %= mod
    B %= mod
    C %= mod
print(C)

### FIXED CODE ###

import sys
input = sys.stdin.readline

S = input().rstrip()
N = len(S)
mod = 10**9 + 7
cnt = 0
A = B = C = 0
for c in S:
    if c == 'A':
        A += pow(3, cnt, mod)
    if c == 'B':
        B += A
    if c == 'C':
        C += B
    if c == '?':
        C = C * 3 + B
        B = B * 3 + A
        A = A * 3 + pow(3, cnt, mod)
        cnt += 1
    A %= mod
    B %= mod
    C %= mod
print(C)
### BUGGY CODE ###

n = int(input())
import collections
l = [input() for i in range(n)]
l_cnt = collections.Counter(l)
l_cnt_max = []
for i in l_cnt:
    if l_cnt[i] == max(l_cnt.values()):
        l_cnt_max.append(i)
m = sorted(l_cnt_max)
for i in m:
    print(i)

### FIXED CODE ###

n = int(input())
l = [input() for i in range(n)]
d = {}
for i in l:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d_max = max(d.values())
for i in sorted(d):
    if d[i] == d_max:
        print(i)
### BUGGY CODE ###

def main():
    INF=10**9
    n,m=map(int,input().split())
    key=[0]*m
    keycost=[0]*m

    for i in range(m):
        a,b=map(int,input().split())
        keycost[i]=a
        c=[pow(2,int(i)-1) for i in input().split()]
        key[i]=sum(c)
    
    dp=[[INF]*(m+1) for _ in range(1<<n)]
    dp[0]=[0]*(1+m)
    
    for s in range(1<<n):
        for i in range(m):
            dp[s][i+1]=min(dp[(s&key[i])^s][i]+keycost[i],dp[s][i])
    
    if dp[-1][m]==INF:
        print(-1)
    else:
        print(dp[-1][m])
 
if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    INF=10**9
    n,m=map(int,input().split())
    key=[0]*m
    keycost=[0]*m

    for i in range(m):
        a,b=map(int,input().split())
        keycost[i]=a
        c=[pow(2,int(i)-1) for i in input().split()]
        key[i]=sum(c)
    
    dp=[[INF]*(m+1) for _ in range(1<<n)]
    dp[0]=[0]*(1+m)
    
    for s in range(1<<n):
        for i in range(m):
            dp[s][i+1]=min(dp[(s&key[i])^s][i]+keycost[i],dp[s][i])
    
    if dp[-1][m]==INF:
        print(-1)
    else:
        print(dp[-1][m])
 
if __name__=='__main__':
    main()
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N-2):
  for j in range(i+1,N): 
    ans += sum([1 for k in L[j+1:] if abs(L[j]-L[i]) < k < L[j]+L[i]])
print(ans)
  

### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)
ans = 0

def binary(L):
  left = -1
  right = len(L)
  t = (left+right)//2
  while right-left != 1:
    if L[t] > max_len - next_len:
      left = t
    else:
      right = t
    t = (left + right) // 2
  return left + 1
  
  
for i in range(N-2):
  max_len = L[i]
  for j in range(i+1,N-1):
    next_len = L[j]
    ans += binary(L[j+1:])
print(ans)
### BUGGY CODE ###

import itertools

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()))

mix_ab= [a_+b_ for a_,b_ in itertools.product(a, b)]
mix_ab.sort(reverse=True)
c.sort(reverse=True)

mix_abc= [ab_+c_ for ab_,c_ in itertools.product(mix_ab[:k], c[:k])]
mix_abc.sort(reverse=True)

print(*mix_abc[:k], sep='\n')

### FIXED CODE ###

import itertools

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()))

mix_ab= [a_+b_ for a_,b_ in itertools.product(a, b)]
mix_ab.sort(reverse=True)
c.sort(reverse=True)

mix_abc= [ab_+c_ for ab_,c_ in itertools.product(mix_ab[:k], c[:k])]
mix_abc.sort(reverse=True)

print(*mix_abc[:k], sep='\n')
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])

for i in range(a):
    da[i].sort()

for i in range(b):
    p = da[d[i][0]-1].index(d[i][1])

    n = str(d[i][0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)



### FIXED CODE ###

import sys
input = sys.stdin.readline

a,b = map(int,input().split())
aa = []
d = []
for i in range(b):
    k,kk = map(int,input().split())
    d.append([k, kk,i+1])

da = sorted(d)

kkk = da[0][0]
ll = 0
for i in range(b):
    kkkk = da[i][0]
    if kkk == kkkk:
        ll += 1
    else:
        kkk = kkkk
        ll = 1
    aa.append([da[i][2],da[i][0],ll])
aa.sort()

for i in aa:
    m = str(i[1])
    n = str(i[2])
    m = "0"*(6-len(m))+m
    n = "0"*(6-len(n))+n
    print(m+n)
### BUGGY CODE ###

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

ans = 0
for i in range(n):
    count = 0
    for j in range(n):
        if i == j:
            continue

        elif a[i] % a[j] == 0:
            count += 1
            break
        else:
            continue
    if count == 0:
        ans += 1

print(ans)

### FIXED CODE ###

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

a_max = a[-1]
ans_list = [0] * a_max

ans = 0

for i in range(n-1):

    p = a[i]

    if ans_list[p-1] == 0:
        for q in range(1, (a_max//p)+1):
            ans_list[p*q-1] = 1
            
        if a[i] != a[i+1]:
            ans += 1

if ans_list[a_max-1] == 0:
    ans += 1

print(ans)
### BUGGY CODE ###

from itertools import combinations
 
n, m = [int(i) for i in input().split(' ')]
x_list = [int(i) for i in input().split(' ')]
y_list = [int(i) for i in input().split(' ')]
 
total = 0
for x1, x2 in combinations(x_list, 2):
    for y1, y2 in combinations(y_list,2):
        total += (x2-x1)*(y2-y1)
        
print(int(total % (10**9+7)))

### FIXED CODE ###

n, m = [int(i) for i in input().split(' ')]
x_list = [int(i) for i in input().split(' ')]
y_list = [int(i) for i in input().split(' ')]

x_res = 0
for i in range(n):
    x_res += (i-(n-i-1))*x_list[i]
y_res = 0
for j in range(m):
    y_res += (j-(m-j-1))*y_list[j]
print((x_res*y_res) % (10**9+7))
### BUGGY CODE ###

n, m = map(int,input().split())

par = [i for i in range(n+1)]
rank = [0] * (n+1)

def find(x):
  if par[x] == x:
    return x
  return find(par[x])

def unite(x,y):
  root_x = find(x)
  root_y = find(y)
  if rank[root_x] != rank[root_y]:
    par[min(root_x,root_y)] = max(root_x,root_y)
  else:
    par[root_y] = root_x
    rank[root_x] += 1


for i in range(m):
  x, y, z = map(int,input().split())
  unite(x,y)
  
roo = [-1]

for i in range(n):
  roo.append(find(i+1))

print(len(set(roo))-1)


### FIXED CODE ###

n, m = map(int,input().split())

par = [i for i in range(n+1)]
rank = [0] * (n+1)

def find(x):
  if par[x] == x:
    return x
  return find(par[x])

def unite(x,y):
  root_x = find(x)
  root_y = find(y)
  if rank[root_x] != rank[root_y]:
    par[min(root_x,root_y)] = max(root_x,root_y)
  else:
    par[root_y] = root_x
    rank[root_x] += 1


for i in range(m):
  x, y, z = map(int,input().split())
  unite(x,y)
  
roo = [-1]

for i in range(n):
  roo.append(find(i+1))

print(len(set(roo))-1)
### BUGGY CODE ###

N=int(input())
S=input()

R=[]
G=[]
B=[]
for i in range(N):
    if S[i]=="R":
        R.append(i)
    elif S[i]=="G":
        G.append(i)
    else:
        B.append(i)
    
cnt=0
for i in R:
    for j in G:
        for k in B:
            mini=min(i,j,k)
            maxi=max(i,j,k)
            if i != mini and i !=maxi:
                mid=i
            if j != mini and j !=maxi:
                mid=j
            if k != mini and k !=maxi:
                mid=k
            if maxi-mid!=mid-mini:
                cnt+=1
                
print(cnt)

### FIXED CODE ###

N=int(input())
S=input()

R=[]
G=[]
B=[]
for i in range(N):
    if S[i]=="R":
        R.append(i)
    elif S[i]=="G":
        G.append(i)
    else:
        B.append(i)

cnt=len(R)*len(G)*len(B)
for i in R:
    for j in G:
        koho=set()
        if (j+i)%2==0:
            koho.add((j+i)//2)
        if 0<=2*i-j<N:
            koho.add(2*i-j)
        if 0<=2*j-i<N:
            koho.add(2*j-i)
        for k in koho:
            if k in B:
                cnt-=1
            
                
print(cnt)
### BUGGY CODE ###

N = int(input())
S = input()
R = S.count("R")
G = S.count("G")
B = S.count("B")

ans = R*G*B
for i in range(N-2):
    for j in range(i,N-1):
        k = 2*j - i
        if k < N:
            tmp = []
            tmp.append(S[i])
            tmp.append(S[j])
            tmp.append(S[k])
            if len(set(tmp)) == 3:
                ans -= 1

print(ans)

### FIXED CODE ###

N = int(input())
S = input()
R = S.count("R")
G = S.count("G")
ans = R*G*(N-R-G)

for i in range(N-2):
    for j in range(i,N-1):
        k = 2*j - i
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

            
print(ans)
### BUGGY CODE ###

a = []
n = int(input())
for i in range(n):
    a.append(int(input()))
print(max(a[j] - a[i] for i in range(n) for j in range(i + 1, n)))

### FIXED CODE ###

maxv = -2*10**9
minv = 2*10**9
n = int(input())
for i in range(n):
    x = int(input())
    maxv = max(x - minv, maxv)
    minv = min(x, minv)
print(maxv)
### BUGGY CODE ###

inp = int(input())
A = []
for a in range(inp):
    A.append(int(input()))
    
m = max(A)

for i, a in enumerate(A):
    if a == m:
        A2 = [v for i2, v in enumerate(A) if i2 != i]
        print(max(A2))
    else:
        print(m)


### FIXED CODE ###

inp = int(input())
A = []
for a in range(inp):
    A.append(int(input()))

m = max(A)

# 最大値をとる要素が何個あるかチェック
c = 0
for a in A:
    if a == m:
        c += 1

# 二番目
if len(A) > c:
    second = max([v for v in A if v != m])    

for i, a in enumerate(A):
    if a == m:
        if c > 1:
            print(m)
        else:
            print(second)
    else:
        print(m)
### BUGGY CODE ###

a = int(input())
s =list(map(int,input().split()))
mod = 10 **18
ans = 1
if 0 in s:
    print(0)
    exit()
for i in s:
    ans = ans *i
if ans > 1e18:
    print(-1)
    exit()
print(ans)



### FIXED CODE ###

a = int(input())
s =list(map(int,input().split()))
mod = 10 **18
ans = 1
if 0 in s:
    print(0)
    exit()
for i in s:
    ans = ans *i
    if ans > 1e18:
      print(-1)
      exit()
print(ans)
### BUGGY CODE ###

from itertools import accumulate, combinations

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    sum_A = sum(A)
    B = [0] + list(accumulate(A))
    cand = []
    for i in range(N+1):
        for j in range(i+1,N+1):
            cand.append(B[j] - B[i])
    cand.sort(reverse=True)
    length = len(bin(cand[K-1])[2:])
    num = []
    for c in cand:
        if len(bin(c)[2:]) < length:
            break
        num.append(c)

    ans = 0
    for item in combinations(num,K):
        n = 0
        for i in range(len(item)):
            if i == 0:
                n = item[i]
            n &= item[i]
        ans = max(ans, n)

    print(ans)




if __name__ == "__main__":
    main()

### FIXED CODE ###

from itertools import accumulate

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    sum_A = sum(A)
    B = [0] + list(accumulate(A))
    cand = []
    for i in range(N+1):
        for j in range(i+1,N+1):
            cand.append(B[j] - B[i])
    ans = 0
    for i in range(40):
        bit = 1 << (39 - i)
        cnt = 0
        new_cand = []
        for c in cand:
            if c & bit:
                cnt += 1
                new_cand.append(c)

        if cnt >= K:
            ans += 2 ** (39 - i)
            cand = new_cand


    print(ans)




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

N = int(input())
A = [int(i) for i in input().split()]
r = [-1]*N
s = A.index(min(A))

for i in range(A[s]+1):
  r[s] = i*2
  for j in range(1,N):
    k = (s+j)%N
    r[k] = 2*A[k-1]-r[k-1]
  if (r[s] + r[s-1])//2 == A[s-1]:
    print(" ".join(map(str,r)))
  

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
r = [-1]*N
sumA_ev = sum([A[i] for i in range(N) if i%2 == 1])
r[0] = sum(A) - 2*sumA_ev
for i in range(N-1):
  r[i+1] = 2*A[i] - r[i]
print(" ".join(map(str,r)))
### BUGGY CODE ###

from fractions import gcd

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

ans = 0
tmp = 1
g = gcd(a,b)
while g > 1:
    for i in range(tmp+1,g+1):
        if g%i == 0:
            ans += 1
            tmp = i
            while g%i == 0:
                g //= i
            break
print(ans+1)

### FIXED CODE ###

from fractions import gcd
from math import sqrt, ceil

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

ans = 0
tmp = 1
g = gcd(a,b)
while g > 1:
    for i in range(tmp+1,ceil(sqrt(g))):
        if g%i == 0:
            ans += 1
            tmp = i
            while g%i == 0:
                g //= i
            break
    else:
        # もうgでしか割れないはず
        ans += 1
        break
print(ans+1)
### BUGGY CODE ###

import sys

def solve():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    D = [[int(d) for d in input().split()] for _ in range(C)]
    col = [[int(i) - 1 for i in input().split()] for _ in range(N)]
    minD = 10 ** 20
    for i in range(C):
        for j in range(C):
            if i == j: continue
            for k in range(C):
                if j != k and k != i:
                    this_D = 0
                    changed = [i, j, k]
                    for ni in range(N):
                        for nj in range(N):
                            this_D += D[col[ni][nj]][changed[(ni + nj) % 3]]
                    minD = min(minD, this_D)
    print(minD)

    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

from collections import defaultdict

N, C = map(int, input().split())
D = [[int(i) for i in input().split()] for c in range(C)]
Ini = [[int(i) for i in input().split()] for n in range(N)]
C0, C1, C2 = defaultdict(int), defaultdict(int), defaultdict(int)
D0, D1, D2 = [[0, d] for d in range(C)], [[0, d] for d in range(C)], [[0, d] for d in range(C)]
for i in range(N):
    for j in range(N):
        if (i+j+2)%3 == 0:
            C0[Ini[i][j] - 1] += 1
        elif (i+j+2)%3 == 1:
            C1[Ini[i][j] - 1] += 1
        else:
            C2[Ini[i][j] - 1] += 1

for i in range(C):
    for c in C0:
        D0[i][0] += D[c][i] * C0[c]
    for c in C1:
        D1[i][0] += D[c][i] * C1[c]
    for c in C2:
        D2[i][0] += D[c][i] * C2[c]

D0.sort()
D1.sort()
D2.sort()
Ans = float("inf")
for i in range(3):
    I = D0[i]
    for j in range(3):
        J = D1[j]
        for k in range(3):
            K = D2[k]
            if I[1] != J[1] and J[1] != K[1] and K[1] != I[1]:
                Ans = min(Ans, I[0] + J[0] + K[0])
print(Ans)
### BUGGY CODE ###

h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]
hlist = [0]*h
wlist = [0]*w
for i in hw:
    hlist[i[0]-1]+=1
    wlist[i[1]-1]+=1

h_index = [n for n, v in enumerate(hlist) if v == max(hlist)]

w_index = [n for n, v in enumerate(wlist) if v == max(wlist)]

li = []
for i in h_index:
    for j in w_index:
        li += [hlist[i]+wlist[j]-int([i+1,j+1] in hw)]
print(max(li))



### FIXED CODE ###

#実験 貼り付けコード
h,w,m = map(int,input().split())
s = [list(map(int,input().split())) for _ in range(m)]

r = [0] * (h + 1)
c = [0] * (w + 1)
for x, y in s:
    r[x] += 1
    c[y] += 1
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = sum(x in nr and y in nc for x, y in s)
print(R + C - (len(nr) * len(nc) == count))
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
for i in range(len(X)):
    k = S[X[i][0]-1:X[i][1]]
    print(k.count("AC"))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]

a =[0]*N
for i in range(1,N):
    if S[i] =="C" and S[i-1] =="A":
        a[i] = a[i-1]+1
    else:
        a[i] = a[i-1]
# print(a)
for i in range(Q):
    print(a[X[i][1]-1]-a[X[i][0]-1])
### BUGGY CODE ###

import sys
n,m=map(int,input().split())
for x in range(n+1):
    for y in range(n+1):
        for z in range(n+1):
            if 10000*x+5000*y+1000*z==m and x+y+z==n:
                print(x,y,z)
                sys.exit()
print("-1 -1 -1")

### FIXED CODE ###

n,m=map(int,input().split())
for x in range(n+1):
    for y in range(n+1-x):
        if 10000*x+5000*y+1000*(n-x-y)==m:
            print(x,y,(n-x-y))
            exit()
print('-1 -1 -1')
### BUGGY CODE ###

while True:
    num=int(input())
    if num==0:
        break
    stars=input().split()
    star_list=list(set(stars))
    for i in star_list:
        if stars.count(i) > num/2:
            print(i)
            break
    else:
        print("NO COLOR")
        

### FIXED CODE ###

while True:
    num=int(input())
    if num==0:
        break
    stars=sorted(input().split())
    if stars.count(stars[num//2]) > num/2 :
        print(stars[num//2])
    else:
        print("NO COLOR")
### BUGGY CODE ###

from sys import stdin
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in stdin.readline().rstrip().split()]
q = [[int(x), "B"]  for x in stdin.readline().rstrip().split()]
r = [[int(x), "C"] for x in stdin.readline().rstrip().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r

apples = sorted(apples, reverse=True)
ans = 0
pend = 0

while (X > 0 or Y > 0) and X+Y > pend:
    if apples[0][1] == "C":
        pend += 1
        ans += apples[0][0]
        apples.pop(0)
    elif apples[0][1] == "A":
        if X > 0:
            ans += apples[0][0]
            apples.pop(0)
            X -= 1
        else:
            apples.pop(0)
    elif apples[0][1] == "B":
        if Y>0:
            ans += apples[0][0]
            apples.pop(0)
            Y -= 1
        else:
            apples.pop(0)
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in input().split()]
q = [[int(x), "B"] for x in input().split()]
r = [[int(x), "C"] for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r


apples.sort(reverse=True)
#print(apples)
ans = 0
pend = 0


for hapi, col in apples:
    if col == "C":
        pend += 1
        ans += hapi
    elif col == "A":
        if X > 0:
            ans += hapi
            X -= 1

    elif col == "B":
        if Y>0:
            ans += hapi
            Y -= 1

    if (X < 1 and Y < 1) or X+Y == pend:
        break
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    words = []
    for _ in range(n):
        words.append(input())
    words_set = set(words)
    pairs = {}
    for i in words_set:
        pairs[i] = words.count(i)
    results = [kv[0] for kv in pairs.items() if kv[1] == max(pairs.values())]
    results.sort()
    print(' '.join(map(str, results)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    words = {}
    for _ in range(n):
        a = input()
        if a in words:
            words[a] += 1
        else:
            words[a] = 1
    max_val = 0
    results = []
    for i in words.keys():
        if words[i] > max_val:
            max_val = words[i]
            results = []
            results.append(i)
        elif words[i] == max_val:
            results.append(i)

            # results = [key
            #            for key in words.keys() if words[key] == max(words.values())]
            # results.sort()
    results.sort()
    print('\n'.join(map(str, results)))


if __name__ == "__main__":
    main()