Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def main():
    N ,K = ints_raw()
    Vs = ints_raw()
    leftSum = [0]
    leftNegas = [[]]
    for v in Vs:
        leftSum.append(leftSum[-1]+v)
        neoNega = leftNegas[-1]
        if v<0:
            neoNega = neoNega+[v]
            neoNega.sort()
        leftNegas.append(neoNega )


    rightSum = [0]
    rightNegas = [[]]
    for v in Vs[::-1]:
        rightSum.append(rightSum[-1]+v)
        neoNega = rightNegas[-1]
        if v<0:
            neoNega = rightNegas[-1]+[v]
            neoNega.sort()
        rightNegas.append(neoNega )

    ans = 0
    for left_k in range(K+1):
        left_total = 0
        left_n = 0
        for n in range(left_k+1):
            tmp = leftSum[n] - (sum(leftNegas[n]) if len(leftNegas[n])+n<=left_k else sum(leftNegas[n][:left_k-n]))
            if left_total < tmp:
                left_total = tmp
                left_n = n
        right_total = 0
        right_n = 0
        for n in range(min(K-left_k+1,N-left_n+1)):
            tmp = rightSum[n] - (sum(rightNegas[n]) if len(rightNegas[n])+n<=K-left_k else sum(rightNegas[n][:K-left_k-n]))
            if right_total < tmp:
                right_total = tmp
                right_n = n
        ans = max(ans,left_total+right_total)
    return ans

print(main())


Fixed submission:
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def main():
    N ,K = ints_raw()
    Vs = ints_raw()
    N = len(Vs)
    leftSum = [0]
    leftNegas = [[]]
    for v in Vs:
        leftSum.append(leftSum[-1]+v)
        neoNega = leftNegas[-1]
        if v<0:
            neoNega = neoNega+[v]
            neoNega.sort()
        leftNegas.append(neoNega )


    rightSum = [0]
    rightNegas = [[]]
    for v in Vs[::-1]:
        rightSum.append(rightSum[-1]+v)
        neoNega = rightNegas[-1]
        if v<0:
            neoNega = rightNegas[-1]+[v]
            neoNega.sort()
        rightNegas.append(neoNega )

    ans = 0
    for left_k in range(K+1):
        left_total = 0
        left_n = 0
        for n in range(min(N+1,left_k+1)):
            tmp = leftSum[n] - (sum(leftNegas[n]) if len(leftNegas[n])<=left_k-n else sum(leftNegas[n][:left_k-n]))
            if left_total < tmp:
                left_total = tmp
                left_n = n
        right_total = 0
        right_n = 0
        right_k = K -left_k
        for n in range(min(K-left_k+1,N-left_n+1)):
            tmp = rightSum[n] - (sum(rightNegas[n]) if len(rightNegas[n])<=right_k-n else sum(rightNegas[n][:right_k-n]))
            if right_total < tmp:
                right_total = tmp
                right_n = n
        ans = max(ans,left_total+right_total)
    return ans

print(main())
Buggy python submission (verdict: Runtime Error):
from collections import deque
from heapq import heappush,heappop
import re
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def getDeci(tree):
    def saiki(p,v):
        ans = [0,v]
        for e in tree[v]:
            if e ==p:
                continue
            tmp = saiki(v,e)
            tmp[0]=tmp[0]+1
            if ans[0]<tmp[0]:
                ans = tmp
        return ans
    leaf = saiki(-1,0)
    ans = saiki(-1,leaf[1])
    return ans

    
N = int_raw()
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = ints_raw()
    a = a-1
    b = b-1
    tree[a].append(b)
    tree[b].append(a)



def main():
    ans = getDeci(tree)
    if (ans[0]+2)%3==0:
        return "Second"
    else:
        return "First"

print(main())


Fixed submission:
from collections import deque
from heapq import heappush,heappop
import re
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def getDeci(tree):
    def saiki(v):
        root = [0,v,-1]
        cur = None
        qu = deque()
        qu.append(root)
        while len(qu)!=0:
            cur = qu.popleft()
            for e in tree[cur[1]]:
                if e ==cur[2]:
                    continue
                qu.append([cur[0]+1,e,cur[1]])
        return cur
    leaf = saiki(0)
    ans = saiki(leaf[1])
    return ans

    
N = int_raw()
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = ints_raw()
    a = a-1
    b = b-1
    tree[a].append(b)
    tree[b].append(a)



def main():
    ans = getDeci(tree)
    if (ans[0]+2)%3==0:
        return "Second"
    else:
        return "First"

print(main())
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush,heappop
import queue
import re
import math
import functools

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


N = int_raw()
As = ints_raw()


def main():
    ans = 0
    for i in range(N):
        ans = max(ans,functools.reduce(gcd, As[:i]+As[i+1:]) )
    return ans
print(main())


Fixed submission:
from heapq import heappush,heappop
import queue
import re
import math
import functools
import numpy

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


N = int_raw()
As = ints_raw()


def main():
    f_gcds = [As[0]]
    for i in range(1,N):
        f_gcds.append(gcd(As[i],f_gcds[-1]))
    b_gcds = [0]*(N-1)+[As[-1]]
    for i in range(N-2,-1,-1):
        b_gcds[i] = gcd(As[i],b_gcds[i+1])
    ans = max(b_gcds[1],f_gcds[-2])
    for i in range(1,N-1):
        ans = max(ans,gcd(f_gcds[i-1],b_gcds[i+1]))
    return ans

print(main())

Buggy python submission (verdict: Runtime Error):
from heapq import heappush,heappop
import queue
import re
import math
import functools

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]


N = int_raw()
A = ints_raw()


def main():
    ans = 0
    for i in range(N):
        ans = max(ans,functools.reduce(math.gcd, A[:i]+A[i+1:]) )
    return ans
print(main())


Fixed submission:
from heapq import heappush,heappop
import queue
import re
import math
import functools
import numpy

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


N = int_raw()
As = ints_raw()


def main():
    f_gcds = [As[0]]
    for i in range(1,N):
        f_gcds.append(gcd(As[i],f_gcds[-1]))
    b_gcds = [0]*(N-1)+[As[-1]]
    for i in range(N-2,-1,-1):
        b_gcds[i] = gcd(As[i],b_gcds[i+1])
    ans = max(b_gcds[1],f_gcds[-2])
    for i in range(1,N-1):
        ans = max(ans,gcd(f_gcds[i-1],b_gcds[i+1]))
    return ans

print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int, ss_raw())

INF = 1 << 29
DIV = 10**9 +7
N,X  = ints_raw()
Ss = ints_raw()

Ss.sort()

def rec(n,subSs):
    if len(subSs) ==1:
        return n%subSs[0]
    else:
        neoSub = subSs[:len(subSs)-1]
        return (rec(n,neoSub)*(len(subSs)-1) + rec(n%subSs[-1],neoSub))%DIV

def ans():
    return rec(X,Ss)

print ans()


Fixed submission:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int, ss_raw())

INF = 1 << 29
DIV = 10**9 +7
N,X  = ints_raw()
dp = [{} for x in xrange(X+1)]

Ss = ints_raw()

Ss.sort()


def rec(n,idx):
    if idx == 0:
        return n%Ss[0]
    elif idx in dp[n]:
        return dp[n][idx]
    else:
        ans = (rec(n,idx-1)*idx + rec(n%Ss[idx],idx-1))%DIV
        dp[n][idx]=ans
        return ans

def ans():
    return rec(X,N-1)

print ans()
Buggy python submission (verdict: Runtime Error):
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

N = int_raw()
memo = [{} for x in range(N+1)]

dna = ["A","C","G","T"]

def chk(last4):
    for i in range(len(last4)):
        l = list(last4)
        if i > 0:
            l[i],l[i-1] = l[i-1],l[i]
        if "AGC" in "".join(l):
            return False
    return True

def rec(idx, last3):
    if idx == N:
        return 1
    elif last3 in memo[idx]:
        return memo[idx][last3]
    else:
        ret =0
        for d in dna:
            if chk(last3 + d):
                ret+= rec(idx+1,last3[1:]+d)
                ret = ret % (10**9+7)
        memo[idx][last3] = ret
        return ret


def ans():
    return rec(0,"TTT")

print(ans())


Fixed submission:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in xrange(n)]

def make2d_arr(w,h,val =INF):
    return [[val for i in xrange(w)]for i in xrange(h)]

table = {"A":"T", "C":"G", "G":"C", "T":"A" }
b = raw_input()
print table[b]
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
if a + b <= k:
    print(0,0)
elif a <= k:
    print(0, a+b-k)
else 
    print(a-k,b)

Fixed submission:
a,b,k = map(int,input().split())
if a + b <= k:
    print(0,0)
elif a <= k:
    print(0, a+b-k)
else:
    print(a-k,b)

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
if a + b <= k:
    print(0,0)
elif a <= k:
    print(0, a+b-k)
else 
    print(a-k,0)

Fixed submission:
a,b,k = map(int,input().split())
if a + b <= k:
    print(0,0)
elif a <= k:
    print(0, a+b-k)
else:
    print(a-k,b)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
for i in range(k):
    if a >= 1:
        a -= 1
    elif a < 1 and b >=1:
        b -= 1
print(a,b,end=" ")

Fixed submission:
a,b,k = map(int,input().split())
if a + b <= k:
    print(0,0)
elif a <= k:
    print(0, a+b-k)
else:
    print(a-k,b)

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input.split())
for i in range(k):
    if a >= 1:
        a -= 1
    elif a < 1 and b >=1:
        b -= 1
print(a,b,end=" ")

Fixed submission:
a,b,k = map(int,input().split())
if a + b <= k:
    print(0,0)
elif a <= k:
    print(0, a+b-k)
else:
    print(a-k,b)
Buggy python submission (verdict: Runtime Error):
N = int(input())

if X >= 30:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())

if N >= 30:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

t = 7
ans = 1

for _ in range(K):
    if t % K == 0:
        print(ans)
        exit(0)
    else:
        t = t * 10 + 7
        ans += 1

print(-1)

Fixed submission:
K = int(input())

t = 7
ans = 1

for _ in range(K):
    if t % K == 0:
        print(ans)
        exit(0)
    else:
        t = (t * 10 + 7) % K
        ans += 1

print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A = A + A
ans = [0] * N
a = 0
for i in range(N-1):
    a ^= A[i]
ans[N-1] = a
W = N - 1
for i in range(N-1):
    remove = A[i]
    addition = A[i+W]
    a = remove^a^addition
    ans[i] = a

print(" ".join([str(i) for i in ans))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = A + A
ans = [0] * N
a = 0
for i in range(N-1):
    a ^= A[i]
ans[N-1] = a
W = N - 1
for i in range(N-1):
    remove = A[i]
    addition = A[i+W]
    a = remove^a^addition
    ans[i] = a

print(" ".join([str(i) for i in ans]))

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

ans = []
for i in range(N):
    a = 0
    for j in range(N):
        if i != j:
            a ^= A[j]
    ans.append(str(a))

print(" ".join(ans))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = A + A
ans = [0] * N
a = 0
for i in range(N-1):
    a ^= A[i]
ans[N-1] = a
W = N - 1
for i in range(N-1):
    remove = A[i]
    addition = A[i+W]
    a = remove^a^addition
    ans[i] = a

print(" ".join([str(i) for i in ans]))
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V<=W:
    print("NO")
    import sys
    sys.exit()

# import math
# if abs(B-A)/(V-W) <= T:
#     print("YES")
# else:
#     print("NO")

# print("t=",t)
# print("A+Vt=", A+V*t)
# print("B+Wt=", B+W*t)

if A+V*t >= B+W*t:
    if 1 <= t and t <= T:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V<=W:
    print("NO")
    import sys
    sys.exit()
import math
if abs(B-A)/(V-W) <= T:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Time Limit Exceeded):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

ok = False
for i in range(T+1):
    if A + (V*T) >= B + (W*T):
        ok = True

if ok:
    print("YES")
else:
    print("NO")


Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if V<=W:
    print("NO")
    import sys
    sys.exit()
import math
if abs(B-A)/(V-W) <= T:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())

ans = 1

import sys

if 0 in A:
  print(0)
  sys.exit()
  

for a in A:
  ans *= a
	if ans > pow(10, 18):
  	print(-1)
  	sys.exit()

print(ans)
  

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

ans = 1

import sys

if 0 in A:
  print(0)
  sys.exit()
  
for a in A:
  ans *= a
  if ans > pow(10, 18):
      print(-1)
      sys.exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = map(int, input().split())

ans = 1

for a in A:
  ans *= a
  
if ans > pow(10, 18):
  print(-1)
  import sys
  sys.exit()

print(ans)
  

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

ans = 1

import sys

if 0 in A:
  print(0)
  sys.exit()
  
for a in A:
  ans *= a
  if ans > pow(10, 18):
      print(-1)
      sys.exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, X = map(int, input().split())
C = [0] * N
A = []

for __ in range(N):
    nums = list(map(int, input().split()))
    C[__] = nums[0]
    A.append(nums[1:])
mincost = 10e9
ok = False
for i in range(1 << N):
    cost = 0
    skill = [0] * M

    for u in range(N):
        if i & (1<<u):
            cost += C[u]
            for si, s in enumerate(A[u]):
                skill[si] += s
    
    # check
    if all([s >= X for s in skill]):
        ok = True
        if mincost > cost:
            mincost = cost

print(mincost if ok else -1)
 dp


Fixed submission:
N, M, X = map(int, input().split())
C = [0] * N
A = []

for __ in range(N):
    nums = list(map(int, input().split()))
    C[__] = nums[0]
    A.append(nums[1:])

mincost = 10e9
ok = False
for i in range(1 << N):
    cost = 0
    skill = [0] * M

    for u in range(N):
        if i & (1<<u):
            cost += C[u]
            for si, s in enumerate(A[u]):
                skill[si] += s
    
    # check
    if all([s >= X for s in skill]):
        ok = True
        if mincost > cost:
            mincost = cost

print(mincost if ok else -1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

mp = dict()
for ix in range(N):
    mp[ix+1] = A[ix]

hist = set()
cur = 1
cnt = 0

while True:
    cur = mp[cur]
    cnt += 1

    if cur in hist:
        break
    else:
        hist.add(cur)

cycle_sp = cur
cycle_l = 0

while True:
    cur = mp[cur]
    cycle_l += 1

    if cur == cycle_sp:
        cycle_l -= 1
        break

rest = (K-cnt) % cycle_l

while rest > 0:
    cur = mp[cur]
    rest -= 1

print(cur)




Fixed submission:
import sys

n, k = map(int, input().split())
ara = [0]
ara += list(map(int, input().split()))

now = 1
vis = []
taken = [0]*(n+1)

while taken[now] == 0:
    vis.append(now)
    taken[now] = 1
    now = ara[now]

cycleLen = len(vis) - vis.index(now)

if k < vis.index(now):
    print(vis[k])
    sys.exit()

k -= vis.index(now)
k %= cycleLen

print(vis[k + vis.index(now)])
Buggy python submission (verdict: Runtime Error):
X = int(input())
import sys
for a in range(-118, 120, 1):
    for b in range(-119, 119, 1):
        if x == pow(a,5) - pow(b,5):
            print(x)
            sys.exit()

Fixed submission:
X = int(input())
import sys
for a in range(-118, 120, 1):
    for b in range(-119, 119, 1):
        if X == pow(a,5) - pow(b,5):
            print(a, b)
            sys.exit()
Buggy python submission (verdict: Runtime Error):
r = int(input())
import math
print(2*r * math.PI)

Fixed submission:
r = int(input())
import math
print(2*r * math.pi)

Buggy python submission (verdict: Runtime Error):
r = int(input())
import math
print(r * math.PI)

Fixed submission:
r = int(input())
import math
print(2*r * math.pi)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
         
t = sum(A)
if N < t:
  print(-1)
  exit(0)
else:
  print(N-A)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
         
t = sum(A)
if N < t:
  print(-1)
  exit(0)
else:
  print(N-t)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split())
         
t = sum(A)
if N < t:
  print(-1)
else:
  print(N-A)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
         
t = sum(A)
if N < t:
  print(-1)
  exit(0)
else:
  print(N-t)

Buggy python submission (verdict: Runtime Error):
r = int(input())
import math
print(2*r * math.pi)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
         
t = sum(A)
if N < t:
  print(-1)
  exit(0)
else:
  print(N-t)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

from collections import defaultdict
d = defaultdict(list)

for ix, c in enumerate(S):
    d[c].append(ix+1)

ans = len(d["B"]) * len(d["G"]) * len(d["R"])

for i in range(1, N+1):
    ci = S[i-1]
    for j in range(i+1, N+1):
        cj = S[j-1]

        if ci == cj:
            continue

        k = 2 * j - i
        if k > j and k <= N:
            ck = S[k-1]
            if ci != ck and cj != ck:
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = input()

from collections import defaultdict
# d = defaultdict(list)
d = defaultdict(int)

for ix, c in enumerate(S):
    # d[c].append(ix+1)
    d[c] += 1

# ans = len(d["B"]) * len(d["G"]) * len(d["R"])
ans = d["R"] * d["G"] * d["B"]

for i in range(1, N+1):
    ci = S[i-1]
    for j in range(i+1, N+1):
        cj = S[j-1]

        if ci == cj:
            continue

        k = j + j - i
        if k <= N:
            ck = S[k-1]
            if ci != ck and cj != ck:
                ans -= 1
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

from collections import defaultdict
d = defaultdict(list)

for ix, c in enumerate(S):
    d[c].append(ix+1)

ans = len(d["B"]) * len(d["G"]) * len(d["R"])

for i in range(1, N+1):
    for j in range(i+1, N+1):
        k = 2 * j - i
        # print(i,j,k)
        if k > j and k <= N and S[i-1] != S[j-1] and S[i-1] != S[k-1] and S[j-1] != S[k-1]:
            ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = input()

from collections import defaultdict
# d = defaultdict(list)
d = defaultdict(int)

for ix, c in enumerate(S):
    # d[c].append(ix+1)
    d[c] += 1

# ans = len(d["B"]) * len(d["G"]) * len(d["R"])
ans = d["R"] * d["G"] * d["B"]

for i in range(1, N+1):
    ci = S[i-1]
    for j in range(i+1, N+1):
        cj = S[j-1]

        if ci == cj:
            continue

        k = j + j - i
        if k <= N:
            ck = S[k-1]
            if ci != ck and cj != ck:
                ans -= 1
        else:
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
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)

temp = P[:X] + Q[:Y]

temp.sort()
ans = sum(temp)
for ri in R:
    if temp[0] < ri:
        ans += ri - temp[0]
        temp.pop(0)
    else:
        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)

temp = P[:X] + Q[:Y] + R

temp.sort(reverse=True)
ans = sum(temp[:X+Y])

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
F = list(map(int, input().split()))
M = list(map(int, input().split()))
C = []

for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    C.append((x,y,c))

minF = min(F)
minM = min(M)
ans = minF + minM

for x, y, z in C:
    tmp = F[x] + F[y] - z
    if tmp < ans:
        ans = tmp

print(ans)

Fixed submission:
A, B, M = map(int, input().split())
Frz = list(map(int, input().split()))
Mic = list(map(int, input().split()))
C = []

for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    C.append((x,y,c))

minF = min(Frz)
minM = min(Mic)
ans = minF + minM

for x, y, z in C:
    tmp = Frz[x] + Mic[y] - z
    if tmp < ans:
        ans = tmp

print(ans)