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

N,Ma,Mb=map(int,input().split())
a=[0 for k in range(N)]
b=[0 for k in range(N)]
c=[0 for k in range(N)]

for k in range(N):
    a[k],b[k],c[k]=map(int,input().split())

count=0
ans=[]
for k in range(2**N-1):
    count+=1
    bi=str(bin(count))
    A=0
    B=0
    C=0
    for j in range(1,len(bi)-1):
        if bi[-j]=="1":
            A+=a[j-1]
            B+=b[j-1]
            C+=c[j-1]
    if A*Mb==B*Ma and A!=0:
        ans.append(C)
if len(ans)>0:
    print(min(ans))
if ans==[]:
    print(-1)

### FIXED CODE ###

N,Ma,Mb=map(int,input().split())
a=[0 for k in range(N)]
b=[0 for k in range(N)]
c=[0 for k in range(N)]
import copy
for k in range(N):
    a[k],b[k],c[k]=map(int,input().split())
Sa=sum(a)
Sb=sum(b)
dp =[[[5000 for k in range(Sb+1)]for k in range(Sa+1)]for k in range(N+1)]
dp[0][0][0]=0
for k in range(N):
    listj=[]
    listl=[]
    for j in range(Sa-a[k]+1):
        for l in range(Sb-b[k]+1):
            if dp[k][j][l]!=5000:
                listj.append(j)
                listl.append(l)
    for m in range(len(listl)):
        dp[k+1][listj[m]+a[k]][listl[m]+b[k]]=min(dp[k][listj[m]][listl[m]]+c[k], dp[k][listj[m]+a[k]][listl[m]+b[k]])
        dp[k+1][listj[m]][listl[m]]=min(dp[k][listj[m]][listl[m]], dp[k+1][listj[m]][listl[m]])
ans=[5000]
for k in range(1, min(Sa//Ma,Sb//Mb)+1):
    ans.append(dp[-1][Ma*k][Mb*k])
if min(ans)==5000:
    print(-1)
else:
    print(min(ans))
### BUGGY CODE ###

n = int(input())
nums = list(map(int,input().split()))
ans = 0
ansa = nums[0]
ansz = nums[-1]
for i in range(1,n//2):
    ansa *= nums[i]
    ansz *= nums[-(i+1)]
if n%2==0:
    ans = ansa*ansz
else:
    ans = ansa*ansz*nums[n//2]
if ans <= 10**18:
    print(ans)
else:
    print('-1')

### FIXED CODE ###

n = int(input())
nums = list(map(int,input().split()))
ans = 1
if 0 in nums:
  print(0)
else:
  for i in range(n):
    ans *= nums[i]
    if ans > 10**18:
      ans = -1
      break
  print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys, itertools


def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    mn = 1e25
    for X in itertools.combinations(x, 2):
        for Y in itertools.combinations(y, 2):
            if len([xx for (xx, yy) in zip(x, y) if (X[0]-xx)*(X[1]-xx)<=0 and (Y[0]-yy)*(Y[1]-yy)<=0]) >= K:
                mn = min(mn, abs(X[0] - X[1]) * abs(Y[0] - Y[1]))
    print(mn)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys, itertools


def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    mn = 1e25
    for X in itertools.combinations(x, 2):
        for Y in itertools.combinations(y, 2):
            if len([xx for (xx, yy) in zip(x, y) if (X[0]-xx)*(X[1]-xx)<=0 and (Y[0]-yy)*(Y[1]-yy)<=0]) >= K:
                mn = min(mn, abs(X[0] - X[1]) * abs(Y[0] - Y[1]))
    print(mn)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)

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

N,Q = map(int, input().split())
answer = (N-2)**2

q1 = [(N,N-2)]
q2 = [(N,N-2)]

for _ in range(Q):
  n,x = map(int, input().split())
  if n == 1:
    index = 0
    while index < len(q1):
      q = q1[index]
      if q[0] > x:
        break
      else:
        index += 1
    answer -= q[1]
    if index == 0:
      q1 = [(x,q[1])] + q1
      q2_0 = q2[0]
      q2[0] = (q2_0[0],x-2)
  if n == 2:
    index = 0
    while index < len(q2):
      q = q2[index]
      if q[0] > x:
        break
      else:
        index += 1
    answer -= q[1]
    if index == 0:
      q2 = [(x,q[1])] + q2
      q1_0 = q1[0]
      q1[0] = (q1_0[0],x-2)
      
print(answer)

### FIXED CODE ###

N,Q = map(int, input().split())
answer = (N-2)**2

q1 = [(N,N-2)]
q2 = [(N,N-2)]

def binary_search(q,n):
  left = 0
  right = len(q) - 1
  while right > left:
    index = (left + right) // 2
    if q[index+1][0] > n:
      left = index + 1
    else:
      right = index
  return left

for _ in range(Q):
  n,x = map(int, input().split())
  if n == 1:
    index = binary_search(q1,x)
    q = q1[index]
    answer -= q[1]
    if index == len(q1)-1:
      q1.append((x,q[1]))
      q2_last = q2[-1]
      q2[-1] = (q2_last[0],x-2)
  if n == 2:
    index = binary_search(q2,x)
    q = q2[index]
    answer -= q[1]
    if index == len(q2)-1:
      q2.append((x,q[1]))
      q1_last = q1[-1]
      q1[-1] = (q1_last[0],x-2)
      
print(answer)
### BUGGY CODE ###

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

def main():
    n, u, v = map(int, input().split())
    u, v = u-1, v-1
    G = [[] for i in range(n)]
    for i in range(n-1):
        a,b = map(int, input().split())
        a,b = a-1,b-1
        G[a].append(b)
        G[b].append(a)

    def dfs(c,p,d):
        dep[c] = d
        for to in G[c]:
            if to != p:
                dfs(to, c, d+1)

    dep = [0]*n
    dfs(v, -1, 0)
    a = dep[:]
    dfs(u, -1, 0)
    b = dep

    ans = 0
    for i in range(n):
        if b[i] >= a[i]:
            continue
        tmp = 0
        d = b[i]
        if d != 0:
            tmp = 2*d
            aoki = d
        else:
            aoki = 0
        tak = a[i]
        m = tak-aoki
        if m%2==1:
            tmp += 2*m -1
        else:
            tmp += 2*(m-1)
        ans = max(ans, tmp)
    print(ans//2)

if __name__ == "__main__":
    main()


### FIXED CODE ###

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

from collections import deque

def main():
    n, u, v = map(int, input().split())
    u, v = u-1, v-1
    G = [[] for i in range(n)]
    for i in range(n-1):
        a,b = map(int, input().split())
        a,b = a-1,b-1
        G[a].append(b)
        G[b].append(a)

    def bfs(start):
        dist = [0]*n
        is_leaf = [0]*n
        que = deque()
        que.append((start, -1, 0))
        while que:
            c,p,d = que.pop()
            dist[c] = d
            cnt = 0
            for to in G[c]:
                if to != p:
                    que.append((to,c,d+1))
                    cnt += 1
            if not cnt:
                is_leaf[c] = 1
        return dist, is_leaf

    a, is_leaf = bfs(v)
    b, _ = bfs(u)

    ans = 0
    for i in range(n):
        if not is_leaf[i]:
            continue
        if b[i] >= a[i]:
            continue
        tmp = 0
        d = b[i]
        if d != 0:
            tmp = 2*d
            aoki = d
        else:
            aoki = 0
        tak = a[i]
        m = tak-aoki
        if m%2==1:
            tmp += 2*m -1
        else:
            tmp += 2*(m-1)
        ans = max(ans, tmp)
    print(ans//2)

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

N = int(input())
height = list(map(int, input().split()))
total = 0
max_number = height[0]

for i in range(1, height.index(max(height))):
	if height[i] > max_number:
		max_number = height[i]
	else:
		total += (max_number - height[i])

for i in range(height.index(max(height)), N):
	total += (max(height)-height[i])
    
print(total)

### FIXED CODE ###

N = int(input())
height = list(map(int, input().split()))
total = 0
max_number = height[0]

for i in range(1, height.index(max(height))):
	if height[i] > max_number:
		max_number = height[i]
	else:
		total += (max_number - height[i])

total += (max(height)*(N-1-height.index(max(height)))-sum(height[height.index(max(height))+1:N]))
    
print(total)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

start = end = 0
MAX = 0
for i in range(n):
    dices = p[i:i+k]
    expec = 0
    for d in dices:
        expec += sum([i for i in range(1, d + 1)]) / d
    MAX = max(MAX, expec)

print(MAX)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

expectations = [(((1 + i) * i) / 2) / i for i in p] # O(n)
i = 0
MAX = e = sum(expectations[i:i + k])
while i + k < n: # O(n)
    i += 1
    t = e - expectations[i - 1] + expectations[i + k - 1]
    MAX = max(MAX, t)
    e = t

print(MAX)
### BUGGY CODE ###

a,b,x = map(int,input().split())
count=0

while a<b+1:
    if a%x==0:
        count+=1
    a+=1

print(count)


### FIXED CODE ###

a,b,x = map(int,input().split())

if a == 0:
    print(b // x + 1)
else:
    a -= 1
    print(b // x - a // x)
### BUGGY CODE ###

icase=0
if icase==0:
    a,b,k=map(int,input().split()) 
    ab=[]
    for i in range(a,b+1):
        if i<=a+k-1 or b-k+1<=i:
            print(i)


### FIXED CODE ###

icase=0
if icase==0:
    a,b,k=map(int,input().split()) 
    if a+k-1<b-k+1:
        for i in range(a,a+k):
            print(i)
        for i in range(b-k+1,b+1):
            print(i)
    else:
        for i in range(a,b+1):
            print(i)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for _ in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count('AC'))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
ans=[0]*n
cnt=0
for i in range(len(s)-1):
    if s[i:i+2]=='AC': cnt+=1
    ans[i]=cnt
for _ in range(q):
    l,r=map(int,input().split())
    print(ans[r-2]-ans[l-2])
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)

ans = {}
key = list(C.keys())
val = list(C.values())

for i in range(len(key)):
    ans[key[i]] = val[i] * (val[i]-1) //2

ans_val = [int(_) for _ in list(ans.values())]

for j in range(N):
    print(sum(ans_val) - (C[A[j]] - 1) )

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)

ans = 0
for i in C.values():
    ans += int(0.5* i * (i-1))
for j in A:
    print(ans-C[j]+1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

def main():
    S = [int(s) for s in input()]
    N = len(S)
    K = 2019

    V = [0] * (N+1)
    count = [0] * 2020
    count[0] = 1
    ans = 0
    ten = 1
    for i in reversed(range(N)):
        rev_i = (N-1)-i
        ten = ten * 10
        v = V[rev_i] + S[i] * ten
        V[rev_i+1] = v
        u = v % K

        count[u] += 1
        cnt = count[u]
        ans -= (cnt-1) * (cnt-2)
        ans += cnt * (cnt-1)


    print(ans//2)

if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def main():
    S = [int(s) for s in input()]
    N = len(S)
    K = 2019

    V = [0] * (N+1)
    for i in reversed(range(N)):
        rev_i = (N-1)-i
        V[rev_i+1] = V[rev_i] + S[i] * (pow(10,rev_i+1,K))
        # print(V)

    dic = {} # value:count
    U = set()
    for v in V:
        u = v % K
        if u in U:
            dic[u] += 1
        else:
            dic[u] = 1
            U.add(u)

    ans = 0
    for u in U:
        u_count = dic[u]
        ans += u_count * (u_count-1) // 2

    # print(S)
    # print(V)
    # print(dic)
    print(ans)

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

import numpy as np
N,K = map(int,input().split())
MOD = 10 ** 9 + 7
M = int(N**.5)

# M+1以上で、商がぢょうとxになるやつ
upper_cnt = np.zeros(M+1, dtype=np.int64)
a = np.arange(M+1, dtype=np.int64)
upper_cnt[1:] = N // a[1:] - np.maximum(M, N // (a[1:]+1))

# 数列の末端ごとの個数
# upperについては、個数にわたって合計をとる
dp_lower = np.zeros((K+1,M+1), dtype=np.int64)
dp_upper = np.zeros((K+1,M+1), dtype=np.int64)
# 0項目に1を置いておくとする
dp_lower[0,1] = 1
for k in range(1,K+1):
    prev_lower = dp_lower[k-1]
    prev_upper = dp_upper[k-1]
    cum_lower = prev_lower.cumsum() % MOD
    cum_upper = prev_upper.cumsum() % MOD
    # 下側 to 下側
    dp_lower[k] += cum_lower[-1]
    # 上側 to 下側
    dp_lower[k] += cum_upper[-1]
    dp_lower[k,1:] -= cum_upper[:-1] # 商がn-1以下だと受け付けない
    dp_lower[k,0] = 0
    # 上側 to 上側：ないはず
    # 下側 to 上側：
    dp_upper[k] = cum_lower * upper_cnt
    dp_lower %= MOD
    dp_upper %= MOD
    
answer = (dp_lower[K].sum() + dp_upper[K].sum()) % MOD
print(answer)

### FIXED CODE ###

import numpy as np
N,K = map(int,input().split())
MOD = 10 ** 9 + 7
M = int(N**.5)

# M+1以上で、商がぢょうとxになるやつ
upper_cnt = np.zeros(M+1, dtype=np.int64)
a = np.arange(M+1, dtype=np.int64)
upper_cnt[1:] = N // a[1:] - np.maximum(M, N // (a[1:]+1))

# 数列の末端ごとの個数
# upperについては、個数にわたって合計をとる
lower = np.zeros(M+1, dtype=np.int64)
upper = np.zeros(M+1, dtype=np.int64)
# 0項目に1を置いておくとする
lower[1] = 1
for k in range(1,K+1):
    prev_lower = lower
    prev_upper = upper
    cum_lower = prev_lower.cumsum() % MOD
    cum_upper = prev_upper.cumsum() % MOD
    # 下側 to 下側
    lower = np.zeros(M+1, dtype=np.int64)
    lower += (cum_lower[-1] + cum_upper[-1])
    lower[1:] -= cum_upper[:-1] # 商がn-1以下だと受け付けない
    lower[0] = 0
    # 上側 to 上側：ないはず
    # 下側 to 上側：
    upper = cum_lower * upper_cnt
    lower %= MOD
    upper %= MOD
    
answer = (lower.sum() + upper.sum()) % MOD
print(answer)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 0
while all( a%2 == 0 for a in A ):
    a = [ i/2 for i in A ]
    ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
while all(A%2 == 0 for A in a):
	a = [i/2 for i in a ]
	ans += 1
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H,W,D = map(int,readline().split())
N = H*W
ind = [0]*N
d = {}

A = []
for _ in range(H):
    row = list(map(int,readline().split()))
    A += row
    
for i in range(1,N+1):
    ind = A.index(i)
    x = ind // W
    y = ind % W
    d[i] = (x+1,y+1)
# print(d)

data = [[] for i in range(D)]
ac_data = []
for i in range(1,D+1):
    n = 1
    while i + D*n <= N: 
        x,y = d[i+D*(n-1)]
        nx,ny = d[i+D*n]
        power = abs(x-nx) + abs(y-ny)
        data[i%D].append(power)
        n += 1
# print(data)      
for row in data:
    row = [0] +row
    ac_row = list(accumulate(row))
    ac_data.append(ac_row)

# print(ac_data)
Q = int(readline())
for i in range(Q):
    L,R = map(int,readline().split())
    k = L % D
    l = L // D 
    m = (R-L) // D
    if k == 0:
        print(ac_data[k][l-1+m]-ac_data[k][l-1])
    else:
        print(ac_data[k][l+m]-ac_data[k][l])

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H,W,D = map(int,readline().split())
X = [(0,0) for _ in range(H*W)]
Y = [0 for _ in range(H*W)]

for i in range(H):
    A = [int(x)-1 for x in readline().split()]
    for j in range(W):
        X[A[j]] = (i,j)

for i in range(0,H*W-D):
    Y[i+D] = Y[i] + abs(X[i+D][0] - X[i][0]) + abs(X[i+D][1] - X[i][1])

Q = int(readline())
for _ in range(Q):
    L,R = map(int,readline().split())
    print(Y[R-1]-Y[L-1])
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
read = sys.stdin.read


def main():
    N, M = map(int, readline().split())

    if M == 0:
        print('Yes')
        exit()

    *LRD, = map(int, read().split())
    graph = [[] for _ in range(N + 1)]

    # 根からの距離、根は複数の可能性あり
    distance = [-1] * (N + 1)
    child = [0] * (N + 1)

    for L, R, D in zip(*[iter(LRD)] * 3):
        graph[L].append((R, D))
        child[R] += 1

    for i in range(1, N + 1):
        if child[i]:
            continue

        # 以下iは根
        distance[i] = 0
        stack = [i]
        while stack:
            V = stack.pop()
            for v, d in graph[V]:
                if distance[v] == -1:
                    distance[v] = distance[V] + d
                else:
                    if distance[v] != distance[V] + d:
                        print('No')
                        exit()

                stack.append(v)

    # 例4のような循環タイプは上のfor内で処理されない
    if -1 in distance[1:]:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
readline = sys.stdin.readline
read = sys.stdin.read

N, M = map(int, readline().split())

if M == 0:
    print('Yes')
    exit()

LRD = map(int, read().split())
graph = [[] for _ in range(N + 1)]

# 根からの距離、根は複数の可能性あり
distance = [-1] * (N + 1)
child = [0] * (N + 1)

for L, R, D in zip(LRD, LRD, LRD):
    graph[L].append((R, D))
    child[R] = 1

for i in range(1, N + 1):
    if child[i]:
        continue

    # 以下iは根
    distance[i] = 0
    stack = [i]
    while stack:
        V = stack.pop()
        for v, d in graph[V]:
            if distance[v] == -1:
                distance[v] = distance[V] + d
                stack.append(v)
            else:
                if distance[v] != distance[V] + d:
                    print('No')
                    exit()

# 例4のような循環タイプは上のfor内で処理されない
if -1 in set(distance[1:]):
    print('No')
else:
    print('Yes')
### BUGGY CODE ###

from fractions import gcd
import math

N=int(input())

def divceil(a,b):
  n=0
  while a>n*b:
    n+=1
  return n

T=1
A=1
for _ in range(N):
  t,a=list(map(int, input().split()))
  m = max(divceil(T,t), divceil(A,a))
  T = t*m
  A = a*m
  
print(T+A)
  
  


### FIXED CODE ###

from fractions import gcd
import math

N=int(input())

def divceil(a,b):
  if a%b==0:
    return a//b
  else:
    return a//b + 1

T=1
A=1
for _ in range(N):
  t,a=list(map(int, input().split()))
  m = max(divceil(T,t), divceil(A,a))
  T = t*m
  A = a*m
  
print(T+A)
### BUGGY CODE ###

#python3
n=int(input())
a=[int(i) for i in input().split()]
MOD = int(1e9+7)
ans=0
for k in range(60):
  x=0
  for i in range(n):
    if(a[i]>>k)&1:
      x+=1
  contribute = x*(n-x)*2**k
  ans+=contribute
print(ans%MOD)

### FIXED CODE ###

#python3
import numpy as np
N = int(input())
A = np.array([int(_) for _ in input().split()])
mod = 10**9 + 7
ans = 0
for b in range(60):
    B = (A >> b) & 1
    M = np.count_nonzero(B)
    ans += 2**b * M * (N - M)
    ans %= mod
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N - 1:
            dp[i + k] = min(dp[i + k], dp[i] + abs(h_list[i + k] - h_list[i]))
print(dp[N-1])


### FIXED CODE ###

N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [float("inf") for _ in range(N + 1)]
dp[1] = 0
for i in range(1, N+1):
    for k in range(1, K+1):
        if i + k <= N:
            dp[i+k] = min(dp[i + k], dp[i] + abs(h_list[i-1] - h_list[i-1+k]))

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

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()
B = III()

first_use = []
second_use = []
for i in range(3):
    if A[i]<B[i]:
        first_use.append(i)
    if A[i]>B[i]:
        second_use.append(i)

# Aでちょうどi個のドングリを交換したときの，Bでのドングリの最大数
dp = [0]*(N+1)
for i in range(N+1):
    for j in first_use:
        if i-A[j]>=0:
            dp[i] = max(dp[i-A[j]]+B[j],dp[i])
for i in range(N+1):
    dp[i] = N-i+dp[i]

# B→A
count = max(dp)
dp = [0]*(count+1)
for i in range(count+1):
    for j in second_use:
        if i-B[j]>=0:
            dp[i] = max(dp[i-B[j]]+A[j],dp[i])
for i in range(count+1):
    dp[i] = count-i+dp[i]

print(max(dp))

### FIXED CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def solve():
    N = I()
    A = III()
    B = III()

    first_use = []
    second_use = []
    for i in range(3):
        if A[i]<B[i]:
            first_use.append(i)
        if A[i]>B[i]:
            second_use.append(i)

    def change(n,A,B,use_index):
        dp = [n]*(n+1)
        for i in range(n+1):
            for j in use_index:
                if i-A[j]>=0:
                    dp[i] = max(dp[i-A[j]]+B[j]-A[j],dp[i])
        return dp[n]

    count1 = change(N,A,B,first_use)
    count2 = change(count1,B,A,second_use)

    print(count2)

solve()
### BUGGY CODE ###

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

def prime(n):
  pn=[1,2]
  for i in range(3,n):
    chk=True
    for j in pn[1:]:
      if i%j==0:chk=False
    if chk==True:pn.append(i)
  return pn

c=set(prime(a//2))&set(prime(b//2))
c=[i for i in c if a%i==0 and b%i==0]
print(len(c))


### FIXED CODE ###

import math,fractions
a,b=list(map(int,input().split()))

def f(n):
    a=[1]
    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

def g(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
 
ans=set(f(a))&set(f(b))
#print(ans)
print(len(ans))
### BUGGY CODE ###

# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(K):
        for a in A:
            if i + a > K:
                break
            dp[i + a] |= dp[i] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()


### FIXED CODE ###

# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [0] * (K + 1)
    for i in range(1, K + 1):
        for a in A:
            if i - a >= 0:
                dp[i] |= dp[i - a] ^ 1
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()
### BUGGY 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()))
result = 0
Z = 0
while (X>0 or Y>0) and X+Y-Z>0:
        
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    if (X>0 or Y>0) and X+Y-Z>0:
        if p[0]>=q[0] and p[0]>=r[0] and X > 0:
            result += p[0]
            
            p[0] = 0
            X-=1
        elif q[0]>=p[0] and q[0]>=r[0] and Y > 0:
            result += q[0]
            
            q[0] = 0
            Y-=1
        elif r[0]>=q[0] and r[0]>=p[0]:
        
            result += r[0]
            r[0] = 0
            Z+=1

        elif X > 0:
            result += p[0]
            
            p[0] = 0
            X-=1
        elif Y > 0:
            result += q[0]
            
            q[0] = 0
            Y-=1
       
print(result)


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

p = p[0:X]
q = q[0:Y]

p.extend(q)
p.extend(r)

p.sort(reverse=True)
s=0
for i in range(X+Y):
    s+=p[i]
print(s)