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

n = int(input())
ta = []
for i in range(n):
    ta.append([int(i) for i in input().split()])

for i in range(1, n):
    tmp = ta[i][:]
    while ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]:
        ta[i][0] += tmp[0]
        ta[i][1] += tmp[1]

print(ta[-1][0] + ta[-1][1])


### FIXED CODE ###

def round_up(x, y):
    res = x // y
    if x % y != 0:
        res += 1
    return res

n = int(input())
ta = []
for i in range(n):
    ta.append([int(i) for i in input().split()])

for i in range(1, n):
    if ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]:
        multi = max(
            round_up(ta[i-1][0], ta[i][0]),
            round_up(ta[i-1][1], ta[i][1])
        )
        ta[i][0] *= multi
        ta[i][1] *= multi

print(ta[-1][0] + ta[-1][1])
### BUGGY CODE ###

from collections import Counter
import math

def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = list(map(int,input().split()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)

### FIXED CODE ###

from collections import Counter
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())
A = list(map(int,input().split()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)
### BUGGY CODE ###

N = int(input())
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return len(table)

MOD = 1000000007

#階乗を求める
result = 0
count = 0
def kaijouWithMod(n):
    if(n == 1):
        return n
    return n * kaijouWithMod(n - 1)

print(divisor(kaijouWithMod(N)) % MOD)

### FIXED CODE ###

#3問目
import math
from decimal import *
N = int(input())
MAX = 10 ** 9 + 7
result = 1

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

Soinsuu = [0] * (N + 1)
for i in range(1, N + 1):
    factorize = prime_factorize(i)
    for j in factorize:
        Soinsuu[j] += 1

for i in Soinsuu:
    if i != 0:
        result *= i+1

print(result % MAX)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l = sorted(l)

    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l[j+1:], l[i] + l[j])

    print(result)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l, l[i] + l[j]) - (j + 1)

    print(result)


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

def main():
    n, m = map(int, input().split())
    As = [int(input()) for _ in range(m)]
    mod = 1000000007

    dp = [0] * (n + 1)
    dp[0] = 1
    if 1 not in As:
        dp[1] = 1
    else:
        dp[1] = 0

    for i in range(2, n+1):
        if i in As:
            continue
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= mod

    print(dp[n])


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    As = set([int(input()) for _ in range(m)])
    mod = 1000000007

    dp = [0] * (n + 1)
    dp[0] = 1
    if 1 not in As:
        dp[1] = 1

    for i in range(2, n+1):
        if i in As:
            continue
        dp[i] = dp[i-1] + dp[i-2]

    ans = dp[n] % mod
    print(ans)


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

from collections import deque
s = deque(input())
q = int(input())
for _ in range(q):
    Q = list(map(str,input().split()))
    if int(Q[0]) == 1:
        if len(s) > 1:
            s=deque(list(s)[::-1])
    else:
        if int(Q[1]) == 1:
            s.appendleft(Q[2])
        else:
            s.append(Q[2])

            
print("".join(s))

### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())
k = 0

for _ in range(q):
    Q = list(map(str,input().split()))
    if int(Q[0]) == 1:
        if k == 0:
            k = 1
        else:
            k = 0
    else:
        if k == 0:
            if int(Q[1]) == 1:
                s.appendleft(Q[2])
            else:
                s.append(Q[2])
        else:
            if int(Q[1]) == 1:
                s.append(Q[2])
            else:
                s.appendleft(Q[2])


if k == 1:
    s = list(s)[::-1]
    
print("".join(s))
### BUGGY CODE ###

N, M = map(int, input().split())
Am = list(map(int, input().split()))
A = sorted(Am, reverse=True)
A.append(0)
for m in range(M):
    a = int(A[0] / 2)
    n = 0
    while A[n + 1] > a and n < N - 1:
        A[n] = A[n + 1]
        n += 1
    A[n] = a
print(sum(A))


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
Am=[-a for a in A]
heapq.heapify(Am)
for m in range(M):
    a = int(heapq.heappop(Am) / 2)
    heapq.heappush(Am, a)
print(-sum(Am))
### BUGGY CODE ###

A, B, K = map(int, input().split())

while K != 0:
    if A >= 1:
        A -= 1
    elif B >= 1:
        B -= 1
    K -= 1

print(A, B)


### FIXED CODE ###

A, B, K = map(int, input().split())

a = A - K
k = K - A
if k <= 0:
    k = 0
b = B - k

if a <= 0:
    a = 0
if b <= 0:
    b = 0

print(a, b)
### BUGGY CODE ###

import math
from functools import reduce

def gcd_list(num_list):
    return reduce(math.gcd, num_list)

K = int(input())

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sum += gcd_list([a, b, c])

print(sum)

### FIXED CODE ###

import math
from functools import reduce

def gcd_list(num_list):
    return reduce(math.gcd, num_list)

K = int(input())

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sum += gcd_list([a, b, c])

print(sum)
### BUGGY CODE ###

K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
while True:
  ans += 1
  x = (x * 10 + 7) % K
  
  if x == 7 % K:
    print('-1')
    exit()
  if x == 0:
    print(ans)
    exit()

### FIXED CODE ###

K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  if x == 7 % K:
    print('-1')
    exit()
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')
### BUGGY CODE ###

import collections
from itertools import combinations

N = int(input())
s = []
for i in range(N):
    s.append(''.join(sorted(list(input()))))
c = collections.Counter(s)

cnt = 0
for i in c.values():
    if i > 1:
        cnt += len(list(combinations(range(i), 2)))
print(cnt)

### FIXED CODE ###

import collections
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
c = collections.Counter(s)

cnt = 0
for i in c.values():
    if i > 1:
        cnt += i*(i-1)//2
print(cnt)
### BUGGY CODE ###

N, M=map(int, input().split())
A=list(map(int, input().split()))
def discount(lst):
    M=max(lst)
    A[A.index(M)]=M/2
    return lst
#print(A)
for i in range(M):

    A=discount(A)
    #print(A)
answer=list(map(int, A))
print(sum(answer))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(lambda x:-int(x), input().split()))
#print([bin(val) for val in A])

heapq.heapify(A)
#print(A)

for _ in range(M):
    temp = -heapq.heappop(A) // 2
    heapq.heappush(A, -temp)
    #print(A)
print(-sum(A))
### BUGGY CODE ###

# B Frog 2

n, k = map(int, input().split())
h_list = [int(x) for x in input().split()]

dp = [float('Inf')] * n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1,1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h_list[i-j]-h_list[i]))

        
print(dp[n-1])

### FIXED CODE ###

# B Frog 2

n, k = map(int, input().split())
h_list = [int(x) for x in input().split()]

dp = [float('Inf')] * n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1,1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h_list[i-j]-h_list[i]))

        
print(dp[n-1])
### BUGGY CODE ###

import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
a = readints()


def func(a):
    cnt = 0
    for i in range(n):
        if a[i] % 2 == 0:
            cnt += 1
            a[i] = a[i]/2
    if cnt == n:
        return True
    else:
        False


cntcnt = 0
for _ in range(100000):
    if func(a):
        cntcnt += 1
print(cntcnt)


### FIXED CODE ###

import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
a = readints()

cnt = 0
while all(x % 2 == 0 for x in a):
    a = [x/2 for x in a]
    cnt += 1
print(cnt)
### BUGGY CODE ###

N = int(input())

def c_ab(n,a,b):
    ret = 0
    for i in range(1,n+1):
        max_digit = int(str(i)[0]) #iを文字列にしたときの頭
        min_digit = int(str(i)[-1]) #iを文字列にしたときの末尾
        if max_digit == a and min_digit == b:
            ret += 1
    return ret

C_ab = [[0 for i in range(10)] for j in range(10)]
for i in range(10):
    for j in range(10):
            C_ab[i][j] = c_ab(N,i,j)

count = 0
for i in range(10):
    for j in range(10):
        count += C_ab[i][j]*C_ab[j][i]

print(count)


### FIXED CODE ###

N = int(input())

C_ab = [[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
    C_ab[int(str(i)[0])][int(str(i)[-1])] += 1

count = 0
for i in range(1,10):
    for j in range(1,10):
        count += C_ab[i][j]*C_ab[j][i]

print(count)
### BUGGY CODE ###


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
s=s0()

c=Counter(s)
d=list(c.values())

def prod(line):
    r=1
    for i in line:
        r*=i
    return r

i=2
ans=sum(d)
while i<=len(d):
    tmp=itertools.combinations(d,i)
    for line in tmp:
        ans+=prod(line)
    i+=1

print(ans%(10**9+7))

### FIXED CODE ###


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
s=s0()

c=Counter(s)
d=list(c.values())
MOD=10**9+7

def prod(line):
    r=1
    for i in line:
        r*=i
        r%=MOD
    return r


ans=prod([i+1 for i in d])
print((ans-1)%MOD)
### BUGGY CODE ###

h, n = map(int, input().split())

dp = [float("inf") for _ in range(h+1)]
dp[0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])


### FIXED CODE ###

h, n = map(int, input().split())

dp = [float("inf") for _ in range(h+1)]
dp[0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)

def dfs(v,s):
  #global dic_score
  #global tree_list
  #global ans_list
  visited[v]=True
  score=s
  if v in dic_score:
    score+=dic_score[v]
    
  ans_list[v]+=score
  for vv in tree_list[v]:
    if not visited[vv]:
      dfs(vv,score)
    
  return s

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

tree_list=[[] for _ in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  tree_list[a].append(b)
  tree_list[b].append(a)
#print(tree_list)

dic_score=defaultdict(int)
for i in range(Q):
  p,x=map(int,input().split())
  dic_score[p]+=x

ans_list=[0]*(N+1)
visited=[False]*(N+1)
dfs(1,0)

print(*ans_list[1:])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline

def dfs(u,par):
  ans_list[u]+=ans_list[par]  
  for v in tree_list[u]:
    if v!=par:
      dfs(v,u)      
  return

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

tree_list=[[] for _ in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  tree_list[a].append(b)
  tree_list[b].append(a)
#print(tree_list)

ans_list=[0]*(N+1)
for i in range(Q):
  p,x=map(int,input().split())
  ans_list[p]+=x

dfs(1,0)

print(*ans_list[1:])
### BUGGY CODE ###

from operator import mul
from functools import reduce
a=int(input())
li = list(map(int,input().split()))

j = reduce(mul, li)
if j > 10**18:
  print(-1)
else:
  print(j)

### FIXED CODE ###


a=int(input())
li = list(map(int,input().split()))
if 0 in li:
  print(0)
  
else:
  result = 1
  for number in li:
    result = result * number
    if result > 10**18:
      print(-1)
      break

  if result <= 10**18:
    print(result)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
def sub(ii):
    dp = 1
    for i in range(n):
        if i==ii:
            continue
        dp |= dp<<a[i]
#         for j in range(k-1, a[i]-1, -1):
#             dp[j] += dp[j-a[i]]
    val = max(i for i in range(k) if (dp>>i)&1)
    return val+a[ii]>=k
if sub(0):
    ans = 0
elif not sub(n-1):
    ans = n
else:
    l = 0
    r = n-1
    while l<r-1:
        m = (l+r)//2
        if sub(m):
            r = m
        else:
            l = m
    ans = l+1
print(ans)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(lambda x: min(int(x), k+1), input().split()))
a.sort()
mask = (1<<(k+1)) - 1
def sub(ii):
    dp = 1
    for i in range(n):
        if i==ii:
            continue
        dp |= (dp<<a[i]) & mask
#         for j in range(k-1, a[i]-1, -1):
#             dp[j] += dp[j-a[i]]
    val = max(i for i in range(k) if (dp>>i)&1)
    return val+a[ii]>=k
if sub(0):
    ans = 0
elif not sub(n-1):
    ans = n
else:
    l = 0
    r = n-1
    while l<r-1:
        m = (l+r)//2
        if sub(m):
            r = m
        else:
            l = m
    ans = l+1
print(ans)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
K1 = min(K, len(A))

B = sorted(list(map(int, input().split())), reverse=True)
K2 = min(K, len(B))

C = sorted(list(map(int, input().split())), reverse=True)
K3 = min(K, len(C))

K12 = min(K1 * K2, K)

M1 = [0] * (K1 * K2)
k = 0
for i in range(0, K1):
    for j in range(0, K2):
        M1[k] = A[i] + B[j]
        k += 1

M1.sort(reverse=True)

M = [0] * (K12 * K3)
k = 0
for i in range(0, K12):
    for j in range(0, K3):
        M[k] = M1[i] + C[j]
        k += 1

M.sort(reverse=True)
for i in range(0, K):
    print(M[i])


### FIXED CODE ###


X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

M = []
for i in range(0, X):
    for j in range(0, Y):
        for k in range(0, Z):
            if (i+1) * (j+1) * (k+1) <= K:
                M.append(A[i] + B[j] + C[k])
            else:
                break

M.sort(reverse=True)
for i in range(0, K):
    print(M[i])
### BUGGY CODE ###

#!/usr/bin/env python3
# Knapsack問題

import numpy as np

# input
N,W = map(int, input().split())
w = np.zeros(N, dtype=int)
v = np.zeros(N, dtype=int)
for i in range(N):
  a,b = map(int ,input().split())
  w[i] = a 
  v[i] = b 

# calc
dp = [[0 for _ in range(W+1)] for _ in range(N+2)]
dp = np.array(dp, dtype=int)
for i in np.arange(N):
   for j in np.arange(W+1):
        if w[i] <= j:
            dp[i+1,j] = max(dp[i, j-w[i]]+v[i], dp[i,j])
        else:
            dp[i+1,j] = dp[i,j]

print(dp[N,W])


### FIXED CODE ###

# Knapsack問題

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

# calc
dp = [[0 for _ in range(W+1)] for _ in range(N+2)]

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

print(dp[N][W])
### BUGGY CODE ###

import copy
N = int(input())
X = list(map(int,input().split()))


for i in range(N):
    Y = copy.copy(X)
    del Y[i]
    Y.sort()
    print(Y[N//2-1])


### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
m1= Y[N//2-1]
m2 = Y[N//2]
for i in range(N):
    if X[i] <= m1:
        print(m2)
    else:
        print(m1)
### BUGGY CODE ###

import sys

N, Y = map(int, input().split())
Y /= 1000
cnt = 0

for x in reversed(range(N+1)):
    for y in reversed(range(N+1-x)):
        for z in reversed(range(N+1-x-y)):
            if 10*x + 5*y + z == Y and x + y + z == N:
                print(str(x)+" "+str(y)+" "+str(z))
                sys.exit()
print("-1 -1 -1")

### FIXED CODE ###

N, Y = map(int, input().split())
Y /= 1000
res10 = res5 = res1 = -1

for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10*x + 5*y + z == Y:
            res10 = x
            res5 = y
            res1 = z
print(str(res10)+" "+str(res5)+" "+str(res1))
### BUGGY CODE ###

x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort(reverse=True)
A=A[a-x:]
B=B[b-y:]

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)
            


### FIXED CODE ###

x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort(reverse=True)
A=A[a-x:]
B=B[b-y:]

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)
### BUGGY CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n, ww = map(int, input().split())

dp = np.array([[0 for _ in range(ww+1)] for _ in range(n)])
w, v = map(int, input().split())
dp[0] = np.array([v if i >= w else 0 for i in range(ww+1)])
for i in range(1, n):
  w, v = map(int, input().split())
  for j in range(1,ww+1):
    if j+w <= ww:
      dp[i][j+w] = max(dp[i-1][j+w], dp[i-1][j]+v)
    dp[i][j] = max(dp[i-1][j],dp[i][j])

print(dp[-1][-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, W = map(int, input().split())
dp = [0] * (W + 1)
def knapsack(n, w):
    for _ in range(N):
        w, v = map(int, input().split())
        for wk in range(W, w-1, -1):
            tv = dp[wk - w] + v
            if tv > dp[wk]:
                dp[wk] = tv
    return dp[-1]
print(knapsack(N, W))
### BUGGY CODE ###

from collections import Counter
import sys
n=int(sys.stdin.readline().rstrip())
S=[]
for _ in range(n):
    S.append(sys.stdin.readline().rstrip())
    
cnt=Counter(S)
list=[]
for k in cnt.most_common():
    if k[1] != cnt.most_common()[0][1]:
        break
    list.append(k[0])

list.sort()
for i in list:
    print(i)

### FIXED CODE ###

from collections import Counter
import sys
n=int(sys.stdin.readline().rstrip())
S=[sys.stdin.readline().rstrip() for _ in range(n)]
    
cnt=Counter(S)
ma = max(cnt.values())
list=[]
for k in cnt.keys():
    if cnt[k] == ma:
      list.append(k)

list.sort()
for i in list:
    print(i)
### BUGGY CODE ###

n = int(input())
ans = 0

ab = [tuple(map(int,input().split())) for i in range(n)]
a,b = [],[]
for ai,bi in ab:
    a.append(ai)
    b.append(bi)

c = 0
for i in reversed(range(n)):
    a[i] += c
    while(a[i]%b[i]):
        c+=1
        a[i]+=1
    
print(c)

### FIXED CODE ###

n = int(input())
ans = 0

a, b = [], []
for i in range(n):
    ai, bi = map(int, input().split())

    a.append(ai)
    b.append(bi)

c = 0
for i in reversed(range(n)):
    a[i] += c
    x = a[i] % b[i]
    if x:
        if a[i] < b[i]:
            c += b[i] - a[i]
        elif a[i] > b[i]:
            c += b[i] - x

print(c)