Buggy python submission (verdict: Runtime Error):
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 ng < G and r[nr] > g[ng]:
        g[ng] = n[nn]
        ng += 1
    elif nr < R and r[nr] <= g[ng]:
        r[nr] = n[nn]
        nr += 1
    nn += 1

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

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

Buggy python submission (verdict: Runtime Error):
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]:
        g[ng] = n[nn]
        ng += 1
    else:
        r[nr] = n[nn]
        nr += 1
    nn += 1

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

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

Buggy python submission (verdict: Time Limit Exceeded):
def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#import bisect
X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)
while non[-1] > ans[-1]:
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
    if non == []:
        break
print(sum(ans))

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

Buggy python submission (verdict: Time Limit Exceeded):
def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#import bisect
X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)
times = len(non)
for i in range(times):
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
print(sum(ans))

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

Buggy python submission (verdict: Time Limit Exceeded):
def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#import bisect
X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)

while non[-1] > ans[-1]:
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
    if non == []:
        break
print(sum(ans))

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

Buggy python submission (verdict: Runtime Error):
import bisect
X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)
if non[-1] > ans[-1]:
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
print(sum(ans))

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