Buggy python submission (verdict: Runtime Error):
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(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

if r:
    while min(deque_p[-1], deque_q[-1]) < r[0]:
        if deque_p[-1] <= deque_q[-1]:
            deque_p.pop()
            deque_r.append(r.popleft())
        else:
            deque_q.pop()
            deque_r.append(r.popleft())

        if not r:
            break

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)


Fixed submission:
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(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

if r:
    while min(deque_p[-1], deque_q[-1]) < r[0]:
        if deque_p[-1] <= deque_q[-1]:
            deque_p.pop()
            deque_r.append(r.popleft())
        else:
            deque_q.pop()
            deque_r.append(r.popleft())

        if (not r) or (not deque_p) or (not deque_q):
            break

if r and deque_p:
    while deque_p[-1] < r[0]:
        deque_p.pop()
        deque_r.append(r.popleft())

        if (not r) or (not deque_p):
            break

if r and deque_q:
    while deque_q[-1] < r[0]:
        deque_q.pop()
        deque_r.append(r.popleft())

        if (not r) or (not deque_q):
            break
    

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)

Buggy python submission (verdict: Runtime Error):
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(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

while min(deque_p[-1], deque_q[-1]) < r[0]:
    if deque_p[-1] <= deque_q[-1]:
        deque_p.pop()
        deque_r.append(r.popleft())
    else:
        deque_q.pop()
        deque_r.append(r.popleft())

    if not r:
        break

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)


Fixed submission:
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(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

r = deque(r)
deque_p = deque(p[:X])
deque_q = deque(q[:Y])
deque_r = deque([])

if r:
    while min(deque_p[-1], deque_q[-1]) < r[0]:
        if deque_p[-1] <= deque_q[-1]:
            deque_p.pop()
            deque_r.append(r.popleft())
        else:
            deque_q.pop()
            deque_r.append(r.popleft())

        if (not r) or (not deque_p) or (not deque_q):
            break

if r and deque_p:
    while deque_p[-1] < r[0]:
        deque_p.pop()
        deque_r.append(r.popleft())

        if (not r) or (not deque_p):
            break

if r and deque_q:
    while deque_q[-1] < r[0]:
        deque_q.pop()
        deque_r.append(r.popleft())

        if (not r) or (not deque_q):
            break
    

ans = sum(deque_p) + sum(deque_q) + sum(deque_r)

print(ans)