Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#import time
import numpy as np
from math import *

def main():
    A, B, H, M = list(map(int, input().split()))
    pai = 3.1415926535897323846264338327950
    kakuH = H*360/12 + M*30/60
    kakuM = M*360/60
    kakuS = kakuH - kakuM
    #print(kakuH, kakuM, kakuS)
    ans =(A**2 + B**2 - 2*A*B*np.cos(kakuS*pai/180)) )**(1/2)

    return ans

def absolute(a, b):
    if a>=b:
        if a-b>180:
            return 360-(a-b)
        else:
            return a-b
    else:
        if b-a>180:
            return 360-(b-a)
        else:
            return b-a

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Fixed submission:
#import time
import numpy as np
from math import *

def main():
    A, B, H, M = list(map(int, input().split()))
    pai = 3.1415926535897323846264338327950
    kakuH = H*360/12 + M*30/60
    kakuM = M*360/60
    kakuS = absolute(kakuH, kakuM)
    #print(kakuH, kakuM, kakuS)
    ans =(A**2 + B**2 - 2*A*B*cos(radians(kakuS)) )**(1/2)

    return ans

def absolute(a, b):
    if a>=b:
        if a-b>180:
            return 360-(a-b)
        else:
            return a-b
    else:
        if b-a>180:
            return 360-(b-a)
        else:
            return b-a

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
Buggy python submission (verdict: Runtime Error):
#import time

def main():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))
    As = [0]+As
    ikisaki = As[1]
    aru = {1}
    itta = [1]
    imaitta = 1
  
    while not ikisaki in aru:
        imaitta = ikisaki
        ikisaki = As[ikisaki]
        itta.append(imaitta)
        aru.add(imaitta)
    ind = itta.index(ikisaki)
    kurikaesi = itta[ind:]
    itidokiri = itta[:ind]
    ans = itidokiri[K-1] if len(itidokiri) <= K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]


    return itta, itidokiri, kurikaesi, ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Fixed submission:
#import time

def main():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))
    As = [0]+As
    ikisaki = As[1]
    aru = {1}
    itta = [1]
    imaitta = 1
  
    while not ikisaki in aru:
        imaitta = ikisaki
        ikisaki = As[ikisaki]
        itta.append(imaitta)
        aru.add(imaitta)
    ind = itta.index(ikisaki)
    kurikaesi = itta[ind:]
    itidokiri = itta[:ind]
    ans = itidokiri[K] if len(itidokiri) > K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]


    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
Buggy python submission (verdict: Time Limit Exceeded):
# 1-index
def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class segtree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num

        for i in range(n):
            self.tree[self.num + i] = init_val[i]

        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N, K = map(int, input().split())
T = []
for i in range(N):
    a = int(input())
    T.append(a)

A = [0]*(max(T)+1)
s_tree = segtree(A, segfunc, ide_ele)
for i in range(N):
    a = T[i]
    p = s_tree.query(max(a - K, 0), min(a + K + 1, max(T)+1))
    s_tree.update(a, p + 1)

print(s_tree.query(0, max(T)+1))

Fixed submission:
# 1-index
def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class segtree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num

        for i in range(n):
            self.tree[self.num + i] = init_val[i]

        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N, K = map(int, input().split())
T = []
for i in range(N):
    a = int(input())
    T.append(a)

M = max(T)+1
A = [0]*M
s_tree = segtree(A, segfunc, ide_ele)
for i in range(N):
    a = T[i]
    p = s_tree.query(max(a - K, 0), min(a + K + 1, M))
    s_tree.update(a, p + 1)

print(s_tree.query(0, M))
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = []
for i in range(N):
    x, y = map(int,input().split())
    t = x + y
    if x <= 0:
        t -= 4*abs(x)
    if y <= 0:
        t -= 4*abs(y)
    K.append([t, x, y])

K.sort()
ans = K[-1][0] - K[0][0]
for i in range(N-1):
    if K[i][0] == K[i+1][0]:
        A.append(K[i+1][1])
    else:
        ans = max(ans, max(A) - min(A))
        A = [K[i][1]]
print(ans)

Fixed submission:
N = int(input())
A = []
B = []
for i in range(N):
    x, y = map(int, input().split())
    A.append(x+y)
    B.append(x-y)
print(max(max(A)-min(A), max(B)-min(B)))
Buggy python submission (verdict: Time Limit Exceeded):
#木の根を得る
def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合
def unite(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

def size(x):
    return -par[root(x)]

N, M = map(int, input().split())
par = [-1]*N
g = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A, B = A - 1, B - 1
    unite(A, B)
    g[A].append(B)
    g[B].append(A)

ans = 0
for i in range(N):
    ans = max(ans, size(i))
print(ans)

Fixed submission:
from collections import deque
N, M = map(int, input().split())
K = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    K[A].append(B)
    K[B].append(A)
used = [0]*N
ans = 0
for i in range(N):
    c = 0
    if used[i] == 0:
        P = deque([i])
        used[i] = 1
        while P:
            c += 1
            a = P.popleft()
            for j in K[a]:
                if used[j] == 0:
                    used[j] = 1
                    P.append(j)
    ans = max(c, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#木の根を得る
def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合
def unite(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

from collections import defaultdict
T = defaultdict(int)
N, M = map(int, input().split())
par = [-1]*N
g = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A, B = A - 1, B - 1
    unite(A, B)
    g[A].append(B)
    g[B].append(A)

for i in range(N):
    T[root(i)] += 1

ans = 0
for k in T.values():
    ans = max(ans, k)
print(ans)

Fixed submission:
from collections import deque
N, M = map(int, input().split())
K = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    K[A].append(B)
    K[B].append(A)
used = [0]*N
ans = 0
for i in range(N):
    c = 0
    if used[i] == 0:
        P = deque([i])
        used[i] = 1
        while P:
            c += 1
            a = P.popleft()
            for j in K[a]:
                if used[j] == 0:
                    used[j] = 1
                    P.append(j)
    ans = max(c, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
p = 0
s = 0
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, i):
            dp[j] = 1
        dp[A_max] = 0
        for j in range(N):
            if A[j] % i == 0:
                c += 1
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")

Fixed submission:
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
K = [0]*(A_max+10)
p = 0
s = 0
for i in range(N):
    K[A[i]] += 1
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, i):
            dp[j] = 1
            c += K[j]
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
p = 0
s = 0
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, 2):
            if j % i == 0:
                dp[j] = 1
        for j in range(N):
            if A[j] % i == 0:
                c += 1
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")

Fixed submission:
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
K = [0]*(A_max+10)
p = 0
s = 0
for i in range(N):
    K[A[i]] += 1
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, i):
            dp[j] = 1
            c += K[j]
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")
Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int, input().split())
T = [[0]*(C+1) for _ in range(R+1)]
dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
for i in range(K):
    r, c, v = map(int, input().split())
    T[r][c] = v
dp[1][1][1] = T[1][1]
dp[0][1][1] = 0

for i in range(1, R+1):
    for j in range(1, C+1):
        for k in range(4):
            for l in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[l][i-1][j])
                dp[1][i][j] = max(dp[1][i][j], dp[l][i-1][j] + T[i][j])
            dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
            if k >= 1:
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + T[i][j])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][R][C])
print(ans)

Fixed submission:
R, C, K = map(int, input().split())
T = [[0]*(C+2) for _ in range(R+2)]
dp = [[[0]*(C+2) for _ in range(R+2)] for _ in range(4)]
for i in range(K):
    r, c, v = map(int, input().split())
    T[r][c] = v
dp[1][1][1] = T[1][1]
dp[0][1][1] = 0

for i in range(1, R+1):
    for j in range(1, C+1):
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[k][i][j] + T[i+1][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
            if k <= 2:
                dp[k+1][i][j+1] = max(dp[k+1][i][j+1], dp[k][i][j] + T[i][j+1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][R][C])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = N
k = 26
c = 0
while(T - k > 0):
    T -= k
    k *= 26
    c += 1

alph = {}
p = 1
for i in range(97, 97+26):
    alph[str(p%26)] = chr(i)
    p += 1
ans = ""
for i in range(c, -1, -1):
    t = N // (26**i)
    ans += alph[str(t)]
    N -= t*(26**i)
print("".join(ans))

Fixed submission:
N = int(input())
c = 0
P = [N]

alph = {}
p = 1
for i in range(97, 97+26):
    alph[str(p%26)] = chr(i)
    p += 1

ans = []
k = 0
T = N
while(N > 0):
    if k == 0:
        ans.append(alph[str((N // (26**k))%26)])
    else:
        ans.append(alph[str(((N-1)//(26**k)+1)%26)])
    k += 1
    N -= 26**k
print("".join(ans[::-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = 0

while(True):
    p = 0
    T = [0]*N
    for i in range(N):
        for j in range(max(i-A[i], 0), min(i+A[i]+1, N)):
            T[j] += 1
    c += 1
    if c == K:
        for i in range(N):
            print(T[i], end=" ")
        sys.exit()
    for i in range(N):
        if T[i] < N:
            p = 1
            break
    if p == 0:
        for i in range(N):
            print(N, end= " ")
        sys.exit()
    A = T[:]

Fixed submission:
import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = 0

while(True):
    p = 0
    T = [0]*N
    for i in range(N):
        T[max(i-A[i], 0)] += 1
        if i+A[i]+1 > N - 1:
            pass
        else:
            T[i+A[i]+1] -= 1
    for i in range(1,N):
        T[i] += T[i-1]
    c += 1
    if c == K:
        for i in range(N):
            print(T[i], end=" ")
        sys.exit()
    for i in range(N):
        if T[i] < N:
            p = 1
            break
    if p == 0:
        for i in range(N):
            print(N, end= " ")
        sys.exit()
    A = T[:]

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = 0

while(True):
    p = 0
    T = [0]*N
    for i in range(N):
        for j in range(max(i-A[i], 0), min(i+A[i]+1, N)):
            T[j] += 1
    c += 1
    if c == K:
        for i in range(N):
            print(T[i], end=" ")
        sys.exit()
    for i in range(N):
        if T[i] <= N:
            p = 1
            break
    if p == 0:
        for i in range(N):
            print(N, end= " ")
        sys.exit()
    A = T[:]

Fixed submission:
import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = 0

while(True):
    p = 0
    T = [0]*N
    for i in range(N):
        T[max(i-A[i], 0)] += 1
        if i+A[i]+1 > N - 1:
            pass
        else:
            T[i+A[i]+1] -= 1
    for i in range(1,N):
        T[i] += T[i-1]
    c += 1
    if c == K:
        for i in range(N):
            print(T[i], end=" ")
        sys.exit()
    for i in range(N):
        if T[i] < N:
            p = 1
            break
    if p == 0:
        for i in range(N):
            print(N, end= " ")
        sys.exit()
    A = T[:]
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
t = X**(0.2)
if t.is_integer():
    print(int(t),0)
else:
    b = 1
    while(True):
        k = b**5
        t = (X+k)**(0.2)
        if t.is_integer():
            print(int(t),b)
            break
        if X >= k:
            t = (X-k)**(0.2)
            if t.is_integer():
                print(int(t),-b)
                break
        b += 1

Fixed submission:
import sys
X = int(input())
for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i**5 - j**5 == X:
            print(i,j)
            sys.exit()

Buggy python submission (verdict: Runtime Error):
X = int(input())
t = X**(0.2)
if t.is_integer():
    print(int(t),0)
else:
    b = 1
    while(True):
        k = b**5
        t = (X+k)**(0.2)
        if t.is_integer():
            print(int(t),b)
            break
        t = (X-k)**(0.2)
        if t.is_integer():
            print(int(t),-b)
            break
        b += 1

Fixed submission:
import sys
X = int(input())
for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i**5 - j**5 == X:
            print(i,j)
            sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q=map(int, input().split())
matrix=[]

for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
    
import itertools
scorelist=[]
k = itertools.product(range(1,M+1), repeat=N)
for i in k:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    scorelist.append(score)
print(max(scorelist))

Fixed submission:
from itertools import combinations_with_replacement
N,M,Q = map(int,input().split())
A = []
for i in range(Q):
    b = list(map(int,input().split()))
    A.append(b)

T = range(1,M+1)
K = list(combinations_with_replacement(T,N))

ans = 0
for line in K:
    total = 0
    for combi in A:
        if line[combi[1]-1] - line[combi[0]-1] == combi[2]:
            total += combi[3]
    ans = max(total,ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
T = []
for i in range(len(S)):
    T.append((int("".join(S[i:])))%2019)

ans = 0
for i in range(len(T)):
    if T[i] == 0:
        ans += 1
print(ans + len(T)-len(set(T)))

Fixed submission:
from collections import Counter

S = list(input())
T = [int(S[len(S)-1])]
k = int(S[len(S)-1])
for i in range(len(S)-2,-1,-1):
    k = (int(S[i])*pow(10,len(S)-i-1,2019) + k ) % 2019
    T.append(k)

A = Counter(T)
ans = 0
ans += A.get(0,0)
for i in A.values():
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from _collections import deque

S = list(input())
dp = [ [0]*2020 for _ in range(len(S)+1) ]
dp[0][0] = 1
A = [0]
for i in range(1,len(S)+1):
    q = deque(A)
    A = []
    while(len(q)>0):
        j = q.popleft()
        T = (j * 10 + int(S[i - 1])) % 2019
        dp[i][T] += dp[i-1][j]
        A.append(T)
    if i != 1:
        dp[i][int(S[i-1])] += 1
        A.append(int(S[i-1]))
    A = set(A)

ans = 0
for i in range(1,len(S)+1):
    ans += dp[i][0]
print(ans)


Fixed submission:
from collections import Counter

S = list(input())
T = [int(S[len(S)-1])]
k = int(S[len(S)-1])
for i in range(len(S)-2,-1,-1):
    k = (int(S[i])*pow(10,len(S)-i-1,2019) + k ) % 2019
    T.append(k)

A = Counter(T)
ans = 0
ans += A.get(0,0)
for i in A.values():
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from _collections import deque

S = list(input())
dp = [ [0]*2020 for _ in range(len(S)+1) ]
dp[0][0] = 1
A = [0]
for i in range(1,len(S)+1):
    q = deque(A)
    A = []
    while(len(q)>0):
        j = q.popleft()
        T = (j * 10 + int(S[i - 1])) % 2019
        dp[i][T] += dp[i-1][j]
        A.append(T)
    if i != 1:
        dp[i][int(S[i-1])] += 1
        A.append(int(S[i-1]))

ans = 0
for i in range(1,len(S)+1):
    ans += dp[i][0]
print(ans)

Fixed submission:
from collections import Counter

S = list(input())
T = [int(S[len(S)-1])]
k = int(S[len(S)-1])
for i in range(len(S)-2,-1,-1):
    k = (int(S[i])*pow(10,len(S)-i-1,2019) + k ) % 2019
    T.append(k)

A = Counter(T)
ans = 0
ans += A.get(0,0)
for i in A.values():
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
dp = [ [0]*2020 for _ in range(len(S)+1) ]
dp[0][0] = 1
for i in range(1,len(S)+1):
    for j in range(2019):
        dp[i][(j*10+int(S[i-1]))%2019] += dp[i-1][j]
    if i != 1:
        dp[i][int(S[i-1])] += 1
ans = 0
for i in range(1,len(S)+1):
    ans += dp[i][0]
print(ans)

Fixed submission:
from collections import Counter

S = list(input())
T = [int(S[len(S)-1])]
k = int(S[len(S)-1])
for i in range(len(S)-2,-1,-1):
    k = (int(S[i])*pow(10,len(S)-i-1,2019) + k ) % 2019
    T.append(k)

A = Counter(T)
ans = 0
ans += A.get(0,0)
for i in A.values():
    ans += i*(i-1)//2
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)

a = p[:X]
b = q[:Y]
p_c = -1
q_c = -1
r_c = 0
k = 0


ans = sum(a)+sum(b)
while(True):
    if p_c < - X or a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

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)

a = [10**10]*(10**5)
a.extend(p[:X])
b = [10**10]*(10**5)
b.extend(q[:Y])
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(p[:X])+sum(q[:Y])
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

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)

a = p[:X]
b = q[:Y]
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(a)+sum(b)
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c]:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

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)

a = [10**10]*(10**5)
a.extend(p[:X])
b = [10**10]*(10**5)
b.extend(q[:Y])
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(p[:X])+sum(q[:Y])
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)