Buggy python submission (verdict: Runtime Error):
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 = p[:x]
q = q[:y]
p.append(0)
q.append(0)

wa = x + y

lsp = x - 1
lsq = y - 1

pi = 0
qi = 0
ri = 0

ans = 0

for i in range(wa):
    if x > 0 and p[pi] == max(p[pi], q[qi], r[ri]):
        ans += p[pi]
        pi += 1
        x -= 1
    elif y > 0 and q[qi] == max(p[pi], q[qi], r[ri]):
        ans += q[qi]
        qi += 1
        y -= 1
    elif r[ri] == max(p[pi], q[qi], r[ri]):
        ans += r[ri]
        ri += 1
        if y > 0 and p[lsp] >= q[lsq]:
            y -= 1
            if lsq == 0:
                continue
            else:
                lsq -= 1
        elif x > 0 and p[lsp] < q[lsq]:
            x -= 1
            if lsp == 0:
                continue
            else:
                lsp -= 1

print(ans)

Fixed submission:
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 = p[:x]
q = q[:y]
p.append(0)
q.append(0)
r += [0] * (10 ** 3)


wa = x + y

lsp = x - 1
lsq = y - 1

pi = 0
qi = 0
ri = 0

ans = 0

for i in range(wa):
    if x > 0 and p[pi] == max(p[pi], q[qi], r[ri]):
        ans += p[pi]
        pi += 1
        x -= 1
    elif y > 0 and q[qi] == max(p[pi], q[qi], r[ri]):
        ans += q[qi]
        qi += 1
        y -= 1
    elif r[ri] == max(p[pi], q[qi], r[ri]):
        ans += r[ri]
        ri += 1
        if y > 0 and p[lsp] >= q[lsq]:
            y -= 1
            if lsq == 0:
                continue
            else:
                lsq -= 1
        elif x > 0 and p[lsp] < q[lsq]:
            x -= 1
            if lsp == 0:
                continue
            else:
                lsp -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
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 = p[:x]
q = q[:y]
p.append(0)
q.append(0)

wa = x + y

lsp = x - 1
lsq = y - 1

pi = 0
qi = 0
ri = 0

ans = 0

for i in range(wa):
    if x > 0 and p[pi] == max(p[pi], q[qi], r[ri]):
        ans += p[pi]
        pi += 1
        x -= 1
    elif y > 0 and q[qi] == max(p[pi], q[qi], r[ri]):
        ans += q[qi]
        qi += 1
        y -= 1
    elif r[ri] == max(p[pi], q[qi], r[ri]):
        ans += r[ri]
        ri += 1
        if p[lsp] >= q[lsq]:
            y -= 1
            lsq -= 1
        elif p[lsp] < q[lsq]:
            x -= 1
            lsp -= 1

print(ans)

Fixed submission:
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 = p[:x]
q = q[:y]
p.append(0)
q.append(0)
r += [0] * (10 ** 3)


wa = x + y

lsp = x - 1
lsq = y - 1

pi = 0
qi = 0
ri = 0

ans = 0

for i in range(wa):
    if x > 0 and p[pi] == max(p[pi], q[qi], r[ri]):
        ans += p[pi]
        pi += 1
        x -= 1
    elif y > 0 and q[qi] == max(p[pi], q[qi], r[ri]):
        ans += q[qi]
        qi += 1
        y -= 1
    elif r[ri] == max(p[pi], q[qi], r[ri]):
        ans += r[ri]
        ri += 1
        if y > 0 and p[lsp] >= q[lsq]:
            y -= 1
            if lsq == 0:
                continue
            else:
                lsq -= 1
        elif x > 0 and p[lsp] < q[lsq]:
            x -= 1
            if lsp == 0:
                continue
            else:
                lsp -= 1

print(ans)