Harryxun/stf_run huggingface dataset:
while True:
      n, m = map(int, raw_input().split())
      if n == 0 and m == 0:
            break
      p = [ 1 for i in range(n) ]
      pn = n; count = 0
      while pn > 1:
            for i in range(n):
                  if p[i] == 1:
                        count += 1
                        if count == m:
                              p[i] = 0
                              pn -= 1
                              count = 0
      print p.index(1)+1

### FIXED CODE ###

while True:
      n, m = map(int, raw_input().split())
      if n == 0 and m == 0:
            break
      p = [ i+1 for i in range(n) ]
      np = n; a = 0
      while np > 1:
            a = (a+m-1)%len(p)
            p.pop(a)
            np -= 1
      print p[0]
N=int(input())

step = sum([90*100**i for i in range(len(str(N))//2)])
dance_floor = sum([9*100**i for i in range(len(str(N))//2)])

ans = len(str(N))%2 * (N-step)  +  -1*(len(str(N))%2-1) * dance_floor
print(ans)


### FIXED CODE ###

A,B = map(int,input().split())
print("IMPOSSIBLE" if (A+B)%2!=0 else int((A+B)/2))
import sys
import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1

ans = 0
for d1 in range(9):
  for d2 in range(9):
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
return ans
    

### FIXED CODE ###

import sys
from collections import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1
 
ans = 0
for d1 in range(1, 10):
  for d2 in range(1, 10):
    d1, d2 = str(d1), str(d2)
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
print(ans)
n = int(input())
b = list(map(int, input().rstirip().split()))
c = max(b)
d = 0
for i in b:
  d +=i
d -= c
if c < d:
  print(Yes)
else:
  print(No)

### FIXED CODE ###

n = int(input())
b = list(map(int, input().rstrip().split()))
c = max(b)
d = 0
for i in b:
  d +=i
d -= c
if c < d:
  print("Yes")
else:
  print("No")
import sys

A = map(int, sys.argv[1::])
A.sort()
print(A[2] - A[1] + A[1] - A[0])



### FIXED CODE ###

A = map(int, raw_input().split())
A.sort()
print(A[2] - A[1] + A[1] - A[0])
n,m = map(int,input().split())
lst1 = [list(map(int,input().split())) for i in range(m)]

lst2 = [0]*n

for i,j in lst1:
    lst2[i] += 1
    lst2[j] += 1

for i in lst2:
    print(i) 

### FIXED CODE ###

n,m = map(int,input().split())
lst1 = [list(map(int,input().split())) for i in range(m)]

lst2 = [0]*n

for i,j in lst1:
    lst2[i-1] += 1
    lst2[j-1] += 1

for i in lst2:
    print(i)
w = input()

ccount = 0
while True:
    line = input()
    if line == 'END_OF_TEXT':
        break
        
      for s in line.lower().split():
          if s == W:
              count += 1

print()

### FIXED CODE ###

while True:
    s = input()
    if s == '-':
        break

    m = int(input())
    for mi in range(m):
        h = int(input())
        s = s[h:] + s[:h]

    print(s)
import itertools

l,r=map(int, input().split())
lis1 = list(range(l,r+1))
lis2=[]

for v in itertools.combinations(lis1, 2):
      lis2.append(v[0]*v[1]%2019)
    
print(min(lis2))

### FIXED CODE ###

import sys
l,r = map(int,input().split())
a=[]

for i in range(l,r):
	for j in range(i+1,r+1):
		a.append((i*j)%2019)

		if (i*j)%2019 == 0:
			print(0)
			sys.exit()
print(min(a))
while True:
    table = str(input())
    if table[0] == 0:
        break
    print(sum(table))



### FIXED CODE ###

while True:
  x = sum(map(int, input()))

  if x == 0:
    break

  print(x)
from itertools import accumulate
from collections import defaultdict

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A = [0]+[i-1 for i in A]
sumA = list(accumulate(A))
sumA = [i % K for i in sumA]
x = sumA[:K]
modmap = [0]*N
ans = 0
for i in x:
    modmap[i] += 1

for i in range(K):
    t = modmap[i]
    ans += t * (t-1) // 2

for i in range(N-K+1):
    modmap[sumA[K+i]] += 1
    modmap[sumA[i]] -= 1
    ans += modmap[sumA[K+i]]-1

print(ans)

### FIXED CODE ###

import sys
from itertools import accumulate
from collections import defaultdict
input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = [i-1 for i in a]
suma = [0]+list(accumulate(a))
suma = [i%k for i in suma]
rem = defaultdict(int)
ans = 0
if k > n:
    for i in range(n+1):
        x = suma[i]
        rem[x] += 1
    for s in rem.values():
        ans += s*(s-1)//2
    print(ans)
    exit()
for i in range(k):
    x = suma[i]
    rem[x] += 1
for s in rem.values():
    ans += s*(s-1)//2
for i in range(n-k+1):
    rem[suma[i]%k] -= 1
    rem[suma[i+k]%k] += 1
    ans += rem[suma[i+k]] -1
print(ans)
X =int(input())
def f(n):
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True
for i in range(X,100004):
    if f(i):
        return(i)
        break

### FIXED CODE ###

S,T = map(str,input().split())
ans = T + S
print(ans)
H, W = map(int, input().split())
a = []
INF = 10**9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

# 白マスごとに最近傍の黒マスまでの距離を計算
dist_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            continue
        min_dist = INF
        for pos in black_pos:
            dist = abs(pos[0]-i) + abs(pos[1]-j)
            if dist < min_dist:
                min_dist = dist
        dist_list.append(min_dist)

print(max(dist_list))

### FIXED CODE ###

from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)
import sys
import io, os
input = sys.stdin.buffer.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

q = int(input())

import heapq
h1 = []
h2 = []
heapq.heapify(h1)
heapq.heapify(h2)

B = 0
S1 = 0
S2 = 0

for i in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        a, b = query[1], query[2]
        B += b
        if len(h1) == 0:
            heapq.heappush(h1, a*(-1))
            S1 += a
        elif len(h2) == 0:
            x = heapq.heappop(h1)*(-1)
            S1 -= x
            if x <= a:
                heapq.heappush(h1, x*(-1))
                heapq.heappush(h2, a)
                S1 += x
                S2 += a
            else:
                heapq.heappush(h1, a*(-1))
                heapq.heappush(h2, x)
                S1 += a
                S2 += x
        else:
            x = heapq.heappop(h1)*(-1)
            y = heapq.heappop(h2)
            S1 -= x
            S2 -= y
            if a <= y:
                heapq.heappush(h1, x*(-1))
                heapq.heappush(h1, a*(-1))
                heapq.heappush(h2, y)
                S1 += x+a
                S2 += y
            else:
                heapq.heappush(h1, x*(-1))
                heapq.heappush(h1, y*(-1))
                heapq.haeppush(h2, a)
                S1 += x+y
                S2 += a
    else:
        t = h1[0]*(-1)
        ans = t*len(h1)-S1+S2-t*len(h2)+B
        print(t, ans)


### FIXED CODE ###

import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

q = int(input())

import heapq
L = []
R = []
heapq.heapify(L)
heapq.heapify(R)

B = 0

for i in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        a, b = query[1], query[2]
        B += b
        heapq.heappush(L, -a)
        heapq.heappush(R, a)
        if -L[0] > R[0]:
            l = -heapq.heappop(L)
            r = heapq.heappop(R)
            B += l-r
            heapq.heappush(L, -r)
            heapq.heappush(R, l)
    else:
        print(-L[0], B)
n = input()
c1=c2=0
l = len(n)
c1 = n - (len([for i in l[0::2] if n == "0"])) - (len([for i in l[1::2] if n == "1"]))
c2 = n - (len([for i in l[0::2] if n == "1"])) - (len([for i in l[1::2] if n == "0"]))

print(min(c1,c2))

### FIXED CODE ###

a,b = map(int,input().split())
if a==b:
  print(a*2)
else:
  print(max([a,b])*2-1)
N = int(input())
L = map(int, input().split())

L.sort(reverse=True)
max_num = L.pop(0)

if max_num < total(L):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))

L.sort(reverse=True)
max_num = L.pop(0)

if max_num < sum(L):
  print("Yes")
else:
  print("No")
N, M = map(int, input().split())
l = 1
r = N
for i in range(M):
  L, R = map(int, input().split())
  if L < l:
    l = L
  if r < R:
    r = R
if l > r:
  print(0)
else:
  print(r-l+1)

### FIXED CODE ###

A, B = map(int, input().split())
if A >= 13:
  print(B)
elif A <= 5:
  print(0)
else:
  print(B//2)
x = int(input())
a = []
for i in range(-100, 100):
  for j in range(-100, 100):
    if i**5 - j**5 == x:
      a.append([i, j])
      break
      
print(*a[0])

### FIXED CODE ###

x = int(input())
a = []
for i in range(-200, 200):
  for j in range(-200, 200):
    if i**5 - j**5 == x:
      a.append([i, j])
      break
      
print(*a[0])
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(max(temp),max([temp[-1]+temp[i+1] for i in range(K%(len(temp)-1))]))
    ans=max(ans, t)
		
print(int(ans))


### FIXED CODE ###

S=input().strip("¥n")

if S=="RRR":
	print(3)
elif "RR" in S:
	print(2)
elif "R" in S:
	print(1)
else:
	print(0)
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]
# dp[i][j](j=0,1,...,W)の値が求まっている状態で、dp[i+1][j]を更新することを考える
for i in range(N):
	for j in range(W + 1):
		# 品物(w[i],v[i])を選ぶとき、j-w[i]>=0に限って、価値v[i]が加算される
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		# 品物(w[i],v[i])を選ばないとき、何も加算しない
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

### FIXED CODE ###

#pypy3でAC

import sys
def input():
    return sys.stdin.readline()[:-1]

N, W = map(int, input().split())
w, v = [], []
for i in range(1, N+1):
    _w, _v = map(int, input().split())
    w.append(_w)
    v.append(_v)

V = sum(v)
#i個目までの品物から価値がj以上になるように選んだときの重さの最小値
dp = [[float("inf")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
"""
i番目を選ぶ場合
dp[i][j] = dp[i-1][j-v] + w
i番目を選ばない場合
dp[i][j] = dp[i-1][j]
"""

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

# dp[N][j]がW以下であるような最大のjを探す
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j
print(ans)
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = []

for j in range(len(S)):
    if S[j] == 'A' and S[j + 1] == 'C':
        S1.append(j+1)
    else:
        pass
print(S1)
for i in range(Q):
    count = 0
    ans = [k for k in S1 if A[i][0] <= k < A[i][1]]
    print(len(ans))

### FIXED CODE ###

# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = [0]*N
count = 0
for j in range(1,len(S)):
    if S[j] == 'C' and S[j - 1] == 'A':
        count += 1
    else:
        pass
    S1[j] = count
#print(S1)

for k in range(Q):
    print(S1[A[k][1]-1]-S1[A[k][0]-1])
A,B =[int(x) for x in input().split()]

def bunkai(n):
    sosu= {1}
    tmp = n
    stop_flag = n
    
    if tmp%2 == 0:
        while tmp%2==0:
            tmp //=2
        sosu.add(2)
    
    for i in range(3,n+1,2):
        if tmp%i == 0:
            while tmp%i==0:
                tmp //=i
            sosu.add(i)
            stop_flag = tmp 
            
        if i > stop_flag:
            break
#        else:
#            stop_flag = int(stop_flag/i) 
            
    if tmp!=1:
        sosu.add(tmp)
                
    if sosu==[1]:
        sosu.add(n)
    
    return sosu

def check_sosu(n,x):
    ans=0
    tmp = n
    for i in x:
        if (tmp % i) == 0:
            ans+=1
    return ans

ans = check_sosu(B,bunkai(A))

print(ans)

### FIXED CODE ###


N = int(input())

if N%2 ==0:
    ans=0.5
else :
    ans=(N//2 + 1)/N
    
print(ans)
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))


### FIXED CODE ###

s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[i]!=t[i] and s[i]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    #print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))
n = int(input())
num_list = [1]
dp = [0] * (n+1)
dp[1] = 1
dp[2] = 2
dp[3] = 3
dp[4] = 4
dp[5] = 5
dp[6] = 1


def recursion(n, li):
    min_n = 10**9
    for i in li:
        if n - i < 0:
            break
        num = dp[n - i]
        if min_n > num:
            min_n = num
    return min_n + 1


for i in range(1, 7):
    a = 6 ** i
    b = 9 ** i
    if a <= n:
        num_list.append(a)
    if b <= n:
        num_list.append(b)

for i in range(7, n+1):
    dp[i] = recursion(i, num_list)

print(dp[n])

### FIXED CODE ###

n = int(input())
num_list = [1]
dp = [0] * (n+1)
dp[1] = 1


def recursion(n, li):
    min_n = 10**9
    for i in li:
        if n - i < 0:
            continue
        num = dp[n - i]
        if min_n > num:
            min_n = num
    return min_n + 1


for i in range(1, 9):
    a = 6 ** i
    b = 9 ** i
    if a <= n:
        num_list.append(a)
    if b <= n:
        num_list.append(b)

for i in range(2, n+1):
    dp[i] = recursion(i, num_list)

print(dp[n])
idCards, gates = input().split(" ")
idCards = int(idCards)
gates = int(gates)

for count in range(0, gates, 1):
    num1, num2 = input().split(" ")
    minNum.append(int(num1))
    maxNum.append(int(num2))

minId = max(minNum)
maxId = min(maxNum)
if minId > maxId:
    print("0")
else:
    print((maxId - minId) + 1)

### FIXED CODE ###

import sys
idCards, gates = input().split(" ")
idCards = int(idCards)
gates = int(gates)
minNum = []
maxNum = []

if idCards > 1000000 or gates > 1000000:
    sys.exit()

for count in range(0, gates, 1):
    num1, num2 = input().split(" ")
    minNum.append(int(num1))
    maxNum.append(int(num2))

minId = max(minNum)
maxId = min(maxNum)
if minId > maxId:
    print("0")
else:
    print((maxId - minId) + 1)
import numpy as np
from scipy import ndimage

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

A_array = np.array(
    [[0 if s == "#" else 1 for s in input()[:-1]] for i in range(H)])


b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))

### FIXED CODE ###

from collections import deque

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

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p - W)
    if h != H-1:
        q_list.append(p + W)
    if w != 0:
        q_list.append(p - 1)
    if w != W-1:
        q_list.append(p + 1)
    return q_list


queue = deque(black_cells)
d = [10000] * (H * W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

print(max(d))
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

# 購買する全パターンを回す
most_row_price = 10**10
for i in range(2**n):
    comb = str(bin(i)[2:]).zfill(n)
    
    # 購買パターン毎の購入金額と理解度を算出する
    money_per_pattern = [0] * n # 購買パターン毎の金額の初期化
    total_money = 0 # 合計購入金額の初期化
    for j in range(n):
        
        # 購入しないケースは除外する
        if comb[j] == '0':
            continue
            
        # 購入するケースだけ、金額算出する
        total_money += ca[j][0]
        
        # 当該パターンの理解度を算出する
        for k in range(m):
            understanding[k] += ca[j][k+1]           

    for j in range(m):
        if understanding[j] < x:
            break
    else:
        most_row_price = min(total_money, most_row_price)

if most_row_price == 10**10:
    print(-1)
else:
    print(most_row_price)

### FIXED CODE ###

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

# 購買する全パターンを回す
most_row_price = 10**10
for i in range(2**n):
    comb = str(bin(i)[2:]).zfill(n)
    
    # 購買パターン毎の購入金額と理解度を算出する
    money_per_pattern = [0] * n # 購買パターン毎の金額の初期化
    understanding = [0] * m # 理解度の初期化
    total_money = 0 # 合計購入金額の初期化
    for j in range(n):
        
        # 購入しないケースは除外する
        if comb[j] == '0':
            continue
            
        # 購入するケースだけ、金額算出する
        money_per_pattern[j] = ca[j][0]
        
        # 当該パターンの理解度を算出する
        for k in range(m):
            understanding[k] += ca[j][k+1]           
    total_money = sum(money_per_pattern)            

    judge_flg = 'ok'
    for j in range(m):
        if understanding[j] < x:
            judge_flg = 'ng'
    
    if judge_flg == 'ok':
        most_row_price = min(total_money, most_row_price)

if most_row_price == 10**10:
    print(-1)
else:
    print(most_row_price)
S = input()
    ans = 0
    if S[0] == "1":
        ans += 1
    if S[1] == "1":
        ans += 1
    if S[2] == "1":
        ans += 1
    print(ans)

### FIXED CODE ###

def resolve():
    S = input()
    ans = 0
    if S[0] == "1":
        ans += 1
    if S[1] == "1":
        ans += 1
    if S[2] == "1":
        ans += 1
    print(ans)
resolve()
m = input().split()
print(48-m)

### FIXED CODE ###

m = int(input())
print(48-m)
a=int(input())
b=list(map(int,input().split()))
 
s=0
for i in range(a):
  for j in range(i+1,a):
    s+=d[i]*d[j]
print(s)

### FIXED CODE ###

a=int(input())
b=list(map(int,input().split()))
 
s=0
for i in range(a):
  for j in range(i+1,a):
    s+=b[i]*b[j]
print(s)
n = input()
x = 1
print ''
while True:
    if x > n:
        break
    if (x % 3 == 0) or ('3' in str(x)):
        print x

     x =x + 1

### FIXED CODE ###

n = input()
x = 1
print '',
while True:
    if x > n:
        break
    if (x % 3 == 0) or ('3' in str(x)):
        print x,
    x += 1
import heapq


def resolve():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())))[-x:]
    q = sorted(list(map(int, input().split())))[-y:]
    r = sorted(list(map(int, input().split())), reverse=True)
    heapq.heapify(p)
    for i in q:
        heapq.heappush(p, i)
    ans = 0
    for i in range(min(a + b, c)):
        ans += max(heapq.heappop(p), r[i])
    print(ans + sum(p))


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import heapq


def resolve():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())))[-x:]
    q = sorted(list(map(int, input().split())))[-y:]
    r = [-int(x) for x in input().split()]
    heapq.heapify(p)
    heapq.heapify(r)
    for i in q:
        heapq.heappush(p, i)
    ans = 0
    while p and r:
        ans += max(heapq.heappop(p), -heapq.heappop(r))
    ans += sum(p)
    print(ans)


if __name__ == '__main__':
    resolve()
A, B = map(int,input().split())
A_factors=prime_factorize(A)
B_factors=prime_factorize(B)
B_factors = set(B_factors)
A_factors = set(A_factors)
C = A_factors & B_factors
ans = len(C) + 1
print(ans)

### FIXED CODE ###

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
A, B = map(int,input().split())
A_factors=prime_factorize(A)
B_factors=prime_factorize(B)
B_factors = set(B_factors)
A_factors = set(A_factors)
C = A_factors & B_factors
ans = len(C) + 1
print(ans)