Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
c=[[abs(a[i][j]-b[i][j])for j in range(w)]for i in range(h)]
d=[[set()for i in range(w+1)]for j in range(h+1)]
d[1][1]=set([-c[0][0],c[0][0]])
for x in range(1,h+1):
    for y in range(1,w+1):
        if not (x==1 and y==1):
            a=d[x-1][y]|d[x][y-1]
            for i in a:
                d[x][y].add(i-c[x-1][y-1])
                d[x][y].add(i+c[x-1][y-1])
print(abs(min(d[h][w],key=abs)))

### FIXED CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
s=[0]*w
s[0]=p=1<<6400
for i in range(h):
    for j in range(w):
        d=abs(a[i][j]-b[i][j])
        if j>0:
            s[j]|=s[j-1]
        s[j]=(s[j]<<d)|(s[j]>>d)
t=s[-1]
for i in range(6401):
    if t&(p<<i) or t&(p>>i):
        print(i)
        break
### BUGGY CODE ###

from bisect import bisect_left, insort_left
from collections import deque
import sys
def main():
	readlines = sys.stdin.readline
	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()
	r.sort(reverse=True)

	p = p[a-x:]
	q = q[b-y:]
	ans = sum(p) + sum(q)
	p_count = 0
	q_count = 0

	for i in range(c):
		if p[p_count] < r[i] and q[q_count] < r[i]:
			if p[p_count] < q[q_count]:
				ans -= p[p_count]
				ans += r[i]
				insort_left(p,r[i])
				p_count += 1
			else:
				ans -= q[q_count]
				ans += r[i]
				insort_left(q,r[i])
				q_count += 1
		elif p[p_count] < r[i]:
			ans -= p[p_count]
			ans += r[i]
			insort_left(p,r[i])
			p_count += 1
		elif q[q_count] < r[i]:
			ans -= q[q_count]
			ans += r[i]
			insort_left(q,r[i])
			q_count += 1
		else:
			break

	print(ans)
if __name__ == '__main__':
	main()

### FIXED CODE ###

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()
r.sort(reverse=True)

p = p[a-x:]
q = q[b-y:]

p.extend(q)
p.sort()

ans = sum(p)
count = 0
for i in range(c):
	if p[i] < r[i]:
		ans += r[i] - p[i]
	else:
		break
print(ans)
### BUGGY CODE ###

N = int(input())
S = str(input())
ans = 0

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

### FIXED CODE ###

N = int(input())
S = str(input())
r = 0
g = 0
b = 0
#S[i],S[j],S[k]が違うものはr*g*b通り
for i in range(N):
  if S[i] == 'R':
    r += 1
  elif S[i] == 'G':
    g += 1
  else:
    b += 1
tot = r*g*b
#S[i],S[j],S[k]が違うかつj-i=k-jを満たすものは引く
minus = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if 2*j-i < N:
      
      if S[i] != S[j] and S[j] != S[2*j-i] and S[i] != S[2*j-i]:
        minus += 1
print(tot - minus)
### BUGGY CODE ###

N = int(input())
a = [int(i) for i in input().split(" ")]
a_sum = sum(a)
ans = 100000000000

for i in range(1,N):
    x = sum(a[0:i])
    y = a_sum - x
    tmp = abs(x-y)
    if ans >= tmp :
        ans = tmp
print(ans)


### FIXED CODE ###

N = int(input())
a = [int(i) for i in input().split(" ")]
a_sum = sum(a)
ans = 100000000000
x = a[0]
y = a_sum - x
if N == 2:
    print(abs(x-y))
else:
    ans = abs(x-y)
    for i in range(1,N-1):
        x += a[i]
        y -= a[i]
        tmp = abs(x-y)
        if ans >= tmp :
            ans = tmp
    print(ans)
### BUGGY CODE ###

import math
X = int(input())

for a in range(1, 10000):
    for b in range(-1, 10000):
        an = (a-b)*((a**4) + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4)

        if an == X:
            print(a, b)
            exit()


### FIXED CODE ###

import math
X = int(input())

for a in range(1, 1500):
    a4 = a**4
    a3 = a**3
    a2 = a**2
    for b in range(-1500, 1500):
        an = (a-b)*(a4 + (a3)*b + (a2)*(b**2) + a*(b**3) + b**4)
        if an < 0:
            break

        if an == X:
            print(a, b)
            exit()
### BUGGY CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
if n-1 <= k:
    print(abs(h[-1]-h[0]))
else:
    for i in range(1,k+1):
        dp[i] = abs(h[i]-h[0])
    for i in range(k+1,n): 
        for j in range(1,k+1):
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
    print(dp[-1])

### FIXED CODE ###

import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,W = map(int,input().split())

w = [0 for i in range(N)]
v = [0 for i in range(N)]
for i in range(N):
    w[i],v[i] = map(int,input().split())

dp = [[0 for i in range(W+1)] for j in range(N)]


for i in range(N):
    if N < w[i]:
        pass
    else:
        dp[i][w[i]] = v[i]
    for j in range(W+1):
        if i-1 >= 0:
            dp[i][j] = max(dp[i][j],dp[i-1][j])
        if j-w[i] >= 0:
            dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i])

print(max(dp[-1]))


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N,W = map(int,input().split())

w = [0 for i in range(N)]
v = [0 for i in range(N)]
for i in range(N):
    w[i],v[i] = map(int,input().split())

w_sum = [0 for i in range(N+1)]
v_sum = [0 for i in range(N+1)]

w.insert(0,0)
v.insert(0,0)

for i in range(N):
    w_sum[i+1] = w_sum[i]+w[i+1]
    v_sum[i+1] = v_sum[i]+v[i+1]


nap_memo = {}

def nap(i,W2):#i:count_pieces,W2:rest_weight
    key = str(i)+":"+str(W2)
    if key in nap_memo:
        return nap_memo[key]
    elif i == 0:#品物０個の時は価値０
        r = 0
    elif W2 < w[0]:
        r = 0
    elif W2 < w[i]:#i番目の荷物が残量を超えるなら入らない
        r = nap(i-1,W2)
    elif w_sum[i] <= W2:
        r = v_sum[i]
    else:
        r = max(nap(i-1,W2-w[i])+v[i], nap(i-1,W2))

    nap_memo[key] = r
    return r


print(nap(N,W))
#
# dp = [[[0 for i in range(W+1)] for j in range(N)]
#
#
# for i in range(N):
#     if N < w[i]:
#         pass
#     else:
#         dp[i][w[i]] = v[i]
#     for j in range(W+1):
#         if i-1 >= 0:
#             dp[i][j] = max(dp[i][j],dp[i-1][j])
#         if j-w[i] >= 0:
#             dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i])
#
# print(max(dp[-1]))
### BUGGY CODE ###

#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    print(0)
    g = {'Vacant':0, 'Male':1, 'Female':2}
    a = top = g[input()]
    i = 1
    while True:
        print(i)
        a = g[input()]
        if a == 0:
            return
        if a != top:
            i *= 2
        else:
            l = i //2 + 1
            r = i
            while a != top:
                print((l+r)//2)
                a = g[input()]
                if a == 0:
                    return




if __name__ == '__main__':
    main()

### FIXED CODE ###

#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    g = {'Vacant':0, 'Male':1, 'Female':2}



    print(0,flush=True)
    sl = g[input()]
    if sl == 0:
        return

    print(N-1,flush=True)
    sr = g[input()]
    if sr == 0:
        return
    
    l = 0
    r = N-1
    while r-l>1:

        m = (l+r)//2
        print(m,flush=True)
        a = g[input()]
        if a == 0:
            return
        
        if (m-l) % 2 == 1:
            if sl == a:
                r = m
                sr = a
            else:
                l = m
                sl = a

        else:
            if a != sl:
                r = m
                sr = a
            else:
                l = m
                sl = a
        

    print(-1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

#C問題
N=int(input())
A=list(map(int,input().split()))
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
MAX=0
kari=0
for i in range(N):
    B=A[::]
    del B[i]
    kari=gcdlist(B)
    MAX=max(MAX,kari)
if N == 2:
    MA=max(A)
    g=gcd(A[0],A[1])
    MAX=max(MA,g)
print(MAX)
    

### FIXED CODE ###

#C問題
N=int(input())
A=list(map(int,input().split()))
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
MAX=0
kari=0
gcdf=[]
for i in range(N):
    if i == 0:
        gcdf.append(A[i])
    else:
        gcdf.append(gcd(A[i],gcdf[-1]))
gcdb=[]
for i in range(N):
    if i == 0:
        gcdb.append(A[-1])
    else:
        gcdb.append(gcd(A[-1-i],gcdb[-1]))
MAX=0
gcdb=gcdb[::-1]
for i in range(N):
    if i == 0:
        kari=gcdb[1]
    elif i == N-1:
        kari=gcdf[-2]
    else:
        f=gcdf[i-1]
        b=gcdb[i+1]
        kari=gcd(f,b)
    MAX=max(kari,MAX)
print(MAX)
### BUGGY CODE ###

import numpy as np

n, m = map(int, input().split())
adj = np.zeros((n, n), dtype=np.bool)
for _ in range(m):
  s, t = map(int, input().split())
  adj[s-1, t-1] = True
deg = adj.sum(axis=1)

dp = np.zeros(n, dtype=np.float)
for i in range(n - 2, -1, -1):
  dp[i] = dp[adj[i]].mean() + 1.
  
ans = dp[0]

for i in np.where(deg > 1)[0]:
  dp_i = dp.copy()
  dp_i[i] = (dp_i[adj[i]].sum() - dp_i[adj[i]].max()) / (deg[i] - 1) + 1.
  for j in range(i - 1, -1, -1):
    dp_i[j] = dp_i[adj[j]].mean() + 1.
  ans = np.minimum(ans, dp_i[0])
    
print(ans)

### FIXED CODE ###

import numpy as np

n, m = map(int, input().split())
adj = np.zeros((n, n), dtype=np.bool)
for _ in range(m):
  s, t = map(int, input().split())
  adj[s-1, t-1] = True
deg = adj.sum(axis=1)

ev = np.zeros(n, dtype=np.float)
for i in range(n - 2, -1, -1):
  ev[i] = ev[adj[i]].mean() + 1.

prob = np.zeros(n, dtype=np.float)
prob[0] = 1.
for i in range(n - 1):
  prob[adj[i]] += prob[i] / deg[i]

decrease = 0.
for i in np.where(deg > 1)[0]:
  now = ev[adj[i]].mean()
  cut = (ev[adj[i]].sum() - ev[adj[i]].max()) / (deg[i] - 1)
  decrease = np.maximum(decrease, (now - cut) * prob[i])
    
print(ev[0] - decrease)
### BUGGY CODE ###

def binary_search(target, left, right, nums):
    if(left > right):
        return -1
    mid = (right-left)//2 + left
    if(nums[mid] == target):
        return mid
    elif(nums[mid] < target):
        return binary_search(target, mid+1, right, nums)
    else:
        return binary_search(target, left, mid-1, nums)
def Main(N, S):
    ans = 0
    d = {'R':[], 'G':[], 'B':[]}
    for i, c in enumerate(S):
        d[c].append(i)
    #print(d)
    lenb = len(d['B'])
    for i in d['R']:
        for j in d['G']:
            for k in d['B']:
                if abs(j-i) != abs(k-j) and abs(j-i) != abs(k-i) and abs(k-j) != abs(i-k):
                    ans += 1
    return ans
        
    

def main():
    N = int(input())
    S = str(input())
    print(Main(N,S))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np
def Main(N, S):
    num = [0]*3
    for c in S:
        if c == 'R':
            num[0] += 1
        elif c == 'G':
            num[1] += 1
        else:
            num[2] += 1
    ans = np.prod(num)
    sub = 0
    i = 0
    j = 1
    while(i-2 < N):
        while(i+2*j < N):
            a = i
            b = i+j
            c = i+2*j
            if S[a] != S[b] and S[a] != S[c] and S[b] != S[c]:
                sub += 1
            j += 1
        i += 1
        j = 1
    return ans - sub
        
    

def main():
    N = int(input())
    S = str(input())
    print(Main(N,S))

if __name__ == '__main__':
    main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!
N,K=map(int,input().split())

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

for _ in range(K):
    ans=[0]*len(A)
    start=[0]*len(A)
    end=[0]*len(A)
    
    for index,item in enumerate(A):
        start[max(0,index-item)]+=1
        end[min(len(end)-1,index+item)]+=1
    
    #print(start)
    #print(end)
    
    temp=0
    for i in range(len(ans)):
        temp+=start[i]
        ans[i]=temp
        temp-=end[i]
    
    A=ans[:]

print(*ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!
N,K=map(int,input().split())

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


for _ in range(K):
    ans=[0]*len(A)
    start=[0]*len(A)
    end=[0]*len(A)
    
    for index,item in enumerate(A):
        start[max(0,index-item)]+=1
        end[min(len(end)-1,index+item)]+=1
    
    #print(start)
    #print(end)
    
    temp=0
    for i in range(len(ans)):
        temp+=start[i]
        ans[i]=temp
        temp-=end[i]
    
    if A==ans:
        break
    else:
        A=ans[:]

print(*ans)
### BUGGY CODE ###

s = input()
K = int(input())
L = set([])
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        L.add(s[i:j])
print(sorted(L)[K-1])

### FIXED CODE ###

s = input()
K = int(input())
L = set([])
for i in range(len(s)):
    for j in range(i+1,min(i+6,len(s)+1)):
        L.add(s[i:j])
print(sorted(L)[K-1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=[0]*n
for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
def dsf(index,u):
  for i in l[index]:
    if i==u:continue
    ans[i]+=ans[index]
    dsf(i,index)
dsf(0,-1)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
px=[0]*n
for i in range(q):
  p,x=map(int,input().split())
  px[p-1]+=x
ans=[0]*n
def dsf(index,u):
  ans[index]=ans[u]+px[index]
  for i in l[index]:
    if i==u:continue
    dsf(i,index)
dsf(0,-1)
print(*ans)
### BUGGY CODE ###

n, m = map(int, input().split(" "))
a = list(map(int,input().split(" ")))

for i in range(m):
    maxIndex = 0
    for j in range(n):
        if a[maxIndex] < a[j]:
            maxIndex = j
    a[maxIndex] = a[maxIndex] >> 1
print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))    
 
print(-sum(a))
### BUGGY CODE ###

# -*- coding: UTF-8 -*-

n, k, q = map(int, input().split(" "))
a = []
points = []
for i in range(0,n):
  points.append(k)

for s in range(0,q):
  a = int(input()) - 1
  for l in range(0, len(points)):
    if l != a:
      points[l] = points[l]-1

for t in range(0, n):
  result = "Yes"
  if points[t] <= 0:
    result = "No"
  print(result)


### FIXED CODE ###

n, k, q = map(int, input().split(" "))
a = []
points = []
for i in range(0,n):
  points.append(k - q)

for s in range(0,q):
  a = int(input()) - 1
  points[a] = points[a] + 1

for t in range(0, n):
  result = "Yes"
  if points[t] <= 0:
    result = "No"
  print(result)
### BUGGY CODE ###

a=int(input())
b=list(map(int,input().split()))
c=1
for i in range(a):
  c=c*b[i]
if c>10**18:
  print(-1)
else:
  print(c)

### FIXED CODE ###

import numpy as np
a=int(input())
b=list(map(int,input().split()))
c=1
if 0 in b:
    print(0)
    exit()
else:
    for i in range(a):
        c=c*b[i]
        if c>10**18:
            print(-1)
            exit()
        else:
            continue
print(c)
### BUGGY CODE ###

str = [input() for i in range(2)]
nums = list(map(int, str[1].split()))
maxCount = 0

for index, item in enumerate(nums):
    count = 0
    for i in range(len(nums)-index-1):
        if nums[index+i] >= nums[index+i+1]:
            count = count + 1
            if count >= maxCount:
                maxCount = count
        else:
            break
        

print(maxCount)
        


### FIXED CODE ###

str = [input() for i in range(2)]
nums = list(map(int, str[1].split()))
maxCount = 0
index = -1
count = 0

for i in range(len(nums)-1):
    if nums[i] >= nums[i+1]:
        count = count + 1
        if count >= maxCount:
            maxCount = count
    else:
        count = 0
        
print(maxCount)
### BUGGY CODE ###

from collections import deque

n, m = (int(x) for x in input().split())
list_load=[]
for i in range(m):
    a, b = (int(x) for x in input().split())
    list_load.append((a,b))
    list_load.append((b,a))
list_ans=[0]*n

que=deque()
que.append(1)
while que:
    now = que.pop()
    for i in list_load:
        if i[0]==now:
            next=i[1]
            if list_ans[next-1]==0:
                list_ans[next-1]=now
                que.appendleft(next)
bool = True
for i in range(1,n):
    if list_ans[i]==0:
        bool=False
if bool:
    print("Yes")
    for i in range(1,n):
        print(list_ans[i])
else:
    print("No")






### FIXED CODE ###

from collections import deque

n, m = (int(x) for x in input().split())
list_load=[[0] for i in range(n)]
for i in range(m):
    a, b = (int(x) for x in input().split())
    list_load[a-1].append(b)
    list_load[b-1].append(a)
list_ans=[0]*n

que=deque()
que.append(1)
while que:
    now = que.pop()
    for i in list_load[now-1]:
        if i!=0:
            if list_ans[i-1]==0:
                list_ans[i-1]=now
                que.appendleft(i)
bool = True
for i in range(1,n):
    if list_ans[i]==0:
        bool=False
if bool:
    print("Yes")
    for i in range(1,n):
        print(list_ans[i])
else:
    print("No")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
from collections import deque

def bfs(sx,sy,gx,gy):
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
ans=0
memo=[[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            for k in range(i,h):
                for l in range(w):
                    if i==k and j==l:
                        continue
                    elif s[k][l]=='.':
                        ans = max(ans,bfs(i,j,k,l))
                        
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from collections import deque


h,w=map(int,input().split())
s = [list(input()) for i in range(h)]

def bfs(sx,sy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[-1]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==-1 and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j))
print(count)
### BUGGY CODE ###

MOD = 10**9+7

N, M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))

dp=[[1]*(M+1) for i in range(N+1)]
S_index=[set() for i in range(10**5+1)]

for i in range(N):
  S_index[S[i]].add(i)
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    for k in S_index[T[j]]:
      dp[i][j]=(dp[i][j]+dp[k-1][j-1])%MOD
      
print(dp[N-1][M-1])

### FIXED CODE ###

MOD = 10**9+7

N, M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))

dp=[[1]*(M+1) for i in range(N+1)]
S_index=[[] for i in range(10**5+1)]

for i in range(N):
  S_index[S[i]].append(i)
  if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
      
print(dp[N-1][M-1])
### BUGGY CODE ###

def sosucheck(num):
    if num == 1:return False
    flag = True
    for i in range(1, int(num **(1/2))+1):
        if flag:
            flag = False
        else:
            if num % i == 0:
                return False
    return True
Q = int(input())
lis = []
minimam = 10**5
maximam = 1
for _ in range(Q):
    l, r = map(int, input().split())
    lis.append((l, r))
    minimam = min(minimam, l)
    maximam = max(maximam, r)
flag_lis = [0] * (maximam+1)
for num in range(minimam, maximam+1, 2):
    if sosucheck(num) and sosucheck((num+1)/2):
        flag_lis[num] = 1
    else:
        flag_lis[num] = 0
for (l, r) in lis:
    count = 0
    for num in range(l,r+1,2):
        if flag_lis[num]==1:
            count += 1
    print(count)

### FIXED CODE ###

import copy
Q = int(input())
lis = []
maximam = 1
for _ in range(Q):
    l, r = map(int, input().split())
    lis.append((l, r))
    maximam = max(maximam, r)
flag_lis = [1] * (maximam+1)
flag_lis[0] = 0
flag_lis[1] = 0
for i in range(2, int((maximam-1)/2)+1):
    if flag_lis[i] != 0:
        for j in range(2*i,maximam+1,i):
            flag_lis[j] = 0
fin_lis = [0]*(maximam+1)
count = 0
for i in range(3, maximam+1, 2):
    if flag_lis[i] == 1 and flag_lis[int((i+1)/2)] == 1:
        count += 1
    fin_lis[i] = count
for (l, r) in lis:
    if l == 1:
        print(fin_lis[r] - 0)
    else:
        print(fin_lis[r] - fin_lis[l-2])
### BUGGY CODE ###

X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]+[-1]
Q=sorted(list(map(int,input().split())))[::-1]+[-1]
R=sorted(list(map(int,input().split())))[::-1]+[-1]
N=0
ans=0
while 1:
  if P[0]>=Q[0] and P[0]>R[0]:
    ans+=P.pop(0)
    X-=1
    if X+Y==N:
      break
    if X==0:
      P=[-1]
  if Q[0]>=P[0] and Q[0]>=R[0]:
    ans+=Q.pop(0)
    Y-=1
    if X+Y==N:
      break
    if Y==0:
      Q=[-1]
  if R[0]>=P[0] and R[0]>=Q[0]:
    ans+=R.pop(0)
    N+=1
    if X+Y==N:
      break
print(ans)

### FIXED CODE ###

X,Y,A,B,C=map(int,input().split())
import numpy as np
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
Xa=np.array(P+Q+R)
Ya=np.array([i for i,j in enumerate([A,B,C]) for k in range(j)])
x = np.argsort(Xa)
Xa=Xa[x]
Xa=Xa[::-1]
Ya=Ya[x]
Ya=Ya[::-1]
ans=0
N=0
nokori=[X,Y]
for i in range(A+B+C):
  if Ya[i]==2:
    N+=1
    ans+=Xa[i]
  elif nokori[Ya[i]]>0:
    nokori[Ya[i]]-=1
    ans+=Xa[i]
  if sum(nokori)==N:
    break
print(ans)