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

Fixed submission:
# coding: utf-8
import time
import re
import math

def main():
    n=int(input())
    H=list(map(int,input().split()))
    memo=[0]*n
    for a in range(n):
        if a==0:
            memo[a]=0
        elif a==1:
            memo[a]=memo[a-1]+abs(H[a-1]-H[a])
        else:
            memo[a]=min([memo[a-1]+abs(H[a-1]-H[a]),memo[a-2]+abs(H[a-2]-H[a])])
    print(memo[-1])


start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math

def main():
    global n,H,memo,mn
    n=int(input())
    H=list(map(int,input().split()))
    mn=1e9
    memo=[]*n
    dp(0,0)
    print(mn)
def dp(index,cost):
    global n,H,memo,mn
    if index==n-1:
        #print("cost {}".format(cost))
        mn=min([mn,cost])
    else:
        if(index+1<n):dp(index+1,cost+abs(H[index]-H[index+1]))
        if(index+2<n): dp(index+2,cost+abs(H[index]-H[index+2]))

start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math

def main():
    global n,H,memo,mn
    n=int(input())
    H=list(map(int,input().split()))
    mn=1e9
    memo=[]*n
    dp(0,0)
    print(mn)
def dp(index,cost):
    global n,H,memo,mn
    if index>=n:
        return
    if index==n-1:
        #print("cost {}".format(cost))
        mn=min([mn,cost])
        return
    if(index+1<n):dp(index+1,cost+abs(H[index]-H[index+1]))
    if(index+2<n): dp(index+2,cost+abs(H[index]-H[index+2]))

start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
Problem p03262 (python)

Fixed submission:
# coding: utf-8
import time
import re
import math

def main():
    n,start=map(int,input().split())
    X=list(map(int,input().split()))
    now=abs(X[0]-start)
    for xi in range(1,n):
        now=GCD(now,abs(X[xi]-start))
    print(now)
def GCD(a,b):
    if a%b==0:
        return b
    else:
        return GCD(b,a%b)
main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math

def main():
    n,start=map(int,input().split())
    X=list(map(int,input().split()))
    mx=0
    dmx=0
    for a in X:
        dmx=max([dmx,abs(start-x)])
    for D in range(1,dmx+1):
        f=1
        for a in range(n):
            if (X[a]-start)%D!=0:
                f=0
        if f==1:
            mx=max([mx,D])
    print(mx)
main()
Problem p03284 (python)

Fixed submission:
n,k=map(int,input().split())
if n%k:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
count=0
for a in range(math.floor(n/4)+1):
    if (n-a*4)%7==0:
        count+=1
print(count)
Problem p03285 (python)

Fixed submission:
import math
n=int(input())
for a in range(math.floor(n/4)+1):
    if (n-a*4)%7==0:
        print("Yes")
        quit()
print("No")

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
count=0
while cakes*4+donuts*7<n:
    for a in range(math.floor(n/4)+1):
        if (n-a*4)%7==0:
            count+=1
print(count)
Problem p03386 (python)

Fixed submission:
# coding: utf-8
import time
import re
import math

def main():
    A,B,K = map(int,input().split())
    ls=[]
    for a in range(K):
        ls.append(A + a)
        ls.append(B - K +1+ a)
    ls=set(ls)
    ls=sorted(ls)
    for a in ls:
        if (a>=A and a<=B):print(a)
main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math

def main():
    A,B,K = map(int,input().split())
    ls=set([])
    for a in range(K):
        ls.append(A + a)
        ls.append(B - K +1+ a)
    ls.sort()
    for a in ls:
        print(a)
main()
Problem p03437 (python)

Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  print(x)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  pritn(x)
Problem p03449 (python)

Fixed submission:
# coding: utf-8
import time
import re
import math
import fractions

def main():
    global N,A
    N=int(input())
    A=[]
    A.append(list(map(int,input().split())))
    A.append(list(map(int,input().split())))
    print(hoge(0,0,0))
def hoge(x,y,total):
    global N,A
    if (x==N-1 and y==1):return total+A[y][x]
    if(x>=N or y>=2):return -1e9
    total+=A[y][x]
    return max([hoge(x+1,y,total),hoge(x,y+1,total)])
    
    
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math
import fractions

def main():
    global N,A
    N=int(input())
    A=[]
    A.append(list(map(int,input().split())))
    A.append(list(map(int,input().split())))
    hoge(0,0,0)
def hoge(x,y,total):
    global N,A
    if(x>N or y>2):return -1e9
    if (x==N and y==2):return total
    total+=A[y][x]
    return max([hoge(x+1,y,total),hoge(x,y+1,total)])
    
    
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math
import fractions

def main():
    n=int(input())
    A=[]
    A.append(list(map(int,input().split())))
    A.append(list(map(int,input().split())))
    if len(A[0])%2==0:
        total=sum(A)
        mn=1e9
        for a in range(2):
            for b in range(n):
                if((a==0 and b==0) or (a==1 and b==n-1)):return
                mn=min([mn,A[a][b]])
        print(total-mn)
    else:
        print(sum(A))
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B
Problem p03463 (python)

Fixed submission:
N,A,B=map(int,input().split())
d=B-A
if d%2==0:print("Alice")
else:print("Borys")

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
d=B-A
if d%2==:print("Alice")
else:print("Borys")
Problem p03486 (python)

Fixed submission:
import math

s=input()
t=input()
s=sorted(s)
t=sorted(t,reverse=True)
if s<t:
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
import math

s=input()
t=input()
s=sorted(s)
t=sorted(s,reverse=True)
if s<n:
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
import math

s=input()
t=input()
s.sort()
t.sort()
t.reverse()

s<t if print("Yes") else print("No")
Problem p03598 (python)

Fixed submission:
# coding: utf-8
import time
import re
import math

def main():
    n=int(input())
    k=int(input())
    X=map(int,input().split())
    total=0
    for a in X:
        total+=min([a,abs(k-a)])*2
    print(int(total))
main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math

def main():
    n=int(input())
    k=int(input())
    X=map(int,input().split())
    total=0
    for a in X:
        total+=min([a,math.abs(k-a)])*2
    print(int(total))
main()
Problem p03699 (python)

Fixed submission:
# coding: utf-8
import time
import re
import math

def main():
    global N,A,memo
    N=int(input())
    A=[int(input()) for  a in range(N)] 
    if sum(A)%10==0:
        nm0=[]
        for a in A:
            if not a%10==0:
                nm0.append(a)
        if len(nm0)==0:
            print(0)
        else:
            print(sum(A)-min(nm0))

    else:
        print(sum(A))

main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import time
import re
import math

def main():
    global N,A,memo
    N=int(input())
    A=[int(input()) for  a in range(N)] 
    if sum(A)%10==0:
        nm0=[]
        for a in A:
            if not a%10==0:
                nm0.append(a)
        if len(nm0)==0:
            print(0)
        else:
            print(sum(A)-math.min(nm0))

    else:
        print(sum(A))

main()
Problem p03407 (python)

Fixed submission:
A =list(map(int, input().split()))
if A[0]+A[1]>=A[2]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A =[input() for i in range(3)]
if A[0]+A[1]>=A[2]:
    print('Yes')
else:
    print('No')
Problem p03106 (python)

Fixed submission:
a,b,k=map(int,input().split())
f=0
c=min(a,b)
for i in range(c):
  d=c-i
  if(a%d==0 and b%d==0):
    f+=1
    if(f==k):
      print(d)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
f=0
c=min(a,b)
for i in range(c):
  d=c-i
  if(a%i==0 and b%i==0):
    f+=1
    if(f==k):
      print(i)
Problem p03200 (python)

Fixed submission:
s=input()
n=0
c=0
for i in range(len(s)):
  if s[i]=='W':
    n+=i-c
    c+=1
print(n)

Buggy submission (verdict: Runtime Error):
import collections
 
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
c=collections.Counter(a)
ans=0
for i in a:
  for j in range(31):
    if(2**j>i):
      k=2**j-i
      break
  if k in c.keys():
    if i==k and c[i]>1:
      c[i]-=2
      ans+=1
    elif i!=k and c[i]>0 and c[k]>0:
      c[i]-=1
      c[k]-=1
      ans+=1
print(ans)
Problem p03251 (python)

Fixed submission:
i=input;x=i().split();print('No '*(max(map(int,i().split()+x[2:3]))<min(map(int,i().split()+x[3:4])))+'War')

Buggy submission (verdict: Runtime Error):
i=input;x=i().split();print('No '*(max(map(int,i().split().append(x[2])))<min(map(int,i().split().append(x[3]))))+'War')
Problem p03254 (python)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(n):
  x-=a[i]
  if(x<0):
    break
if(x!=0):
  print(i)
else:
  print(n)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=list(map(int,input().split()))
sort(a)
for i in range(n):
  x-=a[i]
  if(x<0):
    break
if(x!=0):
  print(i)
else:
  print(n)
Problem p03264 (python)

Fixed submission:
a=int(input())
print((a//2)*((a+1)//2))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print((a//2)*((a+1)//2))
Problem p03377 (python)

Fixed submission:
a,b,x=map(int,input().split())
print('NO' if x<a or x>a+b else 'YES')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('NO' if x<a or x>a+b else 'YES')
Problem p03547 (python)

Fixed submission:
a,b=input().split()
c=int(a,16)
d=int(b,16)
print('>' if c>d else '<' if c<d else '=')

Buggy submission (verdict: Runtime Error):
a,b=input(),split()
c=int(a,16)
d=int(b,16)
print('>' if c>d else '<' if c<d else '=')

Buggy submission (verdict: Runtime Error):
a,b=input(),split()
c=int(a,16)
d=int(b,16)
print('>' if a>b else '<' if a<b else '=')
Problem p03591 (python)

Fixed submission:
s=input()
a=False
if(len(s)>3):
  if(s[0:4]=="YAKI"):
    a=True
print("Yes" if a else "No")

Buggy submission (verdict: Runtime Error):
s=input()
a=False
if(len(s)>3):
  if(s[0:4]="YAKI"):
    a=True
print("Yes" if a else "No")
Problem p03623 (python)

Fixed submission:
a,b,c=map(int,input().split())
print('A' if abs(a-b)<abs(a-c) else 'B')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print('A' if abs(a,b)<abs(a,c) else 'B')
Problem p03657 (python)

Fixed submission:
a,b=map(int,input().split())
print('Possible' if a%3==0 or b%3==0 or (a+b)%3==0 else 'Impossible')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print('Possible'if a%3==0or b%3==0or(a+b)%3==0else'Impossible')
Problem p03671 (python)

Fixed submission:
s=list(map(int,input().split()))
print(sum(s)-max(s))

Buggy submission (verdict: Runtime Error):
s=map(int,input().split())
print(sum(s)-max(s))
Problem p03711 (python)

Fixed submission:
g=[0,2,0,1,0,1,0,0,1,0,1,0]
a,b=map(int,input().split())
print('Yes' if g[a-1]==g[b-1] else 'No')

Buggy submission (verdict: Runtime Error):
g=[0,2,0,1,0,1,0,0,1,0,1,0]
a,b=map(int,input().split())
print('Yes' if g[a]==g[b] else 'No')
Problem p03807 (python)

Fixed submission:
f=lambda x:int(x)%2
n=int(input())
a=list(map(f,input().split())).count(1)
print('YNEOS'[n>1 and a%2>0::2])

Buggy submission (verdict: Runtime Error):
f=lambda x:int(x)%2
n=int(input())
a=list(map(f,input().split())).count(1)
print([YNEOS][n>1 and a%2>0::2])

Buggy submission (verdict: Runtime Error):
f=lambda x:int(x)%2
n=int(input())
a=list(map(f,input().split())).count(1)
print([YNEOS][n>1 and a%2>0::2]
Problem p04043 (python)

Fixed submission:
s=input()
print('YES' if s=='5 5 7' or s=='5 7 5' or s=='7 5 5' else 'NO')

Buggy submission (verdict: Runtime Error):
s=input()
print('YES' if s=='5 5 7'||s=='5 7 5'||s=='7 5 5' else 'NO')
Problem p02555 (python)

Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def cmb_mod(N, mod=10**9+7):
    N1 = N + 1
    g1 = [0] * N1
    g2 = [0] * N1
    inv = [0] * N1
    g1[0] = g1[1] = g2[0] = g2[1] = inv[1] = 1

    for i in range(2, N1):
        g1[i] = g1[i-1] * i % mod
        inv[i] = -inv[mod % i ] * (mod//i) % mod
        #inv[i] = pow(g1[i-1], mod-2, mod)
        g2[i] = g2[i-1] * inv[i] % mod

    def cmb(n, a):
        if a < 0 or a > n:
            return 0
        return g1[n] * g2[a] * g2[n-a] % mod
    return cmb

def resolve():
    mod = 10**9 + 7
    S = int(input())

    if S < 3:
        print(0)
        return
    elif S < 6:
        print(1)
        return

    cmb = cmb_mod(S - 3 * 2 + 3)

    ans = 1
    for i in range(2, S//3+1):
        n = S - 3 * i + i - 1
        tmp = cmb(n, i - 1)
        ans = (ans + tmp) % mod
    print(ans)


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def cmb_mod(N, mod=10**9+7):
    N1 = N + 1
    g1 = [0] * N1
    g2 = [0] * N1
    inv = [0] * N1
    g1[0] = g1[1] = g2[0] = g2[1] = inv[1] = 1

    for i in range(2, N1):
        g1[i] = g1[i-1] * i % mod
        inv[i] = -inv[mod % i ] * (mod//i) % mod
        #inv[i] = pow(g1[i-1], mod-2, mod)
        g2[i] = g2[i-1] * inv[i] % mod

    def cmb(n, a):
        if a < 0 or a > n:
            return 0
        return g1[n] * g2[a] * g2[n-a] % mod
    return cmb

def resolve():
    mod = 10**9 + 7
    S = int(input())

    if S < 3:
        print(0)
        return

    cmb = cmb_mod(S - 3 * 2 + 2)

    ans = 1
    for i in range(2, S//3+1):
        n = S - 3 * i + i - 1
        tmp = cmb(n, i - 1)
        ans = (ans + tmp) % mod
    print(ans)


if __name__ == "__main__":
    resolve()
Problem p02618 (python)

Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(26)]
    S = [[next(it) for i in range(26)] for i in range(D)]

    ans = []
    for i in range(D):
        ss = S[i]
        di, qi = 0, ss[0]
        for j in range(1, 26):
            if ss[j] > qi:
                di, qi = j, ss[j]
        ans.append(di+1)

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

if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect
from time import perf_counter

def resolve():
    tick = perf_counter() + 1.95
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(26)]
    S = [[next(it) for i in range(26)] for i in range(D)]
    L = [[-1] for i in range(26)]
    T = [0] * D

    def update(di, qi):
        T1, L1 = T[:], L[:]

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]
        T1[di] = qi

        L1[t0] = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        L1[qi] = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, T1, L1

    score = 0
    x = (1+D)*D//2
    for i in range(D):
        score += S[i][0]
        score -= C[i] * x
        L[0].append(i)


    while perf_counter() < tick:
        diff, T1, L1 = update(randrange(0, D), randrange(0, 26))
        if diff > 0:
            score += diff
            T, L = T1, L1

    print(*T, sep="\n")

if __name__ == "__main__":
    resolve()
Problem p02651 (python)

Fixed submission:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

X = (10**18).bit_length()

def f(a, s, n):
    if s[-1] == "1":
        return 1

    B = [None] * X
    for i in range(n-1, -1, -1):
        ai, si = a[i], s[i]

        if si == "0":
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    B[x] = ai
                    break
                ai ^= B[x]
        else:
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    return 1
                ai ^= B[x]
    return 0


def resolve():
    T = int(input())

    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S  = input()

        ans.append(f(A, S, N))

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

if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

from functools import lru_cache

def resolve():
    T = int(input())

    @lru_cache
    def f(x, i):
        if i == N:
            return "1" if x else "0"

        ans = f(x, i+1)
        if S[i] == ans:
            return ans
        return f(x^A[i], i+1)

    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S  = input()

        if S[-1] == "1":
            ans.append("1")
        else:
            ans.append(f(0, 0))

        f.cache_clear()

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

if __name__ == "__main__":
    resolve()
Problem p02662 (python)

Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, S = iim()
    A = list(iim())
    mod = 998244353
    S1 = S + 1

    dp = [0] * (S+1)

    dp[0] = pow(2, N, mod)
    inv = pow(2, mod-2, mod)

    for ai in A:
        for i in range(S, ai-1, -1):
            dp[i] = (dp[i] + dp[i-ai]*inv) % mod

    print(dp[-1])


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, S = iim()
    A = list(iim())
    mod = 998244353
    S1 = S + 1

    dp = [0] * (S+1)
    dp1 = dp[:]
    dp[0] = 1
    for ai in A:
        sa = S - ai
        for i in range(sa):
            dp1[i] = 2 * dp[i]
        for i in range(sa, S1):
            dp1[i] = 2 * dp[i] + dp[i-ai]
        dp, dp1 = dp1, dp

    print(dp[-1])


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

iim = lambda: map(int, input().rstrip().split())
from collections import defaultdict

def resolve():
    N, S = iim()
    A = list(iim())
    mod = 998244353

    dp = [0] * (S+1)
    dp1 = dp[:]
    dp[0] = 1
    for ai in A:
        for i in range(ai):
            dp1[i] = 2 * dp[i]
        for i in range(ai, S+1):
            dp1[i] = 2 * dp[i] + dp[i-ai]
        dp, dp1 = dp1, dp

    print(dp[-1])


if __name__ == "__main__":
    resolve()
Problem p02678 (python)

Fixed submission:
#!python3

import sys
from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    d1 = defaultdict(list)

    for i, j in zip(it, it):
        d1[i].append(j)
        d1[j].append(i)

    ans = [0] * (N+1)
    dq = [1]
    visited = set([1])

    updated = True
    while updated:
        updated = False
        dq2 = []
        for i in dq:
            for j in d1[i]:
                if j in visited:
                    continue
                ans[j] = i
                dq2.append(j)
                visited.add(j)
                updated = True
        dq = dq2

    if len(visited) == N:
        print("Yes", *ans[2:], sep="\n")
    else:
        print("No")






if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

import sys
from collections import defaultdict

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    it = map(int, sys.stdin.read().split())

    d1 = defaultdict(list)

    for i, j in zip(it, it):
        d1[i].append(j)
        d1[j].append(i)

    ans = [0] * (N+1)
    dq = [1]
    visited = set([1])
    cnt = 0

    while True:
        dq2 = []
        for i in dq:
            for j in d1[i]:
                if j in visited:
                    continue
                dq2.append(j)
                ans[j] = i
            visited.update(dq2)
            cnt += 1

        if not dq2:
            break

        dq = dq2

    if cnt == N:
        print("Yes", *ans[2:], sep="\n")
    else:
        printi("No")





if __name__ == "__main__":
    resolve()
Problem p02727 (python)

Fixed submission:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    swap = True
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]

            if si[idx] < 0:
                idx ^= 1
                if si[idx] <= 0:
                    break
                swap = False
            elif not swap:
                continue
            elif P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]
            if P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()