Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02983 (python)

Fixed submission:
l,r = (int(i) for i in input().split())
mod = 2019
if r-l >=2019:
    print(0)
else:
    ans = float('inf')
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,i*j%mod)
    print(ans)

Buggy submission (verdict: Runtime Error):
l,r = (int(i) for i in input().split())
mod = 2019
if l-r >=2019:
    print(0)
else:
    ans = float('inf')
    for i in range(l,r+1):
        for j in range(i,r+1):
            ans = (ans,i*j%mod)
        print(ans)

Buggy submission (verdict: Runtime Error):
l,r = (int(i) for i in input().split())
mod = 2019
t,i = 0,1
lim = 10**9
while t<=lim:
    t = mod*i
    if l<=mod<=r:
        print(0)
        exit()
    i+=1
print(min(l*(l+1)%mod,r*(r-1)%mod)
Problem p03000 (python)

Fixed submission:
from itertools import accumulate
n,x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
ruiseki = list(accumulate(l))
ruiseki.insert(0,0)
i = 0
#print(ruiseki)
while i < len(ruiseki) and ruiseki[i] <= x:
    i += 1
print(i)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
n,x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
ruiseki = list(accumulate(l))
ruiseki.insert(0,0)
i = 0
#print(ruiseki)
while ruiseki[i] <= x and i < n+1:
    i += 1
print(i)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
n,x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
ruiseki = list(accumulate(l))
i = 0
while ruiseki[i] <= x and i < n+1:
    i += 1
print(i+1)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
n,x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
ruiseki = list(accumulate(l))
i = 0
while ruiseki[i] <= x:
    i += 1
print(i+1)

Buggy submission (verdict: Runtime Error):
n,x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
d = 0
i = 0
while d<=x:
    d += l[i]
    i += 1
print(i)
Problem p03048 (python)

Fixed submission:
r,g,b,n = (int(i) for i in input().split())
ans = 0
for i in range(n//r+1):
    for j in range((n-(i*r))//g+1):
        k = (n-r*i-j*g)//b
        if r*i+j*g+abs(k*b) == n:
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
r,g,b,n = (int(i) for i in input().split())
ans = 0
for i in range(n//r+1):
    for j in range((n-(i*r))//g+1):
        #k = (n-r*i-j*g)//b
        if r*i+j*g+abs(((n-r*i-j*g)//b)*k) == n:
            ans += 1
print(ans)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(1,n):
    l.append(gcd(l[i-1],a[i-1]))
    r.append(gcd(r[i-1],a[-i]))
r = r[::-1]
ans = 0

for i in range(n):
    ans = max(ans,gcd(l[i],r[i]))
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(n//2+1):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(a[n-i-1],r[i]))

#print(l,r)
ans = 0
for i in range(min(len(l),len(r))):
    ans = max(ans,gcd(l[i],r[n-i-1]))
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r,ans = [a[0]],[a[-1]],[gcd(a[0],a[-1])]
if len(a) == 2:
    print(gcd(a[0],a[1]))
    exit()
for i in range(1,n//2+1):
    l.append(gcd(a[i-1],a[i]))
    r.append(gcd(a[n-i],a[n-i-1]))
    ans.append(r[-1])
    ans.append(l[-1])
ans = list(set(ans))
print(ans[1])

Buggy submission (verdict: Runtime Error):
import fractions
from functions import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = [int(i) for i in input().split()]
ans = 0
l,r = [],[]
for i in range(n):
	l = gcd_list([a[i] for m in range(i)])
	r = gcd_list([a[i] for m in range(n-1,i,-1)])
	ans = max(ans,l,r)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-1):
        m.append(gcd(a[i],a[i+1]))
    m.append(gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-2):
        m.append(math.gcd(a[i],a[i+1]))
    m.append(math.gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-1):
        m.append(math.gcd(a[i],a[i+1]))
    m.append(math.gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-1):
        m.append(math.gcd(a[i],a[i+1]))
    m.append(math.gcd(a[0],a[i+1]))
    m = list(set(m))
    m.sort()
    print(m[1])
Problem p03062 (python)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
m,ans = 10**9,0
for i in range(n-1):
    m = min(m,abs(a[i]))
    if a[i] < 0:
        a[i]*=(-1)
        a[i+1]*=(-1)
if a[-1] >= 0:
    print(sum(a))
else:
    a[-1] *= (-1)
    m = min(m,abs(a[i+1]))
    print(sum(a)-m*2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
min = (10**9,None)
for i in range(n-1):
    if a[i] < 0:
        a[i] *= (-1)
        a[i+1] *= (-1)
    if min[0] > abs(a[i]):
        min = (abs(a[i],i))
if a[-1] < 0:
    a[-1]**=(-1)
    a[min[1]]**=(-1)
print(sum(a))
Problem p03069 (python)

Fixed submission:
n = int(input())
S = [s for s in input()]
w,b = [0],[0]
for i in range(n):
    if S[i] is '#': w.append(w[i]+1)
    else:   w.append(w[i])
    if S[n-i-1] is '.': b.append(b[i]+1)
    else:   b.append(b[i])
b = b[::-1]
#print(w,b)
ans = float('inf')
for i in range(n+1):
    ans = min(ans, w[i]+b[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
S = input()

w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(S)-1,0,-1):
    if S[e] != '#':
        break

for s in range(i,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
S = input()
c = S[::-1]
w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(c)):
    if c[e] != '#':
        break

for s in range(i,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
S = input()
c = S[::-1]
w,b = 0,0

for i in range(len(S)):
    if S[i] != '.':
        break

for e in range(len(c)):
    if c[e] != '#':
        break

for s in range(d,len(S)-e+1):
    if S[s] == '.':
        w += 1
    else:
        b += 1

if b > w:
    print(w)
else:
    print(b)
Problem p03071 (python)

Fixed submission:
a,b = (int(i) for i in input().split())
h = 0

if a > b:
  h = a
  a = a-1
else:
  h = b
  b = b-1

if a > b:
  print(h+a)
else:
  print(h+b)

Buggy submission (verdict: Runtime Error):
N,K = (int(i) for i in input().split())
K += 2 #とれる範囲
S = input()
S = [s for s in S]
cnt = []
last = S[0]
c = 0

for s in S:
    if s == last:
        c += 1
    else:
        cnt.append(c)
        c = 1
        last = s

cnt.append(c)
cnt.extend([0,0,0])
hold = sum([cnt[n] for n in range(K+1)])
ans = [hold]
for i in range(1,len(cnt)-K):
    #right => cnt[i-1]
    #left => cnt[i+K]
    ans.append(hold-cnt[i-1]+cnt[i+K])
    hold = sum([cnt[n+i] for n in range(K+1)])
print(max(ans))
Problem p03212 (python)

Fixed submission:
from itertools import product
n = int(input())

ans = 0

for i in range(3,len(str(n))+1):
    for p in product('753',repeat=i):
        if n >= int(''.join(list(p))) and all(list(p).count(c) > 0 for c in '753'): ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product
n = int(input())

ans = 0

for i in range(3,len(str(n))+1):
    for p in product('753',repeat=i):
        if n >= int(''.join(list(p))) and all(list(p).count(c) > 0 for c in '753': ans += 1

print(ans)
Problem p03472 (python)

Fixed submission:
n,h = (int(i) for i in input().split())
A,B = [],[]
for _ in range(n):
    a,b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)
a_max = max(A)
B.sort(reverse=True)
power,ans = 0,0
for b in B:
    if a_max <= b:
        power += b
        ans += 1
        if power>=h: break
if power>=h:
    print(ans)
else:
    h -= power
    ans += h//a_max
    if h%a_max == 0: print(ans)
    else: print(ans+1)

Buggy submission (verdict: Runtime Error):
n,h = (int(i) for i in input().split())
A,B = [],[]
for _ in range(n):
    a,b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)
a_max = max(A)
B.sort()[::-1]
power,ans = 0,0
for b in B:
    if a_max <= b:
        power += b
        ans += 1
        if power>=h: break
if power>=h:
    print(ans)
else:
    h -= power
    ans += h//a_max
    if h%a_max == 0: print(ans)
    else: print(ans+1)
Problem p03497 (python)

Fixed submission:
from collections import Counter
N,K = (int(i) for i in input().split())
d = Counter([int(i) for i in input().split()])
if len(d) <= K:
    print(0)
    exit()

tmp = 0
for _,p in d.most_common(K):
    tmp += p
print(N-tmp)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
d = [a for a in Counter(A).values()]
tmp = 0
for i in range(min(K,len(d)+1)):
    tmp += max(d)
    d.remove(max(d))
print(len(A)-tmp)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
d = [a for a in Counter(A).values()]
tmp = 0
for i in range(min(K,len(set(d))+1)):
    tmp += max(d)
    d.remove(max(d))
print(len(A)-tmp)
Problem p03633 (python)

Fixed submission:
import fractions
n = int(input())
T = [int(input()) for _ in range(n)]

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

T.sort()
ans = T.pop(0)
for t in T:
    ans = lcm(ans,t)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
T = [int(input()) for _ in range(n)]

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

T.sort()
ans = T.pop(0)
for t in T:
    ans = lcm(ans,t)
print(ans)
Problem p03761 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
s_list = []
for i in range(N):
    s_list.append(input().strip())

alphabets = 'abcdefghijklmnopqrstuvwxyz'

for c in alphabets:
    min_count = float('inf')
    for s in s_list:
        count = s.count(c)

        if count < min_count:
            min_count = count
    print(c * min_count, end='')
print()

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
t = [input() for _ in range(n)]
init = ''.join(['a' for _ in range(50)])
for s in t:
    if len(init) > len(s):  init = s

t.remove(init)
init = {k:v for k,v in Counter([s for s in sorted(list(init))]).items()}

for s in t:
    for k,v in init.items():
        if s.count(k) < v:  init[k] = s.count(k)
ans = ''
for k,v in init.items():
    for i in range(v):  ans += k
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from itertools import permutations
n = int(input())
t = [input() for _ in range(n)]
init = ''.join(['a' for _ in range(50)])
for s in t:
    if len(init) > len(s):  init = s

t.remove(init)
init = {k:v for k,v in Counter([s for s in init]).items()}

for s in t:
    for k,v in init.items():
        if s.count(k) < v:  init[k] = s.count(k)
s = ''
for k,v in init.items():
    for i in range(v):  s += k
ans = sorted([''.join(list(a)) for a in permutations(s,len(s))])
print(ans[0])
Problem p02658 (python)

Fixed submission:
x = input()
t = int(x)
x2 = input()
n = list(map(int, x2.split(" ")))


def main():
  if 0 in n:
    print(0)
    return
  p = 1
  for v in range(t):
    p *= n[v]
    if (p > 10 **18):
      print("-1")
      return
  print(p)

main()

Buggy submission (verdict: Runtime Error):
x = input()
t = int(x)
x2 = input()
n = list(map(int, x2.split(" ")))


def main():
  p = 1
  for v in t:
    p *= n[v]
    if (p >= 10 **18):
      print("-1")
      return
  print(p)

main()
Problem p02761 (python)

Fixed submission:
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for t in range(m):
        r = input()
        s, c = map(int, r.split(" "))
        s -= 1
        if v[s] != "~" and v[s] != str(c):
            print(-1)
            return
        v[s] = str(c)
    if n >= 2 and v[0] == '~':
        v[0] = "1"
    for x in range(n):
        if v[x] == '~':
            v[x] = "0"
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(res_str) != n:
        print(-1)
        return
    print(res_str)

main()

Buggy submission (verdict: Runtime Error):
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for v in range(m):
        r = input()
        s, c = map(int, r1.split(" "))
        v[s] = c
        if v[s] != "~" and v[s] != c:
            print(-1)
            return
    for x in range(len(v)):
        if v[x] == '~':
            v[x] = 0
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(sv) != len(res_str):
        print(-1)
        return
    print(res_str)

main()
Problem p02606 (python)

Fixed submission:
import math

t, r, s = map(int, input().split())
print(r//s - (t-1)//s)

Buggy submission (verdict: Runtime Error):
import math

t = int(input())
r = int(input())
s = int(input())
print(r//s - (t-1)//s)
Problem p02607 (python)

Fixed submission:
import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and a[i]%2 == 1:
        num+=1
print(num)

Buggy submission (verdict: Runtime Error):
import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)

Buggy submission (verdict: Runtime Error):
import math
import itertools
import numpy as np

t = int(input())
g_all = np.array([list(input()) for i in range(t)])
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)

Buggy submission (verdict: Runtime Error):
import math

t = int(input())
g_all = np.array([list(input()) for i in range(t)])
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)
Problem p03633 (python)

Fixed submission:
def gcd(a,b):
    while b > 0:
        r = a % b
        a = b
        b = r
    return a

n = int(input())
x = int(input())
for _ in range(n-1):
    i = int(input())
    x = (x * i) // gcd(x,i)

print(x)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = [int(input()) for i in range(n)]

x = a[0]
for i in a[1:]:
    x = (x * i) // math.gcd(x,i)

print(x)
Problem p02981 (python)

Fixed submission:
n,a,b = map(int, input().split())
print(min(b,a*n))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
print(min(b,a*n)
Problem p02612 (python)

Fixed submission:
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n = ii()
    if n%1000 == 0:
        print(0)
    else:
        print(1000 - n%1000)
    return

main()

Buggy submission (verdict: Runtime Error):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n = ii
    ans = 1000 - n%1000
    print(ans)
    return

main()
Problem p02618 (python)

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    for i in range(365):
        print(i%26+1)

main()

Buggy submission (verdict: Runtime Error):
import sys
from random import randint
from datetime import datetime

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]

def randomize(n):
    return [ randint(1, 26) for _ in range(n) ]

def get_now():
    dt = datetime.now()
    return dt.second + dt.microsecond/1000000

def main():
    start = get_now()
    end = get_now()
    # 開催日数
    D = ii()
    # 満足度の下がりやすさ
    C = lmi()
    # 得られる満足度
    S = lmif(D)
    # 開催するコンテスト
    T = [ randomize(D) ]

    def scoring():
        # 最後に開かれた日付
        last = [0]*26
        score = 0
        for i in range(D):
            score += S[i][T[i]-1]
            last[T[i]-1] = i+1
            for j in range(26):
                score -= C[j] * (i+1 - last[j])
        return score

    max_score = scoring()
    # print(max_score)
    ans = T.copy()
    # a = 0
    while end - start < 1.95:
        idx, value = randint(0, D-1), randint(1, 26)
        old = T[idx]
        T[idx] = value
        score = scoring()
        if max_score < score:
            ans = T.copy()
            max_score = score
        else:
            T[idx] = old
        # if a % 10000 == 0:
        #     print(a, *T, score, max_score)
        # a += 1
        end = get_now()
    print(*ans, sep='\n')

main()
Problem p02639 (python)

Fixed submission:
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    X = list(map(int, input().split()))
    for i in range(len(X)):
        if X[i] == 0:
            print(i+1)
            return

main()

Buggy submission (verdict: Runtime Error):
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    X = list(map(int,input().split))
    for i in range(X):
        if X[i] == 0:
            print(i+1)
            return

main()
Problem p02658 (python)

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    limit = 10**18
    ans = 1
    for i in A:
        ans *= i
        if ans > limit:
            print(-1)
            return

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    limit = 10**18
    ans = 1
    for i in A:
        if A == 0:
            print(0)
            return
        if ans > limit:
            print(-1)
            return
        ans *= A[i]
    print(ans)

main()
Problem p02698 (python)

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import deque
    from bisect import bisect_left

    N = int(input())
    a = list(map(int, input().split()))
    tree = [[] for _ in [0]*N]
    for u, v in [map(int, input().split()) for _ in [0]*(N-1)]:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)
    
    dp = [1001001001] * (N+1)
    dp[0] = -1001001001
    ans = [0] * N
    def dfs(now, p=-1):
        idx = bisect_left(dp, a[now])
        old = dp[idx]
        dp[idx] = a[now]
        ans[now] = idx
        if p != -1 and ans[now] < ans[p]:
            ans[now] = ans[p]
        for child in tree[now]:
            if child == p: continue
            dfs(child, now)
        dp[idx] = old
    dfs(0)

    print(*ans, sep='\n')

main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import deque
    from bisect import bisect_left

    N = int(input())
    a = list(map(int, input().split()))
    tree = [[] for _ in [0]*N]
    for u, v in [map(int, input().split()) for _ in [0]*(N-1)]:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)
    
    dp = [1001001001] * N
    dp[0] = -1001001001
    ans = [0] * N
    def dfs(now, p=-1):
        idx = bisect_left(dp, a[now])
        old = dp[idx]
        dp[idx] = a[now]
        ans[now] = idx
        if p != -1 and ans[now] < ans[p]:
            ans[now] = ans[p]
        for child in tree[now]:
            if child == p: continue
            dfs(child, now)
        dp[idx] = old
    dfs(0)
    
    print(*ans, sep='\n')

main()
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red.sort()
green.sort()
no.sort()
a -= 1
b -= 1
c -= 1
max_a = int(a)
max_b = int(b)

ans = 0
for i in range(x):
    ans += red[a]
    a -= 1
for i in range(y):
    ans += green[b]
    b -= 1
a += 1
b += 1

for i in range(x+y):
    if c >= 0 and a <= max_a and b <= max_b:
        gr = no[c] - red[a]
        gg = no[c] - green[b]
        if gr >= gg:
            if gr > 0:
                ans += no[c]
                ans -= red[a]
                c -= 1
                a += 1
        elif gg >= gr:
            if gg > 0:
                ans += no[c]
                ans -= green[b]
                c -= 1
                b += 1
    elif c >= 0 and a <= max_a:
        if no[c] - red[a] > 0:
            ans += no[c]
            ans -= red[a]
            c -= 1
            a += 1
    elif c >= 0 and b <= max_b:
        if no[c] - green[b] > 0:
            ans += no[c]
            ans -= green[b]
            c -= 1
            b += 1
    else:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red.sort()
green.sort()
no.sort()
a -= 1
b -= 1
c -= 1

ans = 0
for i in range(x):
    ans += red[a]
    a -= 1
for i in range(y):
    ans += green[b]
    b -= 1
a += 1
b += 1

for i in range(x+y):
    gr = no[c] - red[a]
    gg = no[c] - green[b]

    if gr > gg:
        if gr > 0:
            ans += no[c]
            ans -= red[a]
            c -= 1
            a += 1
    elif gg > gr:
        if gg > 0:
            ans += no[c]
            ans -= green[b]
            c -= 1
            b += 1

print(ans)