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

########### E
H, W, M = map(int, input().split())
bombs = []
for _ in range(M):
    bomb = list(map(int, input().split()))
    bombs.append(bomb)

H_list = [0]*H
W_list = [0]*W
sign = True
for i in range(M):
    H_list[bombs[i][0]-1] += 1
    W_list[bombs[i][1]-1] += 1

max_H = [i for i,k in enumerate(H_list) if k == max(H_list)]
max_W = [i for i,k in enumerate(W_list) if k == max(W_list)]

cross = []

for i in max_H:
    for k in max_W:
        if [i+1,k+1] not in bombs:
            sign = False
            print(max(H_list) + max(W_list))
            break
    break

if sign:
    print(max(H_list) + max(W_list) -1)


### FIXED CODE ###

import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H  # X:各行の爆破対象の個数
Y = [0] * W  # Y:各列の爆破対象の個数
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY]  # C:爆破対象の数が最大となる列の番号

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため, 
            # 即座に探索を終了する. これによりループの回数は最大でもM+1回となる.
            print(maxX + maxY)
            exit()
print(maxX + maxY - 1)
### BUGGY CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def main():
    K = int(input())
    s = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                s += gcd(i, j, k)
    print(s)
if __name__ == "__main__":
    main()

### FIXED CODE ###

import math
from functools import reduce
def main():
    K = int(input())
    s = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                s += math.gcd(math.gcd(i, j), k)
    print(s)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

def combs_mod(n,k,mod):
  #nC0からnCkまで
  inv = [1]*(k+1)
  for i in range(1,k+1):
    inv[i] = pow(i,mod-2,mod)
  ans = [1]*(k+1)
  for i in range(1,k+1):
    ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
  return ans
def solve():
  mod = 998244353
  N, K = map(int, input().split())
  ans = 0
  if K<N:
    return ans
  com = combs_mod(K,K,mod)
  com2 = combs_mod(K-1,K-1,mod)
  for r in range(K+1):
    b = K-r
    dif = r-b
    if dif<0 or r<N:
      continue
    elif dif==0:
      ans += com2[r]
      if N>=2:
        ans -= com2[N-2]
    elif dif<N:
      ans += com[r] - com[N-1-dif]
    else:
      ans += com[r]
    ans %= mod
  return ans
print(solve())

### FIXED CODE ###

def combs_mod(n,k,mod):
  #nC0からnCkまで
  inv = [1]*(k+1)
  for i in range(1,k+1):
    inv[i] = pow(i,mod-2,mod)
  ans = [1]*(k+1)
  for i in range(1,k+1):
    ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
  return ans
def solve():
  mod = 998244353
  N, K = map(int, input().split())
  ans = 0
  if K<N:
    return ans
  com = combs_mod(K,K,mod)
  com2 = combs_mod(K-1,K-1,mod)
  for r in range(K+1):
    b = K-r
    dif = r-b
    if dif<0 or r<N:
      continue
    elif dif==0:
      ans += com2[r]
      if N>=2:
        ans -= com2[N-2]
    elif dif<N:
      ans += com[r] - com[N-1-dif]
    else:
      ans += com[r]
    ans %= mod
  return ans
print(solve())
### BUGGY CODE ###

import numpy as np
import itertools as it

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

sum1 = 0
for i in range(n - 1):
    #print(a[i + 1:], a[i])
    #print(sum(a[i + 1:]))
    sum1 += a[i] * sum(a[i + 1:])
if sum1 >= 10 ** 9 + 7:
    sum1 = sum1 % (10 ** 9 + 7)

print(sum1)

# sum = 0
# for i in range(n):
#     sum += 1 / a[i]
#print(sum)

# ans = int(sum * np.prod(a))
# print(ans % (10 ** 9 + 7))


### FIXED CODE ###

# import numpy as np
# import itertools as it

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

res = 0
for i in range(n):
    res += a[i] * a[i]

ans = sum(a) * sum(a)
print(((ans - res)//2) % (10 ** 9 + 7))


# sum = 0
# for i in range(n):
#     sum += 1 / a[i]
#print(sum)

# ans = int(sum * np.prod(a))
# print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

import bisect

n, m=map(int, input().split())
a=[int(n) for n in input().split()]
ans=0
a.sort()
for i in range(m):
  num=a.pop()//2
  a.insert(bisect.bisect_left(a,num),num)
print(sum(a))

### FIXED CODE ###

import heapq

n, m=map(int, input().split())
a=[-1*int(n) for n in input().split()]
heapq.heapify(a)

for i in range(m):
  num=-1*(-1*heapq.heappop(a)//2)
  heapq.heappush(a,num)

print(-1*sum(a))
### BUGGY CODE ###

s = input()
q = int(input())
lst = []
for i in range(q):
    lst.insert(0, input().split())

counter = 0
while len(lst) != 0:
    x = lst.pop()
    if str(x[0]) == '1':
        counter += 1

    else:
        if counter % 2 != 0:
            s = s[::-1]
            counter = 0
        if str(x[1]) == '1':
            s = str(x[2]) + s

        else:
            s = s + str(x[2])

if counter % 2 != 0:
    s = s[::-1]
print(s)


### FIXED CODE ###

s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
b = []
for i in range(q):
    a = list(map(int,input().split()))
    b.append(str(s[a[0]-1:a[1]].count("AC")))
    b.append("\n")
print("".join(b))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

import numpy as np

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

def combi(n):
    return n*(n-1)//2

"""
for i in range(n):
    count = a.count(i+1)
    count_all += combi(count)
"""
count_all = sum([combi(a.count(i+1)) for i in range(n)])
"""
for k in range(n):
    #aのk番目の要素と同じ要素の数を(k番目の要素も含めて)出し、1を引く
    count = a.count(a[k]) - 1
    ans = count_all - count
    print(ans)
"""
count = [a.count(a[k]) - 1 for k in range(n)]
x = np.array([count_all]*n)
y = np.array(count)
ans = x-y
for s in ans.tolist():
    print(s)


### FIXED CODE ###

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

num_list=[0]*n
for i in range(n):
    num_list[a[i]-1]+=1

sm_all=0
for i in range(n):
    k=num_list[i]
    sm_all+=(k*(k-1))//2

for i in range(n):
    print(sm_all-(num_list[a[i]-1]-1))
### BUGGY CODE ###

import math
import calendar
import fractions
import itertools

n = int(input())

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

for i in range(n):
    c = x[:i] + x[i + 1:]
    c.sort()
    print(c[len(c) // 2])





### FIXED CODE ###

import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
x = list(map(int, input().split()))
y = sorted(x)
a = y[n // 2 - 1]
b = y[n // 2]
# print("a =", a)
# print("b =", b)
for i in x:
    if i <= a:
        print(b)
    else:
        print(a)
### BUGGY CODE ###

S = input()
ans = 0
if int(S) < 2019:
  print(ans)
else:
  for i in range(len(S)-4):
    for j in range(4, len(S)-i+1):
      T = S[i:i+j]
      N = int(T)
      if N % 2019 == 0:
        ans += 1
  print(ans)


### FIXED CODE ###

s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0

while len(a) >= 1:
  ans += 1
  temp=a.pop(0)
  if len(a) >= 1:
    if a[0] == temp:
      ans -= 1
    a = list(filter(lambda x: x % temp != 0, a))
  
print(ans)

### FIXED CODE ###

n = int(input())
a  = list(map(int, input().split()))
a.sort()
dp = [0]*a[n-1]
ans = 0
temp2 = 0
for i in range(n):
  if temp2 == a[i]:
    ans -= 1
    temp2=0
  if dp[a[i]-1] == 0:
    ans += 1
    temp = a[i]
    temp2 = a[i]
    while temp <= a[n-1]:
      dp[temp-1] = 1
      temp = temp+a[i]
  #print(dp)    
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
INF = 10**18
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

opposite = 0
max_dist = 0
def f(d,x):
  global max_dist,opposite
  dx = d[x]
  if dx > max_dist:
    opposite = x
    max_dist = dx
  for y in edge[x]:
    if d[y] == INF:
      d[y] = dx + 1
      f(d,y)

# 0からの距離
d = [INF] * N
d[0] = 0
f(d,0)

v = opposite
d = [INF] * N
d[v] = 0
f(d,v)

X = max_dist

ans = 'First' if max_dist%3 != 1 else 'Second'
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
# グラフの最長経路が-1か-2かを選べる
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)


def f(x):
  opposite = 0
  max_dist = 0
  # 最離点と距離とを返す
  d = [None]*N
  q = [(x,0)]
  while q:
    x,dx = q.pop()
    d[x] = dx
    if dx > max_dist:
      max_dist = dx
      opposite = x
    for y in edge[x]:
      if d[y] is None:
        q.append((y,dx+1))
  return opposite,max_dist

if N != 1:
  # 0からの距離
  v,_ = f(0)
  _,max_dist = f(v)

  ans = 'First' if max_dist%3 != 1 else 'Second'
  print(ans)
else:
  print('First')
### BUGGY CODE ###

n = input()
list = [int(i) for i in input().split()]
count = 0
flg = False

while True:
    for num in list:
        if num % 2 != 0:
            flg = True
            break
    if flg:
        break
    else:
        #奇数がなければリスト丸ごと半分にする
        count += 1
        list = map(lambda x: x / 2, list)
print(count)

### FIXED CODE ###

n = input()
list = [int(i) for i in input().split()]
min_count = 1000000000
tmp = 0

for num in list:
    tmp = 0
    while True:
        if num % 2 != 0:
          break
        else:
          tmp += 1
          num = num / 2
    if min_count > tmp:
        min_count = tmp  
          
print(min_count)
### BUGGY CODE ###

from collections import defaultdict
n, m = list(map(int, input().split()))
d1 = defaultdict(set)
for i in range(m):
  u, v = list(map(int, input().split()))
  d1[u].add(v)
s, t = list(map(int, input().split()))
d2 = defaultdict(set)

def dfs (x, nx, cnt, visited):
  if nx in visited:
    return
  if cnt==3:
    d2[x].add(nx)
  elif cnt>3:
    return

  for nnx in d1[nx]:
    dfs(x, nnx, cnt+1, visited)
  visited.add(nx)

for i in range(1, n+1):
  visited = set()
  dfs(i, i, 0, visited)
  visited.add(i)

def bfs():
  que = [(s, 0)]
  visited = set()

  while len(que) > 0:
    p = que.pop(0)
    if p[0]==t:
      return p[1]
    for nx in d2[p[0]]:
      if nx in visited:
        continue
      visited.add(nx)
      que.append((nx, p[1]+1))
  return -1

print(bfs())

### FIXED CODE ###

from collections import defaultdict, deque
n, m = list(map(int, input().split()))
graph = defaultdict(list)
for i in range(m):
  u, v = list(map(int, input().split()))
  graph[u].append(v+n)
  graph[u+n].append(v+2*n)
  graph[u+2*n].append(v)
s, t = list(map(int, input().split()))
dist = [-1 for i in range(3*n+10)]

def bfs():
  que = deque([s])
  dist[s] = 0
  while len(que) > 0:
    cur = que.popleft()
    for to in graph[cur]:
      if dist[to] == -1:
        dist[to] = dist[cur]+1
        que.append(to)

bfs()
print(dist[t]//3)
### BUGGY CODE ###

import copy
N, Q = map(int, input().split())
s = str(input())
TD = [list(map(str, input().split())) for i in range(Q)]

# どんどん合体していくことだけはわかった
hash = {}
for i in range(N):
    if s[i] in hash.keys():
        hash[s[i]].append(i)
    else:
        hash[s[i]] = [i]

for t, d in TD:
    if t not in hash.keys():
        continue
    if d == 'R':
        r_list = map(lambda x: x+1, hash[t])
        hash[t] = []
        for r in r_list:
            if 0 <= r <= N-1:
                hash[s[r]].append(r)
    else:
        l_list = map(lambda x: x-1, hash[t])
        hash[t] = []
        for l in l_list:
            if 0 <= l <= N - 1:
                hash[s[l]].append(l)

ans = 0
for d in hash.values():
    ans += len(d)
print(ans)

### FIXED CODE ###

N, Q = map(int, input().split())
S = str(input())
TD = [list(map(str, input().split())) for i in range(Q)]


def disappear(index, place):
    if index == -1:
        return (False, False)
    else:
        left = False
        right = False
        for t, d in TD:
            cur_chara = place[index]
            if t == cur_chara:
                if d == 'R':
                    index += 1
                else:
                    index -= 1
                if index < 0:
                    left = True
                    break
                elif index > N-1:
                    right = True
                    break
        return (left, right)


def binarySearch(place, direction):
    """
    :param direction; left, right
    :return: 消失する位置
    """
    start, end = -1, N
    if direction == 'left':
        while end - start > 1:
            t = start + (end - start) // 2
            if disappear(t, place)[0]:
                start = t
            else:
                end = t
        return start
    elif direction == 'right':
        while end - start > 1:
            t = start + (end - start) // 2
            if disappear(t, place)[1]:
                end = t
            else:
                start = t
        return start


left = binarySearch(S, direction='left')
right = binarySearch(S, direction='right')
print(right - left)
### BUGGY CODE ###

l, r = map(int, input().split())
ans = []
for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
        ans.append((i * j) % 2019)
print(min(ans))

### FIXED CODE ###

import sys
l, r = map(int, input().split())
ans = []
for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
        ans.append((i * j) % 2019)
        if (i * j) % 2019 == 0:
            print(0)
            sys.exit()
print(min(ans))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Alist=[]
for i in range(N):
    Alist.append(A.index(i+1)+1)

print(" ".join(map(str,Alist)))


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Alist=[]
for i in range(N):
    Alist.append([A[i],i+1])

Alist.sort()

for i in range(N):
    print(Alist[i][1],end=" ")
### BUGGY CODE ###

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

get_ints = lambda: [int(st) for st in input().split()]
N=int(input())
inarr=get_ints()

sorted_in = sorted(inarr)
comb = N * (N-1) // 2

def binsearch(lft, rgt):
    half = (lft + rgt) // 2
    # print(lft, rgt, sorted_in[half])
    if lft >= half:
        return lft
    summed = 0
    res = 0

    bit = Bit(2*N+1)
    for i, x in enumerate(inarr):
        value = -1 if x < sorted_in[half] else 1
        summed += value
        # print("summed: {}, bit: {}".format(summed, i - bit.sum(N + summed)))
        count = i - bit.sum(N + summed)
        bit.add(N + summed, 1)
        res += count

    # print(res)
    if res <= (comb // 2):
        return binsearch(half, rgt)
    else:
        return binsearch(lft, half)

# print(sorted_in)
res = binsearch(0, N)
# print(res, sorted_in[res])
print(sorted_in[res])


### FIXED CODE ###

import math
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

get_ints = lambda: [int(st) for st in input().split()]
N=int(input())
inarr=get_ints()

sorted_in = sorted(inarr)
# print(sorted_in)
comb = N*(N+1) // 2

def binsearch(lft, rgt):
    half = (lft + rgt) // 2
    # print("investigate: lft {} rgt {} half {} value {}".format(lft, rgt, half, sorted_in[half]))
    if lft >= half:
        return half
    summed = 0
    res = 0

    bit = Bit(2*N+1)
    bit.add(N, 1)
    for i, x in enumerate(inarr):
        value = 1 if x >= sorted_in[half] else -1
        summed += value
        # print("summed: {}, bit: {}".format(summed, bit.sum(N + summed)))
        count = bit.sum(N + summed)
        bit.add(N + summed, 1)
        res += count

    # print("num {} cnt {} judge {}".format(sorted_in[half], res, math.ceil(comb/2)))
    if res >= math.ceil(comb/2):
        return binsearch(half, rgt)
    else:
        return binsearch(lft, half)

# print(sorted_in)
res = binsearch(0, N)
# print(res, sorted_in[res])
print(sorted_in[res])
### BUGGY CODE ###

N, W = map(int, input().split())
w = [0]
v = [0]

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for col in range(W+1)] for row in range(N+1)]

#dp[i][j] = i番目までのお菓子の中から，ナップサックの中のお菓子の重さの総和がjを超えないようにいくつかお菓子を選んで詰めるとき，価値の最大値

for i in range(1, N+1):
    for j in range(1, W+1):
        if j - w[i] >= 0: #ex.ナップサックの耐加重がj=100,で, i番目のお菓子の重さが20である場合，ナップサックに追加することができるのは，i-1番目までのお菓子でまだ80以下の重さしかないとき。
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])

### FIXED CODE ###

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

w = [0]
v = [0]

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[float('inf') for a in range(110000)] for b in range(N+1)]
dp[0][0] = 0

ans = 0

for i in range(1, N+1):
    for j in range(110000):
        if j - v[i] >= 0:
            dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i])

        dp[i][j] = min(dp[i][j], dp[i-1][j])

        if dp[i][j] <= W and j > ans:
            ans = j

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

n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
di[0] = abs(ls[0])
di[-1] = abs(ls[-1])
for i in range(1,n):
    di[i] = abs(ls[i] - ls[i-1])
for j in range(n):
    if j == 0:
        if (ls[j])*(ls[j+1]-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))
    elif j == n-1:
        if (ls[j]-ls[j-1])*(-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))
    else:
        if (ls[j]-ls[j-1])*(ls[j+1]-ls[j]) < 0:
            print(sum(di)-di[j]-di[j+1]+max(di[j],di[j+1])-min(di[j],di[j+1]))
        else:
            print(sum(di))

### FIXED CODE ###

n = int(input())
ls = list(map(int,input().split()))
di = [0]*(n+1)
ls = [0] + ls + [0]
for i in range(n+1):
    di[i] = abs(ls[i+1] - ls[i])
mx = sum(di)
for j in range(1,n+1):
    print(mx-di[j-1]-di[j]+abs(ls[j+1]-ls[j-1]))
### BUGGY CODE ###

import copy

H, W = map(int, input().split())
#dist_matrix = [[10000] * W for i in range(H)]
black_h_list = []
black_w_list = []
for i in range(H):
  line_list = list(input())
  for j in range(W):
    if line_list[j] == "#":  
      black_h_list.append(i)
      black_w_list.append(j)

#print(black_h_list)
#print(black_w_list)

max_value = 0
for i in range(H):
  for j in range(W):
    min_dist = H+W+2
    for k in range(len(black_h_list)):
      dist = abs(i-black_h_list[k]) + abs(j-black_w_list[k])
      if max_value >= dist:
        min_dist = dist
        break
      elif min_dist > dist:
        min_dist = dist        
    #dist_matrix[i][j] = min_dist
    if max_value < min_dist:
      max_value = min_dist

#print(dist_matrix)
    
print(max_value)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
 
H, W = map(int, input().split())
mark_matrix = [[True]*(W+2)]
#mark_matrix.extend([[True]+[False]*(W)+[True] for _ in range(H)])
mark_matrix.extend([[True]+[x!='.' for x in input()] for _ in range(H)])
mark_matrix[H].append(True)
mark_matrix.append([True]*(W+2))
#queue = []
queue = deque()
for i in range(1,H+1):
  for j in range(1,W+1):
    if mark_matrix[i][j]:
      queue.append((i,j))
#  line = input()
#  for j,ch in enumerate(line):
#    if ch == "#":
#      mark_matrix[i+1][j+1] = True
#      queue.append((i+1,j+1))
#for i in range(1,H+1):
#  mark_matrix[i][0] = True
#  mark_matrix[i][W+1] = True
#for j in range(W+2):
#  mark_matrix[0][j] = True
#  mark_matrix[H+1][j] = True
#print(mark_matrix)
 
#cnt = 0
#print(queue)
max_value = 0
while(True):
  #print(len(queue))
  if len(queue) == 0:
    break
  
  new_queue = deque()
  for i,j in queue:
  
    if not mark_matrix[i-1][j]:
      mark_matrix[i-1][j] = True
      #queue.append((i-1,j))
      new_queue.append((i-1,j))
    if not mark_matrix[i+1][j]:
      mark_matrix[i+1][j] = True
      #queue.append((i+1,j))
      new_queue.append((i+1,j))
    if not mark_matrix[i][j-1]:
      mark_matrix[i][j-1] = True
      #queue.append((i,j-1))
      new_queue.append((i,j-1))
    if not mark_matrix[i][j+1]:
      mark_matrix[i][j+1] = True
      #queue.append((i,j+1))
      new_queue.append((i,j+1))
 
  if len(new_queue) == 0:
    break
  else:
    queue = new_queue
    max_value += 1
  
#print(cnt)
#print(dist_matrix)
print(max_value)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**10
MAX_LEN = 2*10**4

h, n = [int(item) for item in input().split()]
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
dp = [INF] * (MAX_LEN * (n + 1))
dp[0] = 0
for i in range(1, n+1):
    v, w = ab[i-1]
    for j in range(MAX_LEN):
        if j < v:
            dp[i*MAX_LEN+j] = dp[(i-1)*MAX_LEN+j]
        elif dp[(i-1)*MAX_LEN+j] > dp[i*MAX_LEN + j-v] + w:
            dp[i*MAX_LEN+j] = dp[i*MAX_LEN+j-v] + w
        else:
            dp[i*MAX_LEN+j] = dp[(i-1)*MAX_LEN+j]
ans = min(dp[n*(MAX_LEN) + h:])
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**9

def main(): 
    h, n = [int(item) for item in input().split()]
    MAX_LEN = h + 10**4 - 2
    dp = [INF] * MAX_LEN
    dp[0] = 0
    vw = []
    for _ in range(n):
        v, w = map(int, input().split())
        vw.append((v, w))
    vw.sort(reverse=True, key=lambda x:x[0])
    for v, w in vw:
        for j in range(h):
            if dp[j] == INF:
                continue
            tmp = dp[j] + w
            if tmp < dp[j+v]:
                dp[j+v] = tmp
    print(min(dp[h:]))

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

X, Y, A, B, C = map(int, input().split())
p = [int(a) for a in input().split()]
q = [int(a) for a in input().split()]
r = [int(a) for a in input().split()]
s = []

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

for i in range(X):
    s.append(p.pop(0))
for i in range(Y):
    s.append(q.pop(0))
s.sort()
for i in range(C):
    if(s[0] < r[0]):
        s[0] = r.pop(0)
        s.sort()
        
print(sum(s))

### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
p = [int(a) for a in input().split()]
q = [int(a) for a in input().split()]
r = [int(a) for a in input().split()]
s = []

p.sort(reverse=True)
q.sort(reverse=True)

p = p[:X]
q = q[:Y]
s = p + q + r
s.sort(reverse=True)

s = s[:(X + Y)]
        
print(sum(s))