Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]
numh=[[i,0] for i in range(h)]
numw=[[i,0] for i in range(w)]
m=[[0]*w for _ in range(h)]
for hi,wi in hw:
  numh[hi-1][1]+=1
  numw[wi-1][1]+=1
  m[hi-1][wi-1]=1
numh.sort(key=lambda x:x[1])
numw.sort(key=lambda x:x[1])
ansh=numh[-1][1]
answ=numw[-1][1]
if ansh+answ==1:
  print(1)
  exit()
# 答えはansh+answまたはansh+answ-1
hk=set(())
while numh and numh[-1][1]==ansh:
  hk.add(numh.pop()[0])
wk=set(())
while numw and numw[-1][1]==answ:
  wk.add(numw.pop()[0])

for wi in wk:
  for hi in hk:
    if m[hi][wi]==0:
      print(ansh+answ)
      exit()
print(ansh+answ-1)

Fixed submission:
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for _ in range(m)]
numh=[[i,0] for i in range(h)]
numw=[[i,0] for i in range(w)]
d=set(())
for hi,wi in hw:
  numh[hi-1][1]+=1
  numw[wi-1][1]+=1
  d.add((hi-1,wi-1))
numh.sort(key=lambda x:x[1])
numw.sort(key=lambda x:x[1])
ansh=numh[-1][1]
answ=numw[-1][1]
if ansh+answ==1:
  print(1)
  exit()
# 答えはansh+answまたはansh+answ-1
hk=set(())
while numh and numh[-1][1]==ansh:
  hk.add(numh.pop()[0])
wk=set(())
while numw and numw[-1][1]==answ:
  wk.add(numw.pop()[0])

for wi in wk:
  for hi in hk:
    if (hi,wi) not in d:
      print(ansh+answ)
      exit()
print(ansh+answ-1)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# 文字列をinput()した場合、末尾に改行が入るので注意
def main(R,C,K,rcv):
  inf=float('inf')
  dp0=[[-inf,-inf,-inf,0] for _ in range(C)]
  dp1=[[-inf]*4 for _ in range(C)]
  dp0[0][3]=0
  rcv.sort(key=lambda x:R*x[0]+x[1])
  i=0
  nowc=0
  while rcv[i][0]==1:
    nextc=rcv[i][1]-1
    for j in range(nowc+1,nextc+1):
      dp0[j][0]=dp0[nowc][0]
      dp0[j][1]=dp0[nowc][1]
      dp0[j][2]=dp0[nowc][2]
    v=rcv[i][2]
    dp0[nextc][0]=max(dp0[nextc][0],dp0[nextc][1]+v)
    dp0[nextc][1]=max(dp0[nextc][1],dp0[nextc][2]+v)
    dp0[nextc][2]=max(dp0[nextc][2],dp0[nextc][3]+v)
    i+=1
    nowc=nextc
    for j in range(nowc+1,C):
      dp0[j][0]=dp0[nowc][0]
      dp0[j][1]=dp0[nowc][1]
      dp0[j][2]=dp0[nowc][2]
  for j in range(1,R):
    for c in range(C):
      dp0[c][3]=max(dp0[c])
      dp0[c][2]=-inf
      dp0[c][1]=-inf
      dp0[c][0]=-inf
    nowc=0
    while i<K and rcv[i][0]==j+1:
      nextc=rcv[i][1]-1
      for k in range(nowc+1,nextc+1):
        dp0[k][0]=dp0[nowc][0]
        dp0[k][1]=dp0[nowc][1]
        dp0[k][2]=dp0[nowc][2]
      v=rcv[i][2]
      dp0[nextc][0]=max(dp0[nextc][0],dp0[nextc][1]+v)
      dp0[nextc][1]=max(dp0[nextc][1],dp0[nextc][2]+v)
      dp0[nextc][2]=max(dp0[nextc][2],dp0[nextc][3]+v)
      i+=1
      nowc=nextc
    for j in range(nowc+1,C):
      dp0[j][0]=dp0[nowc][0]
      dp0[j][1]=dp0[nowc][1]
      dp0[j][2]=dp0[nowc][2]
    #print(dp0)

  print(max(dp0[-1]))


if __name__=='__main__':
  R,C,K=map(int,input().split())
  rcv=[list(map(int,input().split())) for _ in range(K)]
  #import datetime
  #print(datetime.datetime.now())
  main(R,C,K,rcv)
  #print(datetime.datetime.now())




Fixed submission:
import sys
input = sys.stdin.readline
def main(R,C,K,rcv):
  inf=float('inf')
  dp0=[[-inf,-inf,-inf,0] for _ in range(C)]
  # dp0[i][j]:i列目の時点で残りちょうどj個取れる時の最大値
  rcv.sort(key=lambda x:C*R*x[0]+x[1])
  i=0
  nowc=0
  for j in range(R):
    # j+1行目に対する操作
    # 初期化
    for c in range(C):
      dp0[c][3]=max(dp0[c])
      dp0[c][2]=-inf
      dp0[c][1]=-inf
      dp0[c][0]=-inf
    nowc=0
    while i<K and rcv[i][0]==j+1:
      nextc=rcv[i][1]-1
      for k in range(nowc+1,nextc+1):
        dp0[k][0]=max(dp0[k][0],dp0[nowc][0])
        dp0[k][1]=max(dp0[k][1],dp0[nowc][1])
        dp0[k][2]=max(dp0[k][2],dp0[nowc][2])
      v=rcv[i][2]
      dp0[nextc][0]=max(dp0[nextc][0],dp0[nextc][1]+v)
      dp0[nextc][1]=max(dp0[nextc][1],dp0[nextc][2]+v)
      dp0[nextc][2]=max(dp0[nextc][2],dp0[nextc][3]+v)
      i+=1
      nowc=nextc
    for k in range(nowc+1,C):
      dp0[k][0]=max(dp0[k][0],dp0[nowc][0])
      dp0[k][1]=max(dp0[k][1],dp0[nowc][1])
      dp0[k][2]=max(dp0[k][2],dp0[nowc][2])
    #print(dp0)
  print(max(dp0[-1]))
if __name__=='__main__':
  R,C,K=map(int,input().split())
  rcv=[list(map(int,input().split())) for _ in range(K)]
  main(R,C,K,rcv)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
  chk=0
  for ai in a:
    # 長さx以下に分割するなら最小でtmp本にわかれる
    tmp=math.ceil(ai/x)
    chk+=tmp
  return chk<=n+k
l,r=0,max(a)
for _ in range(100):
  x=(l+r)/2
  if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
    l,r=l,x
  else:
    l,r=x,r
x=(l+r)/2
print(math.ceil(x))
#print(l,r,x)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
  chk=0
  for ai in a:
    # 長さx以下に分割するなら最小でtmp本にわかれる
    tmp=math.ceil(ai/x)
    chk+=tmp
  return chk<=n+k
l,r=0,max(a)
for _ in range(50):
  x=(l+r)/2
  if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
    l,r=l,x
  else:
    l,r=x,r
x=(l+r)/2
print(math.ceil(x))
#print(l,r,x)
Buggy python submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
tmp=0
cb=[0]
for bi in b:
  tmp+=bi
  cb.append(tmp)
import bisect
s=bisect.bisect_right(ca,k)-1
ans=ca[s]
now_a=s
z=k-ca[now_a]
now_b=bisect.bisect_right(cb,z)-1
t=ca[now_a]+cb[now_b]
ans=now_a+now_b
for i in range(s):
  now_a-=1
  t-=a[now_a]
  while t+b[now_b]<=k:
    t+=b[now_b]
    now_b+=1
  ans=max(ans,now_a,now_b)
print(ans)



Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
tmp=0
cb=[0]
for bi in b:
  tmp+=bi
  cb.append(tmp)
import bisect
s=bisect.bisect_right(ca,k)-1
ans=ca[s]
now_a=s
z=k-ca[now_a]
now_b=bisect.bisect_right(cb,z)-1
t=ca[now_a]+cb[now_b]
#print(now_a,now_b)
ans=now_a+now_b
for i in range(s):
  now_a-=1
  t-=a[now_a]
  while now_b<m and t+b[now_b]<=k:
    t+=b[now_b]
    now_b+=1
  ans=max(ans,now_a+now_b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

def main(n,a):
    s=a[0]+a[1]
    z=0
    for ai in a[2:]:
        z^=ai
    # i+j=s,i<=a[0],i^j=z となるi,jを探す
    # i+j=i^j+2*(i & j)
    # s = z + 2*(i & j)
    # i & j = (s-z)/2 = d
    # z = 2*(i & j) - s = i ^ j
    # d = (s-z) / 2
    # z = x^y , x&y=0
    # d^x,d^yは条件を満たす。d^x+d^y=d^x^d^y + 2*((d^x)&(d^y))= z + 2*d = s
    # (d^x)^(d^y)=x^y=z
    # (d^x)&(d^y)=d (z & d = 0 のときのみ)
    if s-z<0 or (s-z)%2==1:return -1
    d=(s-z)//2
    if d&z!=0:return -1
    part=[]
    i=0
    while z//pow(2,i):
        if (z//pow(2,i))%2==1:part.append(pow(2,i))
        i+=1
    ans=float('inf')
    k=len(part)
    for i in range(2**k):
        x=0
        y=0
        for j in range(k):
            if (i>>j)&1:
                x+=part[j]
            else:
                y+=part[j]
        u=d^x
        v=d^y
        if u+v==s and u<=a[0] and u!=0:
            ans=min(ans,a[0]-u)
    return ans if ans!=float('inf') else -1





n=int(input())
a=list(map(int,input().split()))
print(main(n,a))

Fixed submission:
def main(n,a):
    s=a[0]+a[1]
    z=0
    for ai in a[2:]:
        z^=ai
    # i+j=s,i<=a[0],i^j=z となるi,jを探す
    # i+j=i^j+2*(i & j)
    # s = z + 2*(i & j)
    # i & j = (s-z)/2 = d
    # z = 2*(i & j) - s = i ^ j
    # d = (s-z) / 2
    # z = x^y , x&y=0
    # d^x,d^yは条件を満たす。d^x+d^y=d^x^d^y + 2*((d^x)&(d^y))= z + 2*d = s
    # (d^x)^(d^y)=x^y=z
    # (d^x)&(d^y)=d (z & d = 0 のときのみ)
    if s-z<0 or (s-z)%2==1:return -1
    d=(s-z)//2
    if d&z!=0:return -1
    if not d<=a[0]:return -1
    part=[]
    i=0
    while z//pow(2,i):
        if (z//pow(2,i))%2==1:part.append(pow(2,i))
        i+=1
    ans=float('inf')
    k=len(part)
    x=0
    while part:
        tmp=part.pop()
        if d^(x+tmp)<=a[0]:
            x+=tmp
    return a[0]-(d^x) if d^x else -1


n=int(input())
a=list(map(int,input().split()))
print(main(n,a))
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
s=input()
n=len(s)
mod=pow(10,9)+7

# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n,r,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] 
g2=[1,1] 
inverse=[0,1]
for i in range(2,n+k+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

import numpy as np
tmp=[pow(25,i,mod)*cmb(i+n-1,n-1,mod) for i in range(k+1)]
f=np.array(tmp)
g=np.zeros(k+1,int)
g[0]=1
for ki in range(1,k+1):
  g[ki]=f[ki]+26*g[ki-1]
  g[ki]%=mod
print(g[k])


Fixed submission:
k=int(input())
s=input()
n=len(s)
mod=pow(10,9)+7

# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
def cmb(n,r,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] 
g2=[1,1] 
inverse=[0,1]
for i in range(2,n+k+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

f=[pow(25,i,mod)*cmb(i+n-1,n-1,mod) for i in range(k+1)]
g=[0]*(k+1)
g[0]=1
for ki in range(1,k+1):
  g[ki]=f[ki]+26*g[ki-1]
  g[ki]%=mod
print(g[k])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,int(n**0.5)+10)):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,int(n**0.5)+10)):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(n**0.5+1):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,int(n**0.5)+10)):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(k):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,int(n**0.5)+10)):
  add_a=[0]*(n+1)
  for i in range(n):
    a[i]
    add_a[max(0,i-a[i])]+=1
    add_a[min(n,i+a[i]+1)]-=1
  tmp=0
  for i in range(n):
    tmp+=add_a[i]
    a[i]=tmp
print(' '.join(map(str,a)))
Buggy python submission (verdict: Time Limit Exceeded):
def slv(n,a,s):
    dp=[set(()) for _ in '_'*(n+1)]
    dp[-1]={0}
    for i in range(n-1,-1,-1):
        if s[i]=='0':
            for j in dp[i+1]:
                dp[i].add(a[i]^j)
                dp[i].add(j)
        else:
            if a[i] in dp[i+1]:
                dp[i]=dp[i+1]
            else:
                dp[i]=set(())
            """
            for j in dp[i+1]:
                if a[i]^j in dp[i+1]:
                    dp[i].add(j)
                    dp[i].add(j^a[i])
            """
        if not dp[i]:return 1
    if dp[0]:return 0
    return 1

t=int(input())
n=[]
a=[]
s=[]
for _ in range(t):
    n.append(int(input()))
    a.append(list(map(int,input().split())))
    s.append(input())
for i in range(t):
    print(slv(n[i],a[i],s[i]))

"""
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

1
0
0
"""

Fixed submission:
def slv(n,a,s):
  base=[0]
  for i in range(n-1,-1,-1):
    v=a[i]
    for j in sorted(base,reverse=True):
      v=min(v,j^v)
    if v==0:
      pass
    else:
      if s[i]=='0':base.append(v)
      if s[i]=='1':return 1
  if base:return 0
  return 1

t=int(input())
n=[]
a=[]
s=[]
for _ in range(t):
  n.append(int(input()))
  a.append(list(map(int,input().split())))
  s.append(input())
for i in range(t):
  print(slv(n[i],a[i],s[i]))
Buggy python submission (verdict: Time Limit Exceeded):
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
import numpy as np
dp=np.zeros((n+1,s+1),int)
# dp[i][j]:aの中からi個選んでjにできるものの個数。
dp[0][0]=1
for ai in a:
  if ai>s:
    continue
  for j in range(n,0,-1):
    dp[j][ai:]+=dp[j-1][:-ai]
    dp[j]%=mod
ans=0
for i in range(n+1):
  ans+=dp[i][s]*pow(2,n-i,mod)
  ans%=mod
print(ans)  



Fixed submission:
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
import numpy as np
dp=np.zeros((n+1,3001),int)
# dp[j]:総和がjになるようにできる空でない部分集合の個数。
dp[0][0]=1 # 遷移用、実際は0

for i in range(n):
  dp[i+1]+=dp[i]*2
  dp[i+1,a[i]:]+=dp[i,:-a[i]]
  dp[i+1]%=mod
print(dp[n][s])

#print(dp)

Buggy python submission (verdict: Time Limit Exceeded):
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
import math
import numpy as np
dp=np.zeros((n+1,s+1),int)
# dp[i][j]:aの中からi個選んでjにできるものの個数。
dp[0][0]=1
for ai in a:
  if ai>s:
    continue
  for j in range(n,0,-1):
    dp[j][ai:]+=dp[j-1][:-ai]
ans=0
for i in range(n+1):
  ans+=dp[i][s]*pow(2,n-i,mod)
  ans%=mod
print(ans)  



Fixed submission:
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
import numpy as np
dp=np.zeros((n+1,3001),int)
# dp[j]:総和がjになるようにできる空でない部分集合の個数。
dp[0][0]=1 # 遷移用、実際は0

for i in range(n):
  dp[i+1]+=dp[i]*2
  dp[i+1,a[i]:]+=dp[i,:-a[i]]
  dp[i+1]%=mod
print(dp[n][s])

#print(dp)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  mod=998244353
  n,m,k=map(int,input().split())
  def ncr_mod(n,r,mod):
    a,b=1,1
    for i in range(r):
      a*=n-i
      a%=mod
      b*=i+1
      b%=mod
    return (a*pow(b,mod-2,mod))%mod
  ans=m*pow(m-1,n-1,mod)
  ans%=mod
  for i in range(1,k+1):
    ans+=m*pow(m-1,n-1-i,mod)*ncr_mod(n-1,i,mod)
    ans%=mod
  print(ans)
    
if __name__=='__main__':
  main()


Fixed submission:
def main():
  mod=998244353
  n,m,k=map(int,input().split())
  def cmb(n, r, mod):
      if ( r<0 or r>n ):
          return 0
      r = min(r, n-r)
      return g1[n] * g2[r] * g2[n-r] % mod
  g1 = [1, 1] 
  g2 = [1, 1] 
  inverse = [0, 1]
  for i in range( 2, n + 1 ):
      g1.append( ( g1[-1] * i ) % mod )
      inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
      g2.append( (g2[-1] * inverse[-1]) % mod )

  ans=m*pow(m-1,n-1,mod)
  ans%=mod
  for i in range(1,k+1):
    ans+=(m*pow(m-1,n-1-i,mod))%mod*cmb(n-1,i,mod)
    ans%=mod
  print(ans)
  
if __name__=='__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a_=list(map(int,input().split()))
from collections import defaultdict
a=[[i,ai] for i,ai in enumerate(a_)]
sa=defaultdict(lambda:0)
# sa[(i,j)]:i番目の人までで自分の番号-身長がjの人
d=defaultdict(lambda:0)
# 自分の番号-身長の累計
mt=0
for i,ai in a:
  d[i-ai]+=1
  for k,v in d.items():
    sa[(i+1,k)]=v
ans=0
for i,ai in a:
  c=sa[(n,i+ai)]-sa[(i+1,i+ai)]
  ans+=c
print(ans)


Fixed submission:
def main(n,a_):
  from collections import defaultdict
  lr=[[i+ai,i-ai] for i,ai in enumerate(a_)]
  rs=defaultdict(lambda:0)
  ls=defaultdict(lambda:0)
  ans=0
  for l,r in lr:
    rs[r]+=1
    ls[l]+=1
  for k in rs.keys():
    ans+=rs[k]*ls[k]
  print(ans)
if __name__=='__main__':
  n=int(input())
  a_=list(map(int,input().split()))
  #n=200000
  #a_=[3 for _ in range(n)]
  main(n,a_)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a_=list(map(int,input().split()))
a=[[i,ai] for i,ai in enumerate(a_)]
ans=0
for i,ai in a:
  c=len([[j,aj]for j,aj in a if j>i and ai+i==j-aj])
  ans+=c
print(ans)


Fixed submission:
def main(n,a_):
  from collections import defaultdict
  lr=[[i+ai,i-ai] for i,ai in enumerate(a_)]
  rs=defaultdict(lambda:0)
  ls=defaultdict(lambda:0)
  ans=0
  for l,r in lr:
    rs[r]+=1
    ls[l]+=1
  for k in rs.keys():
    ans+=rs[k]*ls[k]
  print(ans)
if __name__=='__main__':
  n=int(input())
  a_=list(map(int,input().split()))
  #n=200000
  #a_=[3 for _ in range(n)]
  main(n,a_)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
all_a=[]
def make_a(t):
  ret=[]
  todo=[t]
  while todo:
    i=todo.pop()
    if len(i)==n:
      ret.append(i)
      continue
    for j in range(i[-1],m+1):
      todo.append(i+[j])
  return ret
for i in range(1,m+1):
  all_a.extend(make_a([1]))
ans=0
for an in all_a:
  ansi=0
  for a,b,c,d in abcd:
    if an[b-1]-an[a-1]==c:
      ansi+=d
  ans=max(ans,ansi)
print(ans)

Fixed submission:
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
# dfsで数列を生成
def dfs():
  todo=[[]]
  ret=[]
  while len(todo)>0:
    t=todo.pop()
    if len(t)==n:
      ret.append(t)
    else:
      l=t[-1] if len(t)>0 else 1
      for i in range(l,m+1):
        tc=t.copy()
        tc.append(i)
        todo.append(tc)
  return ret
def point(s):# 数列sに対する特典
  ret=0
  for a,b,c,d in abcd:
    if s[b-1]-s[a-1]==c:
      ret+=d
  return ret
a=dfs()
ans=0
for ai in a:
  ans=max(ans,point(ai))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
all_a=[]
def make_a(t):
  if len(t)==n:
    return [t]
  ret=[]
  for ti in range(t[-1],m+1):
    ret.extend(make_a(t+[ti]))
  return ret
for i in range(1,m+1):
  all_a.extend(make_a([1]))
ans=0
for an in all_a:
  ansi=0
  for a,b,c,d in abcd:
    if an[b-1]-an[a-1]==c:
      ansi+=d
  ans=max(ans,ansi)
print(ans)

Fixed submission:
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
# dfsで数列を生成
def dfs():
  todo=[[]]
  ret=[]
  while len(todo)>0:
    t=todo.pop()
    if len(t)==n:
      ret.append(t)
    else:
      l=t[-1] if len(t)>0 else 1
      for i in range(l,m+1):
        tc=t.copy()
        tc.append(i)
        todo.append(tc)
  return ret
def point(s):# 数列sに対する特典
  ret=0
  for a,b,c,d in abcd:
    if s[b-1]-s[a-1]==c:
      ret+=d
  return ret
a=dfs()
ans=0
for ai in a:
  ans=max(ans,point(ai))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  print(a[i:].count(i+1))


Fixed submission:

n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(n-1):
  if a[i] in d:
    d[a[i]]+=1
  else:
    d[a[i]]=1

for i in range(1,n+1):
  if i in d:
    print(d[i])
  else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
# 1<=i<j<k<=n
# j-i!=k-j
# si!=sj, sj!=sk, si!=sk
ans=0
cl=['R','G','B']
for i in range(n-2):
    c1=s[i]
    if c1=='R':
        c2='G'
        c3='B'
    if c1=='G':
        c2='R'
        c3='B'
    if c1=='B':
        c2='G'
        c3='R'
    # c2
    p=sum([x==c3 for x in s[i+1:]])
    pj=i+1
    for j in range(i+1,n-1):
        if s[j]!=c2:
            continue
        p-=sum([x==c3 for x in s[pj:j]])
        pj=j
        ans+=p
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1

    # c3
    p=sum([x==c2 for x in s[i+1:]])
    pj=i+1
    for j in range(i+1,n-1):
        if s[j]!=c3:
            continue
        p-=sum([x==c2 for x in s[pj:j]])
        pj=j
        ans+=p
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1

print(ans)


Fixed submission:
n=int(input())
s=input()
nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
for i in range(1,1+(n-1)//2):
      for j in range(n-2*i):
            if s[j]!=s[j+i] and s[j]!=s[2*i+j] and s[j+i]!=s[j+2*i]:
                  ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
# 1<=i<j<k<=n
# j-i!=k-j
# si!=sj, sj!=sk, si!=sk
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]:
            continue
        #ans+=len(s[j+1:].replace(s[i],'').replace(s[j],''))
        ans+=sum([x!=s[i] and x!=s[j] for x in s[j+1:]])
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1
print(ans)

Fixed submission:
n=int(input())
s=input()
nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
for i in range(1,1+(n-1)//2):
      for j in range(n-2*i):
            if s[j]!=s[j+i] and s[j]!=s[2*i+j] and s[j+i]!=s[j+2*i]:
                  ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
# 1<=i<j<k<=n
# j-i!=k-j
# si!=sj, sj!=sk, si!=sk
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]:
            continue
        ans+=len(s[j+1:].replace(s[i],'').replace(s[j],''))
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1
print(ans)

Fixed submission:
n=int(input())
s=input()
nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
for i in range(1,1+(n-1)//2):
      for j in range(n-2*i):
            if s[j]!=s[j+i] and s[j]!=s[2*i+j] and s[j+i]!=s[j+2*i]:
                  ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
"""
"""
n,x,y=map(int,input().split())
k_mins=[]
for i in range(1,n):
    for j in range(i+1,n+1):
        k_mins.append(min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)))
ret=[]
k_mins.sort(reverse=True)
for i in range(1,n):
    c=0
    while len(k_mins) > 0 and k_mins[len(k_mins)-1]==i:
        k_mins.pop() 
        c+=1
    ret.append(c)
for r in ret:
    print(r)




Fixed submission:
"""
"""
n,x,y=map(int,input().split())
ret=[0]*(n-1)
for i in range(1,n):
    for j in range(i+1,n+1):
        ret[min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))-1]+=1
for r in ret:
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
"""
"""
n,x,y=map(int,input().split())
k_mins=[]
for i in range(1,n):
    for j in range(i+1,n+1):
        k_mins.append(min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)))

ret=[]
for i in range(1,n):
    #[i for i in l if not i % 2 == 0]
    ret.append(len([ki for ki in k_mins if ki == i]))
for r in ret:
    print(r)




Fixed submission:
"""
"""
n,x,y=map(int,input().split())
ret=[0]*(n-1)
for i in range(1,n):
    for j in range(i+1,n+1):
        ret[min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))-1]+=1
for r in ret:
    print(r)
Buggy python submission (verdict: Time Limit Exceeded):
#n,x,y=map(int,input())
# Queue

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()
q.sort()
p=p[a-x:]
q=q[b-y:]
r.sort()
for ri in r:
    if ri > p[0] and q[0] >= p[0]:
        p[0] = ri
        p.sort()
        continue
    if ri > q[0] and p[0] >= q[0]:
        q[0]=ri
        q.sort()
print(sum(p)+sum(q))

"""
1 2 2 2 1
2 4
5 1
3
->12
2 2 2 2 2
8 6
9 1
2 1
->25
"""



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)
p=p[:x]
q=q[:y]
p[x:x]=q
p[x+y:x+y]=r
p.sort(reverse=True)
p=p[:x+y]
print(sum(p))

Buggy python submission (verdict: Runtime Error):
#n,x,y=map(int,input())
# Queue
from collections import deque

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()
q.sort()
p=deque(p[a-x:])
q=deque(q[b-y:])
r.sort()
for ri in r:
    if ri > p[0] and q[0] >= p[0]:
        p.popleft()
        p.append(ri)
        p.sort()
        continue
    if ri > q[0] and p[0] >= q[0]:
        q.popleft()
        q.sort()
        q.append(ri)
print(sum(p)+sum(q))

"""
1 2 2 2 1
2 4
5 1
3
->12
2 2 2 2 2
8 6
9 1
2 1
->25
"""



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)
p=p[:x]
q=q[:y]
p[x:x]=q
p[x+y:x+y]=r
p.sort(reverse=True)
p=p[:x+y]
print(sum(p))