Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
from functools import reduce,lru_cache
from operator import mul

def main():
  sys.setrecursionlimit(10 ** 5)
  N,M = map(int,input().split())
  
  @lru_cache(maxsize = None)
  def recur(n):
    if n == 0:
      return 1
    else:
      m = n * recur(n - 1)
      return m
      
  if N == M:
    L = [i for i in range(1,N + 1)]
    #ans = (reduce(mul,L) ** 2) * 2  % (10 ** 9 + 7)
    ans = (recur(N) % (10 ** 9 + 7))
    print(ans)
  elif abs(M - N) == 1: 
    ans = 1
    ans *= (recur(N) % (10 ** 9 + 7)) 
    ans *= (recur(M) % (10 ** 9 + 7))
    print(ans)
    
  else:
    print(0)
    
main()

Fixed submission:
import sys
from functools import reduce,lru_cache
import math
from operator import mul

def main():
  #sys.setrecursionlimit(10 ** 5 + 1)
  N,M = map(int,input().split())
  
  @lru_cache(maxsize = None)
  def recur(n):
    if n == 0:
      return 1
    else:
      m = n * recur(n - 1)
      return m
      
  if N == M:
    L = [i for i in range(1,N + 1)]
    #ans = (reduce(mul,L) ** 2) * 2  % (10 ** 9 + 7)
    ans = (math.factorial(M) ** 2) * 2 % ((10 ** 9) + 7)
    print(ans)
  elif abs(M - N) == 1: 
    ans = math.factorial(N) * math.factorial(M) % ((10 ** 9) + 7)
    print(ans)
    
  else:
    print(0)
    
main()

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul

def main():
  N,M = map(int,input().split())
  if N == M:
    L = [i for i in range(1,N + 1)]
    ans = (reduce(mul,L) ** 2) * 2  % (10 ** 9 + 7)
    print(ans)
  elif N + 1 == M or M + 1 == N: 
    L1 = [i for i in range(1,N + 1)]
    L2 = [i for i in range(1,M + 1)]
    ans = (reduce(mul,L1)) * (reduce(mul,L2)) % (10 ** 9 + 7)
    print(ans)
  else:
    print(0)
main()

Fixed submission:
import sys
from functools import reduce,lru_cache
import math
from operator import mul

def main():
  #sys.setrecursionlimit(10 ** 5 + 1)
  N,M = map(int,input().split())
  
  @lru_cache(maxsize = None)
  def recur(n):
    if n == 0:
      return 1
    else:
      m = n * recur(n - 1)
      return m
      
  if N == M:
    L = [i for i in range(1,N + 1)]
    #ans = (reduce(mul,L) ** 2) * 2  % (10 ** 9 + 7)
    ans = (math.factorial(M) ** 2) * 2 % ((10 ** 9) + 7)
    print(ans)
  elif abs(M - N) == 1: 
    ans = math.factorial(N) * math.factorial(M) % ((10 ** 9) + 7)
    print(ans)
    
  else:
    print(0)
    
main()
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

def recur(s,c):
  if len(set(s)) == 1:
    return c
  else:
    ret = []
    roll = 2 ** (len(s) - 2)
    for i in range(roll):
      sen = ""
      for j in range(len(s) - 1):
        if ((i >> j) & 1):
          sen += s[j + 1]
        else:
          sen += s[j]
      ret.append(recur(sen,c + 1))
    return min(ret)
      
print(recur(S,0))

Fixed submission:
S = input()
type = sorted(set(S))
count = [0] * len(type)

for i,t in enumerate(type):
  sen = S
  con = 0
  while True:
    tmp = ""
    if len(set(sen)) == 1:
      count[i] = con
      break
    for j in range(len(sen) - 1):
      if (sen[j] == t) or (sen[j + 1] == t):
        tmp += t
      else:
        tmp += sen[j]
    con += 1
    sen = tmp

print(min(count))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

totals = [0] * N
totals[0] = A[0]
con = 0

if totals[0] == 0:
  for i in range(1,N):
    if A[i] != 0:
      f = A[i]
      if f > 0:
        totals[0] = -1
      else:
        totals[0] = 1
    break
  else:
    totals[0] = 1
  con += 1

for i in range(1,N):
  totals[i] = totals[i - 1] + A[i]
  if totals[i - 1] * totals[i] >= 0:
    if totals[i - 1] < 0:
      con += abs(1 - totals[i])
      totals[i] += abs(1 - totals[i])
    elif totals[i - 1] > 0:
      con += abs(-1 - totals[i])
      totals[i] -= abs(-1 - totals[i])
  print(totals[:i + 1])
  
print(con)


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

#値を修正する場合、1か−1にすればよい
##そのためには、値の絶対値に1を足した数を加えればよい

#正、負のパターンと負、正のパターンの両方について算出し、小さい方を出力する
##没解だと、所与のA[0]の符号を基準としたまま、答えを提出していたが、
##当然、それが最適値であるとは限らない！！！

total = 0
ans = 0
total2 = 0
ans2 = 0

for i in range(N):
    total += A[i]
    #奇数番目を正にする
    if i % 2 == 0:
        #1より小さい == 0以下
        if total < 1:
            ans += 1 - total
            total = 1
    else:
        #0以上
        if total > -1:
            ans += (1 + total)
            total = -1

for i in range(N):
    total2 += A[i]
    #偶数番目を正にする
    if i % 2 == 1:
        if total2 < 1:
            ans2 += 1 - total2
            total2 = 1
    else:
        if total2 > -1:
            ans2 += 1 + total2
            total2 = -1

print(min(ans,ans2))
Buggy python submission (verdict: Runtime Error):
import copy

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

ans = [None for i in range(2 ** (N - 1))]
seen = 1  #[[A[j] for j in range(i,N) if A[j] > A[i]] for i in range(0,N)]

for i in range(2 ** (N - 1)):
  AA = copy.deepcopy(A)
  cost = 0
  for j in range(N - 1):
    m = max(AA[:j + 1])
    a = AA[j + 1]
    if ((i >> j) & 1) and a <= m:
      cost += (m - a + 1)
      AA[j + 1] = m + 1
  print(AA,bin(i),cost)
  if len([AA[i] for i in range(1,N) if AA[i] > A[0]]) >= K - 1:
    ans[i] = cost
  
print(min(ans))


Fixed submission:
import copy

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

ans = [10 ** 12 for i in range(2 ** (N - 1))]
seen = 1  #[[A[j] for j in range(i,N) if A[j] > A[i]] for i in range(0,N)]

for i in range(2 ** (N - 1)):
  AA = copy.deepcopy(A)
  cost = 0
  s = str(bin(i))[2:]
  if s.count("1") >= K:
    continue
    
  for j in range(N - 1):
    m = max(AA[:j + 1])
    a = AA[j + 1]
    if ((i >> j) & 1) and a <= m:
      cost += (m - a + 1)
      AA[j + 1] = m + 1
  
  if len([AA[i] for i in range(1,N) if AA[i] > max(AA[:i])]) >= K - 1:
    ans[i] = cost
    #print(AA,bin(i),cost)
    
print(min(ans))

Buggy python submission (verdict: Runtime Error):
import copy

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

ans = 10 ** 12
seen = 1  #[[A[j] for j in range(i,N) if A[j] > A[i]] for i in range(0,N)]

for i in range(2 ** (N - 1)):
  AA = copy.deepcopy(A)
  cost = 0
  con = 0
  for j in range(N - 1):
    m = max(AA[:j + 1])
    W
    #print(AA[:j + 1])
    a = AA[j + 1]
    if ((i >> j) & 1) and A[j + 1] <= m:
      cost += (m - a + 1)
      AA[j + 1] = m + 1
      con += 1
    if con == K - 1:
      break
  if len([AA[i] for i in range(1,N) if AA[i] > A[0]]) == K - 1:
    ans = min(cost,ans)
  
print(ans)

Fixed submission:
import copy

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

ans = [10 ** 12 for i in range(2 ** (N - 1))]
seen = 1  #[[A[j] for j in range(i,N) if A[j] > A[i]] for i in range(0,N)]

for i in range(2 ** (N - 1)):
  AA = copy.deepcopy(A)
  cost = 0
  s = str(bin(i))[2:]
  if s.count("1") >= K:
    continue
    
  for j in range(N - 1):
    m = max(AA[:j + 1])
    a = AA[j + 1]
    if ((i >> j) & 1) and a <= m:
      cost += (m - a + 1)
      AA[j + 1] = m + 1
  
  if len([AA[i] for i in range(1,N) if AA[i] > max(AA[:i])]) >= K - 1:
    ans[i] = cost
    #print(AA,bin(i),cost)
    
print(min(ans))
Buggy python submission (verdict: Runtime Error):
X = int(input())

if x >= 1200:
  print("ARC")
else:
  print("ABC")

Fixed submission:
N = int(input())

if N >= 1200:
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
m = 0
p = 0
for i in S:
  if i == D:
    p -= 1
  else:
    p += 1
  if p >= m:
    m = p
print(m)

Fixed submission:
N = int(input())
S = input()
m = 0
p = 0
for i in S:
  if i == "D":
    p -= 1
  else:
    p += 1
  if p >= m:
    m = p
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [0,0]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = 1
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))

Fixed submission:
N = int(input())
P = [1,1]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = max(P[0]//t,P[1]//a,1)
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  X = input()

  st = "ST"
  con = X.count(st)
  
  while con > 0:
    X = X.replace(st,"")
    con = X.count(st)
    
  print(len(X))
  
if __name__ == '__main__':
  main()

Fixed submission:
from collections import deque

X = input()
N = len(X)
S = "S"
T = "T"
stack = deque("")

for i,str in enumerate(X):
  if str == S:
    stack.append(str)
  elif str == T:
    if len(stack) == 0:
      stack.append(str)
    elif stack[-1] == T:
      stack.append(str)
    elif stack[-1] == S:
      stack.pop()
      
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
def rem():
  X = input()
  N = len(X)
  
  st = "ST"
  con = X.count(st)
  
  while con > 0:
    X = X.replace(st,"")
    con = X.count(st)
    
  print(len(X))
  
rem()

Fixed submission:
from collections import deque

X = input()
N = len(X)
S = "S"
T = "T"
stack = deque("")

for i,str in enumerate(X):
  if str == S:
    stack.append(str)
  elif str == T:
    if len(stack) == 0:
      stack.append(str)
    elif stack[-1] == T:
      stack.append(str)
    elif stack[-1] == S:
      stack.pop()
      
print(len(stack))

Buggy python submission (verdict: Time Limit Exceeded):
X = input()
N = len(X)

st = "ST"
con = X.count(st)

while con > 0:
  X = X.replace(st,"")
  con = X.count(st)
  
print(len(X))

Fixed submission:
from collections import deque

X = input()
N = len(X)
S = "S"
T = "T"
stack = deque("")

for i,str in enumerate(X):
  if str == S:
    stack.append(str)
  elif str == T:
    if len(stack) == 0:
      stack.append(str)
    elif stack[-1] == T:
      stack.append(str)
    elif stack[-1] == S:
      stack.pop()
      
print(len(stack))
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,inputs().split())

if A + B + C == 17:
  if A + B or A + C or B + C == 10:
    print("YES")
  else:
    print("NO")
else:
  print("NO")

Fixed submission:
A,B,C = map(int,input().split())

if A + B + C == 17:
  if A + B or A + C or B + C == 10:
    print("YES")
  else:
    print("NO")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
a = round(float(a)*100)
b = int(b)
print(a*b//100)

Fixed submission:
a, b = input().split()
a = int(a)
b = round(float(b) * 100)
print(a * b // 100)
Buggy python submission (verdict: Runtime Error):
t = input()

prev = ""
res = []
for i, x in enumerate(t):
    if x == "?":
        if prev == "" or prev == "D" and (i < len(t) and t[i+1] != "P"):
            res.append("P")
        else:
            res.append("D")
    else:
        res.append(x)
    prev = x
print("".join(res))


Fixed submission:
t = input()

prev = ""
res = []
for i, x in enumerate(t):
    if x == "?":
        if prev == "" and len(t) == 1:
            res.append("D")
        elif prev == "" and (i < len(t) - 1 and t[i+1] == "P"):
            res.append("D")
        elif prev == "" or prev == "D" and (i < len(t) - 1 and t[i+1] != "P"):
            res.append("P")
        else:
            res.append("D")
    else:
        res.append(x)
    prev = res[-1]
print("".join(res))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

res = 0
for x in range(N):
    for y in range(x+1, N):
        for z in range(y+1,N):
            if S[x] != S[y] and S[y] != S[z] and S[x] != S[z] and (y - x != z - y):
                res += 1
print(res)


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

r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r * g * b

for x in range(N-2):
    for y in range(x+1, N-1):
        z = 2 * y - x
        if z >= N:
            break
        if S[x] != S[y] and S[y] != S[z] and S[x] != S[z]:
            ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = set(map(int, input().split()))
a = set(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")


Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n,m = set(map(int, input().split()))
a = set(map(int,input().split()))
d = sum(a)/(4.0*m)
count = 0
for x in a:
    if x >= d:
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n,m = set(map(int, input().split()))
a = set(map(int,input().split()))
d = sum(a)/(4.0*m)
count = 0
for x in a:
    if float(x) >= d:
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n,m = set(map(int, input().split()))
a = set(map(int,input().split()))
d = sum(a)/(4*m)
count = 0
for x in a:
    if float(x) >= d:
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
l = int(input())
print(f"{l**3 / 27:.10f}")


Fixed submission:
l = int(input())
print(l**3 / 27)

Buggy python submission (verdict: Runtime Error):
l = int(input())
print(f"{pow(l,3) / 27.0:.10f}")


Fixed submission:
l = int(input())
print(l**3 / 27)

Buggy python submission (verdict: Runtime Error):
l = int(input())
print(f"{pow(l / 3.0, 3):.10f}")


Fixed submission:
l = int(input())
print(l**3 / 27)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

count = {}
for x in A:
    if count.get(x):
        count[x] += 1
    else:
        count[x] = 1

for i in range(N):
    count[A[i]] -= 1
    s = 0
    for x in count.values():
        s += x * (x - 1) // 2
    print(s)
    count[A[i]] += 1


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

count = {}
for x in A:
    if count.get(x):
        count[x] += 1
    else:
        count[x] = 1

sub = {}
s = 0
for i, x in count.items():
    count[i] = x * (x - 1) // 2
    s += count[i]
    sub[i] = (x-1) * (x - 2) // 2

for i in range(N):
    print(s - count[A[i]] + sub[A[i]])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
flag = True
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        flag = not flag
    else:
        if (query[1] == "1" and flag) or (query[1] == "2" and not flag):
            s = query[2] + s
        else:
            s = s + query[2]
sf = 1 if flag else -1
print(s[::sf])


Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flag = True
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        flag = not flag
    else:
        if (query[1] == "1" and flag) or (query[1] == "2" and not flag):
            s.appendleft(query[2])
        else:
            s.append(query[2])
if not flag:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        s = s[::-1]
    else:
        if query[1] == "1":
            s = query[2] + s
        else:
            s = s + query[2]
print(s)


Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flag = True
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        flag = not flag
    else:
        if (query[1] == "1" and flag) or (query[1] == "2" and not flag):
            s.appendleft(query[2])
        else:
            s.append(query[2])
if not flag:
    s.reverse()
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
import statistics

n = int(input())
x = list(map(int, input().split()))

a = round(statistics.mean(x))
sums = 0
for i in x:
    sums += (i - a) ** 2
print(sums)


Fixed submission:
import statistics

n = int(input())
x = list(map(int, input().split()))

a = round(statistics.mean(x))
sums = 0
for i in x:
    sums += (i - a) ** 2
print(sums)
Buggy python submission (verdict: Runtime Error):
already = [False] * 200000
n = int(input())
a = list(map(int, input().split()))
for x in a:
    if already[x]:
        print("NO")
        break
    already[x] = True
else:
    print("YES")


Fixed submission:
already = {}
n = int(input())
a = list(map(int, input().split()))
for x in a:
    if already.get(x):
        print("NO")
        break
    already[x] = True
else:
    print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int,input().split()))

max_v = 0
max_i = 0
for x in range(n - k + 1):
    s = sum([p[x+i] for i in range(k)])
    if max_v < s:
        max_v = s
        max_i = x
sums = 0.0
for x in p[max_i:max_i+k]:
    sums += (x + 1) / 2

print("{:.6f}".format(sums))

Fixed submission:
n, k = map(int, input().split())
p = list(map(int,input().split()))
b = [(1 + p[i])/2 for i in range(n)]

ttl = sum(b[:k])
res = ttl
for i, v in enumerate(b[k:]):
    ttl += v - b[i]
    res = max(res, ttl)

print("{:.10f}".format(res))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]


def solve():
    G = [[False] * N for _ in range(N)]
    for a, b in AB:
        G[a][b] = True
        G[b][a] = True

    ans = 0
    visited = [False] * N
    for start in range(N):
        if visited[start]:
            continue
        nexts = [i for i in range(N) if G[start][i]]
        if all([H[start] > H[next] for next in nexts]):
            ans += 1
            for next in nexts:
                visited[next] = True

    print(ans)


solve()


Fixed submission:
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]


def solve():
    G = [0] * N
    for a, b in AB:
        G[a] = max(G[a], H[b])
        G[b] = max(G[b], H[a])

    ans = 0
    for i in range(N):
        if H[i] > G[i]:
            ans += 1

    print(ans)


solve()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]


def solve():
    G = [[False] * N for _ in range(N)]
    for a, b in AB:
        G[a][b] = True
        G[b][a] = True

    ans = 0
    for start in range(N):
        if all([H[start] > H[next] for next in [i for i in range(N) if G[start][i]]]):
            ans += 1
    print(ans)


solve()


Fixed submission:
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]


def solve():
    G = [0] * N
    for a, b in AB:
        G[a] = max(G[a], H[b])
        G[b] = max(G[b], H[a])

    ans = 0
    for i in range(N):
        if H[i] > G[i]:
            ans += 1

    print(ans)


solve()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
N, X, Y = [int(str) for str in input().strip().split()]

INF = 100000
d = [[INF] * N for _ in range(N)]

for i in range(N - 1):
    d[i][i + 1] = 1
    d[i + 1][i] = 1
d[X - 1][Y - 1] = 1
d[Y - 1][X - 1] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

dists = dict()
for i in range(N):
    for j in range(i + 1, N):
        k = d[i][j]
        dists[k] = dists.get(k, 0) + 1

for k in range(1, N):
    print(dists.get(k, 0))

Fixed submission:
#!/usr/bin/env python3
N, X, Y = [int(str) for str in input().strip().split()]

X -= 1
Y -= 1
dists = [0] * N
for i in range(N - 1):
    for j in range(i + 1, N):
        d = min(j - i, abs(X - i) + abs(Y - j) + 1)
        dists[d] += 1

for k in range(1, N):
    print(dists[k])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
X, Y, A, B, C = [int(str) for str in input().strip().split()]
ps = [int(str) for str in input().strip().split()]
qs = [int(str) for str in input().strip().split()]
rs = [int(str) for str in input().strip().split()]

def f(n):
    if n == 0:
        return sum(red_and_green)
    if n > X + Y:
        return sum(rs)
    return sum(red_and_green[:-n] + rs[:n])

ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)

red_and_green = ps[:X] + qs[:Y]
red_and_green.sort(reverse=True)

# print([f(i) for i in range(C)])
print(max([f(i) for i in range(C + 1)]))

Fixed submission:
#!/usr/bin/env python3
X, Y, A, B, C = [int(str) for str in input().strip().split()]
ps = [int(str) for str in input().strip().split()]
qs = [int(str) for str in input().strip().split()]
rs = [int(str) for str in input().strip().split()]

def sums(li):
    ret = [0]
    for i in range(len(li)):
        ret.append(ret[-1] + li[i])
    return ret

def f(n):
    return red_and_green_sums[X + Y - n] + r_sums[n]

ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)

r_sums = sums(rs)

red_and_green = ps[:X] + qs[:Y]
red_and_green.sort(reverse=True)
red_and_green_sums = sums(red_and_green)

# print([f(i) for i in range(C)])
print(max([f(i) for i in range(min(X + Y, C) + 1)]))