Buggy python submission (verdict: Runtime Error):
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]

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

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if ri < P[p_i] and ri < Q[q_i]:
        break

    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)



Fixed submission:
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]

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

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)

Buggy python submission (verdict: Runtime Error):
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]

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

p_i = 0
q_i = 0

for ri in R:
    if ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)



Fixed submission:
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]

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

p_i = 0
q_i = 0

for ri in R:
    if p_i >= len(P) and q_i >= len(Q):
        break
    if p_i >= len(P):
        if ri >= Q[q_i]:
            Q[q_i] = ri
            q_i += 1
    elif q_i >= len(Q):
        if ri >= P[p_i]:
            P[p_i] = ri
            p_i += 1
    elif ri < P[p_i] and ri < Q[q_i]:
        break
    elif ri > P[p_i] and ri > Q[q_i]:
        d1 = ri - P[p_i]
        d2 = ri - Q[q_i]
        if d1 > d2:
            P[p_i] = ri
            p_i += 1
        else:
            Q[q_i] = ri
            q_i += 1
    elif ri > P[p_i] and ri < Q[q_i]:
        P[p_i] = ri
        p_i += 1
    else:
        Q[q_i] = ri
        q_i += 1


# print(P, Q)
ans = sum(P) + sum(Q)
print(ans)