Problem:
 Score : 500 points    Problem Statement You are going to eat X red apples and Y green apples. You have A red apples of deliciousness p_1,p_2, \dots, p_A , B green apples of deliciousness q_1,q_2, \dots, q_B , and C colorless apples of deliciousness r_1,r_2, \dots, r_C . Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively. From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible. Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.      Constraints  1 \leq X \leq A \leq 10^5  1 \leq Y \leq B \leq 10^5  1 \leq C \leq 10^5  1 \leq p_i \leq 10^9  1 \leq q_i \leq 10^9  1 \leq r_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  X  Y  A  B  C  p_1  p_2  ...  p_A  q_1  q_2  ...  q_B  r_1  r_2  ...  r_C       Output Print the maximum possible sum of the deliciousness of the eaten apples.        Sample Input 1 1 2 2 2 1
2 4
5 1
3      Sample Output 1 12  The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:   Eat the 2 -nd red apple.  Eat the 1 -st green apple.  Paint the 1 -st colorless apple green and eat it.        Sample Input 2 2 2 2 2 2
8 6
9 1
2 1      Sample Output 2 25       Sample Input 3 2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4      Sample Output 3 74

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]



def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res



def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    X, Y, A, B, C = NMI()
    P = NLI()
    Q = NLI()
    R = NLI()
    reds = [[1, p] for p in P]
    greens = [[2, q] for q in Q]
    skels = [[0, r] for r in R]
    apples = reds + greens + skels
    apples.sort(key=lambda x: x[1], reverse=True)

    colors = [0, 0, 0]
    limits = [10**9, X, Y]
    ans = 0
    for color, a in apples:
        if sum(colors) >= X + Y:
            break

        if colors[color] <= limits[color] - 1:
            colors[color] += 1
            ans += a
            continue

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)









x,y,a,b,c=n1()
P=n1()
Q=n1()
R=n1()

P.sort()
Q.sort()

A=P[-x:]+Q[-y:]+R

A.sort()
print(sum(A[-x-y:]))

Solution (Python):
X,Y,A,B,C=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)

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

print(sum(S[:X+Y]))

Solution (Python):
x,y,a,b,c=map(int,input().split())
R=sorted(map(int,input().split()),reverse=True)
G=sorted(map(int,input().split()),reverse=True)
N=sorted(map(int,input().split()),reverse=True)
L=sorted(R[:x]+G[:y]+N[:(x+y)],reverse=True)
print(sum(L[:(x+y)]))

Solution (Python):
import sys 
x,y,A,B,C=map(int,sys.stdin.readline().split())
R=list(map(int,sys.stdin.readline().split()))
G=list(map(int,sys.stdin.readline().split()))
N=list(map(int,sys.stdin.readline().split()))
arr=[]
for i in range(A):
    arr.append([R[i],-1])
for i in range(B):
    arr.append([G[i],-2]) 
for i in range(C):
    arr.append([N[i],-3])    
arr.sort(reverse=True)
ans=0
adv=0
for i in range(len(arr)):
    if x+y==adv:
        break
    if arr[i][1]==-1:
        if x>0:
            ans+=arr[i][0]
            x-=1 
    elif arr[i][1]==-2:
        if y>0:    
            ans+=arr[i][0]
            y-=1
    else:
        ans+=arr[i][0]
        adv+=1 
        
print(ans)

Solution (Python):
x,y,A,B,C=map(int,input().split())
R=list(map(int,input().split()))
G=list(map(int,input().split()))
N=list(map(int,input().split()))
arr=[]
for i in range(A):
    arr.append([R[i],-1])
for i in range(B):
    arr.append([G[i],-2]) 
for i in range(C):
    arr.append([N[i],-3])    
arr.sort(reverse=True)
ans=0
adv=0
for i in range(len(arr)):
    if x+y==adv:
        break
    if arr[i][1]==-1:
        if x>0:
            ans+=arr[i][0]
            x-=1 
    elif arr[i][1]==-2:
        if y>0:    
            ans+=arr[i][0]
            y-=1
    else:
        ans+=arr[i][0]
        adv+=1 
        
print(ans)

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p, q, r = [list(map(int, input().split())) for _ in range(3)]

p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]

l = p+q+r

l.sort(reverse=True)

print(sum(l[:X+Y]))

Solution (Python):
X, Y, A, B, C = 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()

R = p[:X]
G = q[:Y]
i = X - 1
j = Y - 1
con = True
while con and len(r) > 0:
    rr = r.pop()
    if R[i] < G[j]:
        if R[i] < rr:
            R[i] = rr
            i -= 1
            continue
        else:
            con = False
    else:
        if G[j] < rr:
            G[j] = rr
            j -= 1
            continue
        else:
            con = False

print(sum(R) + sum(G))

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def main():
    X,Y,A,B,C = map(int,input().split())
    P = sorted(list(map(int,input().split())),reverse=True)
    Q = sorted(list(map(int,input().split())),reverse=True)
    R = list(map(int,input().split()))

    print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))

if __name__ == "__main__":
  main()

Solution (Python):
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 = 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))

Solution (Python):
import sys
from io import StringIO
import unittest
import copy



def resolve():
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))

    p.sort(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    
    
    def_red = copy.copy(p[0:x])
    def_grren = copy.copy(q[0:y])

    
    redcnt = -1
    grncnt = -1
    def_red_cnt = len(def_red)
    def_grren_cnt = len(def_grren)

    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            
            def_grren[grncnt] = r[i]

            if grncnt is not -def_grren_cnt:
                grncnt -= 1

        else:
            
            def_red[redcnt] = r[i]

            if redcnt is not -def_red_cnt:
                redcnt -= 1


    print(sum(def_red) + sum(def_grren))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)







    








if __name__ == "__main__":
    
    resolve()

Solution (Python):
from collections import Counter

X,Y,A,B,C=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()
p_list=p[-X:]
q_list=q[-Y:]
r.extend(p_list)
r.extend(q_list)
r.sort()
print(sum(r[-(X+Y):]))

Solution (Python):
x,y,a,b,c=map(int,input().split())
reds=sorted(list(map(int,input().split())))
greens=sorted(list(map(int,input().split())))
neutral=sorted(list(map(int,input().split())))

reds=reds[a-x:]
greens=greens[b-y:]
total=sorted(reds+greens+neutral)

print(sum(total[len(total)-x-y:]))

Solution (Python):
import sys
input = sys.stdin.readline

X, Y, A, B, C = 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)

ans = sum(P[:X]) + sum(Q[:Y])
x = X-1
y = Y-1
for z in range(C):
    if x < 0:
        if R[z] > Q[y]:
            ans += R[z] - Q[y]
            y -= 1
    elif y < 0:
        if R[z] > P[x]:
            ans += R[z] - P[x]
            x -= 1
    else:
        if R[z] > P[x] >= Q[y]:
            ans += R[z] - Q[y]
            y -= 1
        elif R[z] > Q[y] > P[x]:
            ans += R[z] - P[x]
            x -= 1
        elif P[x] >= R[z] > Q[y]:
            ans += R[z] - Q[y]
            y -= 1
        elif Q[y] >= R[z] > P[x]:
            ans += R[z] - P[x]
            x -= 1
print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
p =list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p)
q = sorted(q)

p = p[(len(p)-x):]
q = q[(len(q)-y):]
r = r + p
r = r + q
r = sorted(r)
print(sum(r[(len(r)-x-y):]))

Solution (Python):
from collections import deque
X,Y,A,B,C = 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()
p = deque(p)
q = deque(q)
r = deque(r)
p.appendleft(0)
q.appendleft(0)
r.appendleft(0)


a = p.pop()
b = q.pop()
c = r.pop()
x = 0
y = 0
ans = 0
for i in range(X+Y):
    if x < X and y < Y:
        if a >= b and a >= c:
            ans += a
            x += 1
            a = p.pop()
        elif b >= c:
            ans += b
            y += 1
            b = q.pop()
        else:
            ans += c
            c = r.pop()
    elif x < X:
        if a >= c:
            ans += a
            x += 1
            a = p.pop()
        else:
            ans += c
            c = r.pop()
    else:
        if b >= c:
            ans += b
            y += 1
            b = q.pop()
        else:
            ans += c
            c = r.pop()

print(ans)

Solution (Python):
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    t = [1]
    t.sort()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if i < c:
            if s[i] < R[i]:
                s[i] = R[i]
            else:
                break
        else:
            break
    print(sum(s))


if __name__ == "__main__":
    main()

Solution (Python):
X,Y,A,B,C=map(int,input().split())

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()

R=RO[A-X:A]
G=GO[B-Y:B]

TO.extend(R)
TO.extend(G)

TO.sort(reverse=True)

T=TO[0:X+Y]

print(sum(T))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
IronMan = sorted(p)
CaptainAmerica = sorted(q)
for i in range(X):
    r.append(IronMan.pop())
for i in range(Y):
    r.append(CaptainAmerica.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))

Solution (Python):
X,Y,A,B,C = map(int,input().split())
r = sorted(list(map(int,input().split())),reverse=True)[:X]
g = sorted(list(map(int,input().split())),reverse=True)[:Y]
w = list(map(int,input().split()))

new = sorted(r+g+w,reverse=True)
print(sum(new[:X+Y]))

Solution (Python):
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)

AD = P[:X] + Q[:Y] + R
AD.sort(reverse=True)
print(sum(AD[:(X+Y)]))
exit(0)


ans = sum(P[:X]) + sum(Q[:Y])

pi, qi, ri = X-1, Y-1, 0
for _ in range(C+10):
  if P[pi] < R[ri] and P[pi] <= Q[qi]:
    ans += R[ri] - P[pi]
    pi, ri = pi-1, ri+1
  elif Q[qi] < R[ri] and P[pi] >= Q[qi]:
    ans += R[ri] - Q[qi]
    qi, ri = qi-1, ri+1
  if pi < 0 or qi < 0 or ri >= C:
    break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

x, y, a, b, c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)

p = p[:x]
q = q[:y]

p_and_q = p + q

import heapq

heapq.heapify(p_and_q)

while r:
    temp = max(heapq.heappop(p_and_q), r.pop())
    heapq.heappush(p_and_q, temp)

print(sum(p_and_q))

Solution (Python):

from collections import deque

X,Y,A,B,C = map(int, input().split())
p_list = [int(e) for e in input().split()]
q_list = [int(e) for e in input().split()]
r_list = [int(e) for e in input().split()]

p_list.sort(reverse=True)
q_list.sort(reverse=True)
r_list.sort(reverse=False)


red_apples = p_list[0:min(A,X)]
green_apples = q_list[0:min(B,Y)]

colorless_apples = r_list







if len(red_apples) < X:
    shortage = X - len(red_apples)
    red_apples += colorless_apples[0:shortage]
    del colorless_apples[0:shortage]
if len(green_apples) < Y:
    shortage = Y - len(green_apples)
    green_apples += colorless_apples[0:shortage]
    del colorless_apples[0:shortage]






eat_apples = red_apples + green_apples
eat_apples.sort(reverse=True)




lowest_apple = eat_apples.pop(-1)

replaced_deque = deque() 











for i in range(len(colorless_apples)):

    
    
    
    
    

    if colorless_apples[i] > lowest_apple:
        replaced_deque.appendleft(colorless_apples[i])

        if len(eat_apples) > 0:
            if replaced_deque[-1] < eat_apples[-1]:
                lowest_apple = replaced_deque.pop()
            else:
                lowest_apple = eat_apples.pop(-1)
        else:
            lowest_apple = replaced_deque.pop()

print(sum(eat_apples) + sum(replaced_deque) + lowest_apple)

Solution (Python):
x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())),reverse=True)[:x]
q = sorted(list(map(int,input().split())),reverse=True)[:y]
r = list(map(int,input().split()))
print(sum(sorted(p+q+r,reverse=True)[:(x+y)]))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
ps = list(map(int, input().split()))
qs = list(map(int, input().split()))
rs = list(map(int, input().split()))
ps = sorted(ps, reverse=True)[:X]
qs = sorted(qs, reverse=True)[:Y]
rs = sorted(ps+qs+rs, reverse=True)[:X+Y]
r = sum(rs)
print(r)

Solution (Python):
x, y, a, b, c = 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()

for _ in range(x):
    r.append(p.pop())

for _ in range(y):
    r.append(q.pop())

r.sort()
ans = 0

for _ in range(x+y):
    ans += r.pop()

print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())))[a-x:]
q = sorted(list(map(int, input().split())))[b-y:]
r = sorted(list(map(int, input().split()))+p+q)[::-1]

print(sum(r[:x+y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())))[a-x:]
q = sorted(list(map(int, input().split())))[b-y:]
r = sorted(list(map(int, input().split()))+p+q)[::-1]

print(sum(r[:x+y]))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def Yes(): print("Yes"); return
def No(): print("No"); return


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





X,Y,A,B,C = inputIL()
p = inputIL()+[0]*X
q = inputIL()+[0]*Y
r = inputIL()

p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

p = p[:X]
q = q[:Y]

a = p+q+r

a.sort(reverse=True)

print(sum(a[:X+Y]))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def Yes(): print("Yes"); return
def No(): print("No"); return


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





X,Y,A,B,C = inputIL()
p = inputIL()+[0]*X
q = inputIL()+[0]*Y
r = inputIL()

p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

p = p[:X]
q = q[:Y]

wp = p.pop()
wq = q.pop()

eat_p = []
eat_q = []

while C:
  br = r.pop()
  C -= 1
  if min(wp,wq) < br:
    if wp<wq:
      eat_p.append(br)
      if p:
        wp = p.pop()
      else:
        wp = INF
    else:
      eat_q.append(br)
      if q:
        wq = q.pop()
      else:
        wq = INF
        
eat_p += p
eat_q += q
if wp != INF:
  eat_p.append(wp)
if wq != INF:
  eat_q.append(wq)

print(sum(eat_p)+sum(eat_q))

Solution (Python):
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)
 
p.append(float("inf"))
q.append(float("inf")) 

Z = 0
while Z < C:
  if min(p[X - 1], q[Y - 1]) < r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
    continue
  break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

Solution (Python):
X,Y,A,B,C=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)
P.append(float("inf"))
Q.append(float("inf"))
ans=sum(P[:X]+Q[:Y])
rfinish=False
gfinish=False
r,g,f=X-1,Y-1,0
while f<C and (R[f]>P[r] or R[f]>Q[g]):
    if P[r]<Q[g]:
        ans=ans-P[r]+R[f]
        r-=1
        f+=1
    else:
        ans=ans-Q[g]+R[f]
        g-=1
        f+=1
print(ans)

Solution (Python):
from heapq import heapify, heappop
from collections import deque

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(lambda x: -1 * int(x), input().split(' ')))

p = sorted(p, reverse=True)
q = sorted(q, reverse=True)

s = p[:x] + q[:y]
s.sort()

heapify(r)

for i, _s in enumerate(s):
    if len(r) == 0:
        break

    n = -1 * heappop(r)
    if n > _s:
        s[i] = n

print(sum(s))

Solution (Python):
import sys
input = sys.stdin.buffer.readline
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
Ans = []
for p in P:
    Ans.append((p, 1))
for q in Q:
    Ans.append((q, 2))
for r in R:
    Ans.append((r, 3))
Ans.sort(reverse=True)

x = 0
y = 0
num = 0
ans = 0

for i, j in Ans:
    if j == 1:
        if x == X:
            continue
        else:
            x += 1
            num += 1
            ans += i
    elif j == 2:
        if y == Y:
            continue
        else:
            y += 1
            num += 1
            ans += i
    else:
        num += 1
        ans += i
    if num == X+Y:
        break
print(ans)

Solution (Python):
X, Y, R, G, N = map(int, input().split())
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]

apple = r + g + n
apple = sorted(apple)[len(apple)-(X+Y):]
print(sum(apple))

Solution (Python):
X, Y, R, G, N = map(int, input().split())
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
n = sorted(n, reverse=True)

nr = 0; ng = 0; nn = 0
for i in range(N):
    if n[nn] <= min(r[nr], g[ng]):
        break
    if r[nr] < g[ng]:
        r[nr] = n[nn]
        nr += 1
        if nr == X:
            nr = X-1
    else:
        g[ng] = n[nn]
        ng += 1
        if ng == Y:
            ng = Y-1
    nn += 1

print(sum(r) + sum(g))

Solution (Python):
x,y,a,b,c = 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)
apples = p[0:x]+q[0:y]+r
print(sum(sorted(apples,reverse=True)[0:x+y]))

Solution (Python):
x,y,a,b,c = 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 = sum(p[0:x]) + sum(q[0:y])
red = x-1
green = y-1
colorless = 0

while colorless < c:
	
	if red >= 0 and green >= 0:
		if p[red] < q[green]:
			if r[colorless] > p[red]:
				result -= p[red]
				result += r[colorless]
				colorless += 1
				red -= 1
			else:
				break
		else:
			if r[colorless] > q[green]:
				result -= q[green]
				result += r[colorless]
				colorless += 1
				green -= 1
			else:
				break
	elif red >= 0:
		if r[colorless] > p[red]:
			result -= p[red]
			result += r[colorless]
			colorless += 1
			red -= 1
		else:
			break
	elif green >= 0:
		if r[colorless] > q[green]:
			result -= q[green]
			result += r[colorless]
			colorless += 1
			green -= 1
		else:
			break
print(result)

Solution (Python):
X,Y,A,B,C = 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)

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

print(sum(C[:X+Y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = list(reversed(sorted(list(map(int, input().split())))))
q = list(reversed(sorted(list(map(int, input().split())))))
r = list(reversed(sorted(list(map(int, input().split())))))
del p[x:]
del q[y:]
l = list(reversed(sorted(p + q + r)))
print(sum(l[:x + y]))

Solution (Python):



                            
                            
                            
                            



import sys
import math


def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printwsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end="tst, ")

MODPRIME = int(1e9+7); BABYMOD = 998244353;



x, y, a, b, c = get_ints()
la = get_array()
lb = get_array()
lc = get_array()
la.sort(reverse = True)
lb.sort(reverse = True)
for i in range(x):
    lc.append(la[i])
for i in range(y):
    lc.append(lb[i])
lc.sort(reverse = True)
sum = 0
for i in range(x+y):
    sum += lc[i]
print(sum)



'''
THE LOGIC AND APPROACH IS BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
: DO NOT PLAGIARISE.
'''

Solution (Python):
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_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

total = sum(sorted(pq_rev + r, reverse=True)[:x+y])
print(total)

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, y, a, b, c = map(int, input().split())
    pqr = []
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    for i in range(a):
        pqr.append([p[i], 1])
    for i in range(b):
        pqr.append([q[i], 2])
    for i in range(c):
        pqr.append([r[i], 0])
    pqr.sort(reverse=True)

    ans = 0
    c_a = 0
    c_b = 0
    c_c = 0
    for v, k in pqr:
        if k == 1 and c_a < x:
            ans += v
            c_a += 1
        elif k == 2 and c_b < y:
            ans += v
            c_b += 1
        elif k == 0 and c_a + c_b + c_c < x + y:
            ans += v
            c_c += 1
        if c_a + c_b + c_c == x + y:
            print(ans)
            exit()


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x,y,a,b,c=MI()
ps=sorted(LI(),reverse=True)
qs=sorted(LI(),reverse=True)
rs=sorted(LI(),reverse=True)
ps=ps[0:x]
qs=qs[0:y]
u=rs+ps+qs
u.sort(reverse=True)
print(sum(u[0:x+y]))

Solution (Python):
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)
p=p[:x]
q=q[:y]
r.extend(p)
r.extend(q)
r.sort(reverse=True)

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

print(ans)

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, Y, A, B, C = lr()
P = lr(); P.sort(reverse=True)
Q = lr(); Q.sort(reverse=True)
R = lr(); R.sort(reverse=True)
P = P[:X]
Q = Q[:Y]
Z = P + Q + R
Z.sort(reverse=True)
answer = sum(Z[:X+Y])
print(answer)