CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))


def is_possible(C):
    res = 0
    for x in A:
        if x+C - N >= 0:
            res += (x+ C - N)//(N+1) + 1
    #print(res,C)
    return int(res <= C)

l = 0  # impossible
r = 10**30  # possible
is_possible(1234567894848)
while r - l > 1:
    M = (l+r)//2
    if is_possible(M)>0:
        r = M
    else:
        l = M
for i in range(10**5,-1,-1):
    if is_possible(r -i):
        print((r-i))
        break

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))


def is_possible(C):
    res = 0
    for x in A:
        if x+C - N >= 0:
            res += (x+ C - N)//(N+1) + 1
    #print(res,C)
    return int(res <= C)

l = 0  # impossible
r = 10**30  # possible

while r - l > 1:
    M = (l+r)//2
    if is_possible(M)>0:
        r = M
    else:
        l = M
for i in range(10**5,-1,-1):
    if is_possible(r -i):
        print((r-i))
        break
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

a.sort()
ans = 0
while a[-1] >= n:
    k = -(-(a[-1]+1)//n)-1
    ans += k
    for i in range(n-1):
        a[i] += k
    a[-1] -= n*k
    a.sort()

print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

ans = 0
while True:
    tmp = 0
    for i in range(n):
        k = -(-(a[i]+1)//n)-1
        tmp += k
        a[i] -= k*n
        a[i] -= k
    for i in range(n):
        a[i] += tmp
    if not tmp:
        break
    ans += tmp

print(ans)
# Original solution

def main():
  x, y, _a, _b, _c = list(map(int, input().split()))
  p = sorted(map(int, input().split()))[-x:]
  q = sorted(map(int, input().split()))[-y:]
  r = sorted(map(int, input().split()), reverse=True)[:x + y]

  arr = sorted(p + q)

  for nc_apple in r:
    apple = arr[0]
    if apple >= nc_apple: break

    arr.pop(0)
    arr.append(nc_apple)

  print((sum(arr)))


main()


# Optimized solution

def main():
  x, y, _a, _b, _c = list(map(int, input().split()))
  p = sorted(map(int, input().split()))[-x:]
  q = sorted(map(int, input().split()))[-y:]
  r = sorted(map(int, input().split()), reverse=True)[:x + y]

  arr = sorted(p + q)
  new_num = 0

  for i, nc_apple in enumerate(r):
    if arr[i] >= nc_apple: break

    new_num += nc_apple - arr[i]

  print((sum(arr) + new_num))


main()
# Original solution
import sys
input = sys.stdin.readline

X,Y,A,B,C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
p = p[A-X:]
q.sort()
q = q[B-Y:]
r.sort()
a = p+q+r
a.sort(reverse=True)
print((sum(a[:X+Y])))

# Optimized solution
import sys
input = sys.stdin.readline
def main():
    X, Y, A, B, C = list(map(int, input().split()))
    p = list(map(int, input().split()))
    p.sort(reverse=True)
    q = list(map(int, input().split()))
    q.sort(reverse=True)
    r = list(map(int, input().split()))
    r.sort(reverse=True)
    target = p[:X] + q[:Y] + r
    target.sort(reverse=True)
    ans = sum(target[:X+Y])
    print(ans)
if __name__ == "__main__":
    main()
# Original solution
x, y, a, b, c = list(map(int, input().split()))
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_N = []

for i in list_A:
    list_N.append([i, "A"])

for i in list_B:
    list_N.append([i, "B"])

for i in list_C:
    list_N.append([i, "C"])

k = x + y
cnt = 0
ans = 0
list_N.sort(key=lambda x:x[0], reverse=True)
while True:
    if cnt == k:
        break
    l = list_N.pop(0)

    if l[1] == "A" and x != 0:
        x -= 1
        cnt += 1
        ans += l[0]

    if l[1] == "B" and y != 0:
        y -= 1
        cnt += 1
        ans += l[0]

    if l[1] == "C":
        cnt += 1
        ans += l[0]

print(ans)

# Optimized solution
x, y, a, b, c = list(map(int, input().split()))
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort(reverse=True)
list_B.sort(reverse=True)
list_C.sort(reverse=True)

list_N = list_A[:x] + list_B[:y] + list_C[:min(c, x + y)]
list_N.sort(reverse=True)
print((sum(list_N[:x+y])))
# Original solution
x, y, a, b, c = list(map(int, input().split()))
 
red = sorted(list(map(int, input().split())), reverse=True)
gre = sorted(list(map(int, input().split())), reverse=True)
non = sorted(list(map(int, input().split())), reverse=True)
 
eat = []
 
for i in range(x):
    eat.append(red.pop(0))
 
for i in range(y):
    eat.append(gre.pop(0))
 
eat.sort()
 
for i in range(len(non)):
    n = non.pop(0)
    if eat[i] < n:
        eat[i] = n
    else:
        break
 
print((sum(eat)))

# Optimized solution
x, y, a, b, c = list(map(int, input().split()))

red = sorted(list(map(int, input().split())), reverse=True)
gre = sorted(list(map(int, input().split())), reverse=True)
non = sorted(list(map(int, input().split())), reverse=True)

red = red[0:x]
gre = gre[0:y]

eat = red + gre + non

eat.sort(reverse=True)

print((sum(eat[0:x+y])))
# Original solution
X,Y,A,B,C=list(map(int, input().split()))
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
AAA=AA[0:X]
BBB=BB[0:Y]
for i in CC:
    if i>min(AAA)or i>min(BBB):
        if min(AAA)>min(BBB):
            BBB[-1]=i
            BBB=sorted(BBB,reverse=True)
        else:
            AAA[-1]=i
            AAA=sorted(AAA,reverse=True)
    else:
        break
print((sum(AAA)+sum(BBB)))

# Optimized solution
X,Y,A,B,C=list(map(int, input().split()))
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
XX=sorted(AA[0:X]+BB[0:Y]+CC,reverse=True)
XX=XX[0:X+Y]
print((sum(XX)))
# Original solution
from collections import deque

N_red_toEat, N_green_toEat, N_red, N_green, N_white = list(map(int, input().split()))

delicious_red = list(map(int, input().split()))
delicious_green = list(map(int, input().split()))
delicious_white = list(map(int, input().split()))

delicious_red.sort(reverse=True)
delicious_green.sort(reverse=True)
delicious_white.sort(reverse=True)

delicious_red = delicious_red[:N_red_toEat]
delicious_green = delicious_green[:N_green_toEat]

Q_red = deque(delicious_red)
Q_green = deque(delicious_green)
Q_white = deque(delicious_white)

summ = 0

for n in range(N_red_toEat + N_green_toEat):
    if (len(Q_red) > 0):
        r_tmp = Q_red.popleft()
    else:
        r_tmp = 0
    
    if (len(Q_green) > 0):
        g_tmp = Q_green.popleft()
    else:
        g_tmp = 0
    
    if (len(Q_white) > 0):
        w_tmp = Q_white.popleft()
    else:
        w_tmp = 0
    
    MAX_tmp = max(r_tmp, g_tmp, w_tmp)
    
    if (MAX_tmp == r_tmp):
        eat = r_tmp
        Q_green.appendleft(g_tmp)
        Q_white.appendleft(w_tmp)
    
    elif (MAX_tmp == g_tmp):
        eat = g_tmp
        Q_red.appendleft(r_tmp)
        Q_white.appendleft(w_tmp)
    
    else:
        eat = w_tmp
        Q_red.appendleft(r_tmp)
        Q_green.appendleft(g_tmp)
    
    summ += eat
    

print(summ)

# Optimized solution
x, y, a, b, c = list(map(int, input().split()))

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

a = sorted(a, reverse=True)[:x]
b = sorted(b, reverse=True)[:y]

al = a + b + c
al.sort(reverse=True)

ans = sum(al[: x + y])

print(ans)
# Original solution
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(min(len(ans),c)):
  if ans[i]<=r[rcount]:
    ans[i]=r[rcount]
    rcount+=1
print((sum(ans)))

# Optimized solution
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
ans=[]
for i in range(x):
  r.append(p[i])
for i in range(y):
  r.append(q[i])
r.sort(reverse=True)
print((sum(r[0:x+y])))
# Original solution
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
p.reverse()
q.sort()
q.reverse()
r.append(0)
r.sort()
r.reverse()
ct=0
P=p[0:x]
Q=q[0:y]
L=P+Q
L.sort()
R=0
for i in range(len(L)):
  if r[R]>L[i]:
    L[i]=r[R]
    if R<c:
      R+=1
print((sum(L)))

# Optimized solution
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
L=p[a-x:a]+q[b-y:b]+r
L.sort()
L.reverse()
print((sum(L[0:x+y])))
# Original solution
x, y, a, b, c = list(map(int,input().split()))
red = sorted(list(map(int,input().split())))[a-x:]
green = sorted(list(map(int,input().split())))[b-y:]
white = sorted(list(map(int,input().split())))
rcnt = 0
gcnt = 0
ans = 0
#print(red,green,white)

for i in range(x+y):
#    print(red,green,white)    
    if red[-1] == max(red[-1],green[-1],white[-1]):
#        print('hoge')
        rcnt += 1
        ans += red.pop(-1)
        if len(red) == 0:
            red = [0]
    elif green[-1] == max(red[-1],green[-1],white[-1]):
#        print('huga')
        gcnt += 1
        ans += green.pop(-1)
        if len(green) == 0:
            green = [0]
    else:
        if red[0] < green[0]:
            rcnt += 1
            red.pop(0)
            if len(red) == 0:
                red = [0]
        else:
            gcnt += 1
            green.pop(0)
            if len(green) == 0:
                green = [0]
#        print('foo')
        ans += white.pop(-1)
        if len(white) == 0:
            white = [0]


print(ans)

# Optimized solution
x, y, a, b, c = list(map(int,input().split()))
red = sorted(list(map(int,input().split())),reverse=True)[:x]
green = sorted(list(map(int,input().split())),reverse=True)[:y]
white = sorted(list(map(int,input().split())),reverse=True)

l = sorted(red+green+white,reverse=True)[:x+y]
print((sum(l)))
# Original solution
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

red = [[i, "r"] for i in p]
green = [[i, "g"] for i in q]
white = [[i, "w"] for i in r]

total = sorted(red + green + white)[::-1]

ans = 0
cnt = 0
r_cnt = 0
g_cnt = 0
for t in total:
    if t[1] == "r" and r_cnt == X:
        continue
    if t[1] == "g" and g_cnt == Y:
        continue
    ans += t[0]
    if t[1] == "r":
        r_cnt += 1
    elif t[1] == "g":
        g_cnt += 1
    cnt += 1
    if cnt == X + Y:
        break

print(ans)

# Optimized solution
X, Y, A, B, C = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))[-X:]
q = sorted(list(map(int, input().split())))[-Y:]
r = list(map(int, input().split()))

total = sorted(p + q + r)[::-1]
print((sum(total[:X + Y])))
# Original solution
X, Y, A, B, C = list(map(int, input().split()))
R = list(map(int, input().split()))
G = list(map(int, input().split()))
C = list(map(int, input().split()))

R.sort()
R.reverse()
G.sort()
G.reverse()
C.sort()
C.reverse()

R = R[:X]
G = G[:Y]

temp = 0
  
for i in range(len(C)) :
  if((X==0) and (Y==0)) :
    break
  if(X==0) :
    last = G[Y-1]
    Y -= 1
    
  else :
    if(Y==0) :
      last = R[X-1]
      X -= 1
    else :
      if(R[X-1] < G[Y-1]) :
        last = R[X-1]
        X -= 1
      else :
        last = G[Y-1]
        Y -= 1

  if(C[i] < last) :
    if(i == 0) :
      answer = sum(R[:X]) + sum(G[:Y]) + last
    else :
      break
  else :
    answer = sum(R[:X]) + sum(G[:Y]) + sum(C[:i+1])
    
print(answer)

# Optimized solution
X, Y, A, B, C = list(map(int, input().split()))
R = list(map(int, input().split()))
G = list(map(int, input().split()))
C = list(map(int, input().split()))

R.sort()
R.reverse()
G.sort()
G.reverse()
C.sort()
C.reverse()

R = R[:X]
G = G[:Y]

temp = 0
  
for i in range(len(C)) :
  if((X==0) and (Y==0)) :
    i = i-1
    break
  if(X==0) :
    last = G[Y-1]
    Y -= 1
    
  else :
    if(Y==0) :
      last = R[X-1]
      X -= 1
    else :
      if(R[X-1] < G[Y-1]) :
        last = R[X-1]
        X -= 1
      else :
        last = G[Y-1]
        Y -= 1

  if(C[i] < last) :
      break
  else :
    last = C[i]
    
print((sum(R[:X])+sum(G[:Y])+sum(C[:i])+last))
# Original solution
import sys

X, Y, A, B, C = list(map(int, sys.stdin.readline().strip().split()))

P = list(map(int, sys.stdin.readline().strip().split()))
Q = list(map(int, sys.stdin.readline().strip().split()))
R = list(map(int, sys.stdin.readline().strip().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

P = P[:X]
P.sort()
Q = Q[:Y]
Q.sort()

ans = 0
i, j, k = 0, 0, 0
while C > k:
    if X > i and Y > j:

        if P[i] >= Q[j]:
            if R[k] > Q[j] and Y > j:
                Q[j] = R[k]
                j += 1
                k += 1
            elif R[k] > P[i] and X > i:
                P[i] = R[k]
                i += 1
                k += 1
            else:
                break
 
        elif P[i] < Q[j]:
            if R[k] > P[i] and X > i:
                P[i] = R[k]
                i += 1
                k += 1
            elif R[k] > Q[j] and Y > j:
                Q[j] = R[k]
                j += 1
                k += 1
            else:
                break
    elif X > i:
        if R[k] > P[i]:
            P[i] = R[k]
            i += 1
            k += 1
        else:
            break
    elif Y > j:
        if R[k] > Q[j]:
            Q[j] = R[k]
            j += 1
            k += 1
    else:
        break

# print(P)
# print(Q)
print((sum(P) + sum(Q)))

# Optimized solution
import sys

X, Y, A, B, C = list(map(int, sys.stdin.readline().strip().split()))

P = list(map(int, sys.stdin.readline().strip().split()))
Q = list(map(int, sys.stdin.readline().strip().split()))
R = list(map(int, sys.stdin.readline().strip().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ans = P[:X] + Q[:Y] + R
ans.sort(reverse=True)
print((sum(ans[:X+Y])))
# Original solution
def red_and_green_apples(X, Y, A, B, C, P, Q, R):
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    P = P[:X]
    Q = Q[:Y]
    q = P + Q + R
    q.sort(reverse=True)

    return sum(q[:X + Y])


X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

print((red_and_green_apples(X, Y, A, B, C, P, Q, R)))

# red_and_green_apples(
#     1, 2, 2, 2, 1,
#     [2, 4],
#     [5, 1],
#     [3],
# )
#
# red_and_green_apples(
#     2, 2, 2, 2, 2,
#     [8, 6],
#     [9, 1],
#     [2, 1],
# )


# Optimized solution
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = P[:X] + Q[:Y] + R
a.sort(reverse=True)

print((sum(a[:X + Y])))
# Original solution
LMIIS = lambda: list(map(int,input().split()))
X,Y,*e = LMIIS()
P = LMIIS()
Q = LMIIS()
R = LMIIS()
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
print((sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y])))

# Optimized solution
f=lambda:list(map(int,input().split()))
X,Y,*e=f()
P=f()
Q=f()
R=f()
P.sort()
Q.sort()
R.sort()
print((sum(sorted(P[-X:]+Q[-Y:]+R)[-X-Y:])))
# Original solution
import sys
input = sys.stdin.readline
from heapq import *

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
pq = []
ans = 0

for i in range(X):
    heappush(pq, p[i])
    ans += p[i]

for i in range(Y):
    heappush(pq, q[i])
    ans += q[i]

r.sort(reverse=True)
now = ans

for i in range(C):
    now -= heappop(pq)
    heappush(pq, r[i])
    now += r[i]
    ans = max(ans, now)

print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l = p[:X]+q[:Y]
l.sort()
s = sum(l)
ans = s
pre = s

for i in range(min(len(l), C)):
    ans = max(ans, pre-l[i]+r[i])
    pre = pre-l[i]+r[i]

print(ans)
# Original solution
import heapq

x, y, a, b, c = list(map(int, input().split()))

def max_listup(limit):
  l = list([int(x)*-1 for x in input().split()])
  heapq.heapify(l)
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = heapq.heappop(l)
    res.append(m*-1)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)


# Optimized solution
import heapq

x, y, a, b, c = list(map(int, input().split()))

def max_listup(limit):
  l = sorted(list(map(int, input().split())))
  cnt = 1
  res = []
  while l:
    if cnt > limit:
      break
    m = l.pop()
    res.append(m)
    cnt += 1
  return res

if __name__ == "__main__":
  all = sorted(max_listup(x) + max_listup(y) + list(map(int, input().split())))
  ans = 0
  for _ in range(x+y):
    ans += all.pop()

  print(ans)
# Original solution
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

z = sorted(p)[-X:] + sorted(q)[-Y:] + r
print((sum(sorted(z)[-(X+Y):])))


# Optimized solution

X, Y, A, B, C = list(map(int, input().split()))
P = sorted(map(int, input().split()))
Q = sorted(map(int, input().split()))
R = sorted(map(int, input().split()))

cand = sorted(P[-X:] + Q[-Y:] + R)
print((sum(cand[-X-Y:])))
# Original solution
x,y,a,b,c = list(map(int, input().split()))
result=sorted(list(map(int, input().split())), reverse=True)[:x]
result+=sorted(list(map(int, input().split())), reverse=True)[:y]
r=sorted(list(map(int, input().split())), reverse=True)
s = sum(result)
for el in r:
    t = el - min(result)
    if t>0:
        s += t
print(s)


# Optimized solution
x, y, a, b, c = list(map(int, input().split()))
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
result = p[:x] + q[:y] + r
result = sorted(result, reverse=True)
print((sum(result[:x+y])))
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:12:42 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
X, Y, A, B, C = list(map(int,input().split()))
r = list(map(int,input().split()))
g = list(map(int,input().split()))
n = list(map(int,input().split()))

r.sort()
g.sort()
n.sort()

x, y = A-X, B-Y
z = C-1
ans = 0
ans += sum(r[x:])
ans += sum(g[y:])
g.append(10**10)
#print(x,y,z,r[x],g[y],n[z],ans)
while z >= 0:
#    print(x,y,z,r[x],g[y],n[z],ans)
    flg = True
    if x < A and r[x] < n[z] and r[x] < g[y]:
        ans += (n[z] - r[x])
        x += 1
        z -= 1
        flg = False
    elif y < B and g[y] < n[z]:
        ans += (n[z] - g[y])
        y += 1
        z -= 1
        flg = False
    if flg:
        break
#print(x,y,z,r[x],g[y],n[z],ans)
print(ans)



# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:12:42 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
X, Y, A, B, C = list(map(int,input().split()))
r = list(map(int,input().split()))
g = list(map(int,input().split()))
n = list(map(int,input().split()))

r.sort()
g.sort()

r = r[-X:]
g = g[-Y:]

all_apple = r+g+n
all_apple.sort()
ans = sum(all_apple[-(X+Y):])

print(ans)
# Original solution
x, y, a, b, c = list(map(int,input().split()))
datp = list(map(int, input().split()))
datq = list(map(int, input().split()))
datr = list(map(int, input().split()))
datp.sort(reverse=True)
datq.sort(reverse=True)
datr.sort(reverse=True)
res = sum(datp[:x]) + sum(datq[:y])
pl, pr = 0, x - 1
ql, qr = 0, y - 1
#print(datp)
#print(datq)
#print(datr)
#print("defaultt", res)

for i in range(c):
    #print(" musyoku ", i , "=", datr[i])
    #print("pr{0}, qr{1}".format(pr, qr))
    diffp, diffq = -1, -1
    if pr >= 0:
        diffp = datr[i] - datp[pr] # この無色を取ったときのメリット
    if qr >= 0:
        diffq = datr[i] - datq[qr] # この無色を取ったときのメリット
    #print("diffp", diffp, "diffq", diffq)
    if diffp <= 0 and diffq <= 0: # デメリットしか両者ないならいらない
        #print("break")
        break
    if diffp >= diffq and pr >= 0: # pを押し出したほうがいいなら
        #print("get p")
        res += diffp
        pr -= 1
    elif qr >= 0 and diffq > 0: #qを押し出したほうがいいなら
        #print("get q")
        res += diffq
        qr -= 1

print(res)


# Optimized solution
x, y, a, b, c = list(map(int,input().split()))
datp = sorted(list(map(int, input().split())), reverse=True)
datq = sorted(list(map(int, input().split())), reverse=True)
datr = sorted(list(map(int, input().split())), reverse=True)
dat = sorted(datp[:x] + datq[:y] + datr, reverse=True)
print((sum(dat[:x+y])))
# Original solution
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 i in range(len(apples)):
    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)
    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)


# Optimized solution
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)
# Original solution
x, y, a, b, c = list(map(int, input().split()))
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)
rn.sort(reverse=True)

pq = pn[:x] + qn[:y]
rcount = 0

while min(pq) <= rn[0]:
  pq.remove(min(pq))
  pq.append(rn[0])
  del rn[0]
  if len(rn) == 0:
    break
  
print((sum(pq)))


# Optimized solution
x, y, a, b, c = list(map(int, input().split()))
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)

pqr = pn[:x] + qn[:y] + rn
pqr.sort(reverse=True)
  
print((sum(pqr[:x+y])))