Harryxun/stf_run huggingface dataset:
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ans=100000
for p in itertools.product(['A','B','C','Z'],repeat=n):
  if list(p).count('A')>=1 and list(p).count('B')>=1 and list(p).count('C')>=1:
    for i in range(n):
      la=0
      lb=0
      lc=0
      if p[i]=='A':
        la+=p[i]
      elif p[i]=='B':
        lb+=p[i]
      elif p[i]=='C':
        lc+=p[i]
      ans=min(ans,abs(la-a)+abs(lb-b)+abs(lc-c))
print(ans)

### FIXED CODE ###

import itertools
n,A,B,C=map(int,input().split())
l=[int(input()) for i in range(n)]
ll=[]
for p in itertools.product(['A','B','C','Z'],repeat=n):
  ans=0
  a=0
  b=0
  c=0
  numa=0
  numb=0
  numc=0
  for i in range(n):
    if p[i]=='A':
      a+=l[i]
      numa+=1
    elif p[i]=='B':
      b+=l[i]
      numb+=1
    elif p[i]=='C':
      c+=l[i]
      numc+=1
  ans+=(abs(a-A)+abs(B-b)+abs(C-c)+(numa+numb+numc-3)*10)
  if all(nn!=0 for nn in [numa,numb,numc]):
    ll.append(ans)
print(min(ll))
n,k=map(int, input())
if n%k==0:
  print("0")
else:
  print("1")

### FIXED CODE ###

n,k=map(int, input().split())
if n%k==0:
  print("0")
else:
  print("1")
l,r = map(int, input().split())
if r-l >= 2019:
  print(0)
else:
  m = 2018
  for i in range(l, r+1):
    for j in range(i+1, r+1):
      if i*j % 2019 < m:
        m = i*j % 2019

print(m)

### FIXED CODE ###

l,r = map(int, input().split())
if r-l >= 2019:
  print(0)
  exit()
else:
  m = 2018
  for i in range(l, r):
    for j in range(i+1, r+1):
      if i*j % 2019 < m:
        m = i*j % 2019

print(m)
n = int(input())
a = int(input())
b = int(input())

ttl = 0

for i in range(1,n+1):
  nums = sum(list(map(int,str(i)[:])))
  if nums >= a and nums <= b:
    ttl += i

print(ttl)

### FIXED CODE ###

n,a,b = map(int,input().split())
ttl = 0

for i in range(1,n+1):
  nums = sum(list(map(int,str(i)[:])))
  if nums >= a and nums <= b:
    ttl += i

print(ttl)
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int N, M; cin >> N >> M;

    vector< pair<int, int> > rawInput(M);
    vector<vector<int> > prifList(N);
    map<pair<int, int>, int> answer;

    for(int i = 0; i < M; ++i)
    {
        int P, Y; cin >> P >> Y;
        rawInput.at(i) = make_pair(P, Y);
        prifList.at(P - 1).push_back(Y);
        answer[make_pair(P, Y)] = 0;
    }

    for(int i = 0; i < N; ++i)
    {
        sort(prifList.at(i).begin(), prifList.at(i).end());
        for(int j = 0; j < prifList.at(i).size(); ++j)
        {
            answer[make_pair(i+1, prifList[i][j])] = j + 1;
        }
    }
    for(int i = 0; i < M; ++i)
    {
        cout << setw(6) << setfill('0') << rawInput.at(i).first;
        cout << setw(6) << setfill('0') << answer[rawInput.at(i)] << '\n';
    }
    return 0;
}


### FIXED CODE ###

N, M = map(int, input().split())
A = []
Plst = [list() for _ in range(N)]
dic = {}
for i in range(M):
    P, Y = map(int, input().split())
    A.append([i, P, Y])
    Plst[P - 1].append(Y)
    dic[(P, Y)] = 0
for i in range(N):
    Plst[i].sort()
    for j in range(len(Plst[i])):
        s = str(str(i + 1).zfill(6) + str(j + 1).zfill(6))
        dic[(i, Plst[i][j])] = s
for e in A:
    print(dic[(e[1] - 1, e[2])])
N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
#print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    #print(clear)
    bug.pop(0)
    O = clear.pop(0)

    if len(bug) == len(clear):
        ways.append(O)

    bug = []
    for k in range(M + 1):
        bug.append(0)

if len(ways) == 0:
    print(-1)
else:
    print(min(ways))

### FIXED CODE ###

N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
# print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    O = bug.pop(0)
    clear = [l for l in bug if l >= X]
    # print(clear)

    if len(bug) == len(clear):
        ways.append(O)

    bug = []
    for k in range(M + 1):
        bug.append(0)

if len(ways) == 0:
    print(-1)
else:
    print(min(ways))
import math
n = int(input())
k = math.log2(n) + 1
print(2**math.floor(k)-1)

### FIXED CODE ###

import math
n = int(input())
k = math.log(n, 2) + 1
print(2**math.floor(k)-1)
import fractions
n,m=map(int,input().split())
lis  = list(map(int,input().split()))
#aそれぞれを2で割ったものを持っておく
div = []
for i in range(n):
    div.append(lis[i]//2)
#lisそれぞれの要素を2で割り切れる回数をすべて数える
L = []
for i in range(n):
    cnt = 0
    while lis[i] %2 ==0:
        lis[i] //= 2
        cnt += 1
    L.append(cnt)

bl = True
for i in range(n):
    for j in range(n):
    if L[i] != L[j]:
        bl = False
        print(0)
        exit()
#div内の最小子公倍数Tを求める
T = 0
ans = div[0]
for i in range(1,n):
    ans =ans*div[i]//fractions.gcd(ans,div[i])
    T = ans

S = m//T
if S %2 ==0:
    print(S//2)
else:
    print(S//2 +1)


### FIXED CODE ###

import fractions
n,m=map(int,input().split())
lis  = list(map(int,input().split()))
#aそれぞれを2で割ったものを持っておく
div = []
for i in range(n):
    div.append(lis[i]//2)
#lisそれぞれの要素を2で割り切れる回数をすべて数える
L = []
for i in range(n):
    cnt = 0
    while lis[i] %2 ==0:
        lis[i] //= 2
        cnt += 1
    L.append(cnt)

bl = True
#重複要素を削除して要素数でLがすべて一緒か判断
def set_list(es):
    return len(list(set(es))) == 1

if set_list(L) != 1:
    print(0)
    exit()

#div内の最小子公倍数ansを求める

ans = div[0]
for i in range(1,n):
    ans =ans*div[i]//fractions.gcd(ans,div[i])

S = m//ans
if S %2 ==0:
    print(S//2)
else:
    print(S//2 +1)
a = input().spulit()
A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])
if A*B <= C*D:
 print(C*D)
else:
 print(A*B)

### FIXED CODE ###

a = input().split()
A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])
q = A*B
w = C*D
if q <= w:
 print(w)
else:
 print(q)
a = input()
b = input()
c = input()

d = a[0]
a.pop(0)
while True:
    if d == "a":
        if len(a) == 0:
            print("A")
            break
        d = a[0]
        a.pop(0)
    if d == "b":
        if len(b) == 0:
            print("B")
            break
        d = b[0]
        b.pop(0)
    if d == "c":
        if len(c) == 0:
            print("C")
            break
        d = c[0]
        c.pop(0)

### FIXED CODE ###


a = input()
b = input()
c = input()

d = a[0]
a = a[1:]
while True:
    if d == "a":
        if len(a) == 0:
            print("A")
            break
        d = a[0]
        a = a[1:]
    if d == "b":
        if len(b) == 0:
            print("B")
            break
        d = b[0]
        b = b[1:]
    if d == "c":
        if len(c) == 0:
            print("C")
            break
        d = c[0]
        c = c[1:]
list(input())
r= weather. count("R")
if r==2 and weather[1]=="S":
   print(1)
else:
   print(r)

### FIXED CODE ###

weather=list(input())
r= weather. count("R")
if r==2 and weather[1]=="S":
   print(1)
else:
   print(r)
def prity(mat, line):
    for i in range(line):
        for j in range(100):
            print(mat[i][j], end='')
        print()

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

if A*B == 1:
    print(".#")
    exit(1)

mat = [['' for i in range(100)] for j in range(100)]

line=0
if B > 1 and A > 1: # start with white
    B -= 1
    while A > 1:
        for j in range(50):
            if A > 1:
                mat[line][2*j] = "."
                A -= 1
            else:
                mat[line][2*j] = "#"
            mat[line][2*j+1] = "#"
        for j in range(100):
            mat[line+1][j] = "#"
        line += 2
        
for j in range(100):
    mat[line][j] = "."
A -= 1
line += 1
assert A == 0

if B > 1:
    while B > 0:
        for j in range(50):
            if B > 0:
                mat[line][2*j] = "#"
                B -= 1
            else:
                mat[line][2*j] = "."
            mat[line][2*j+1] = "."
        for j in range(100):
            mat[line+1][j] = "."
        line += 2
        
prity(mat, line)

### FIXED CODE ###

def prity(mat, line):
    print(line, 100)
    for i in range(line):
        for j in range(100):
            print(mat[i][j], end='')
        print()

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

if A*B == 1:
    print(1, 2)
    print(".#")
else:

    mat = [['' for i in range(100)] for j in range(100)]

    # start with white
    line=0
    if A > 1: 
        B -= 1
        while A > 1:
            for j in range(50):
                if A > 1:
                    mat[line][2*j] = "."
                    A -= 1
                else:
                    mat[line][2*j] = "#"
                mat[line][2*j+1] = "#"
            for j in range(100):
                mat[line+1][j] = "#"
            line += 2

    # one line of white
    for j in range(100):
        mat[line][j] = "."
    A -= 1
    line += 1
    assert A == 0
    
    # finish black
    if B > 0:
        while B > 0:
            for j in range(50):
                if B > 0:
                    mat[line][2*j] = "#"
                    B -= 1
                else:
                    mat[line][2*j] = "."
                mat[line][2*j+1] = "."
            for j in range(100):
                mat[line+1][j] = "."
            line += 2

    prity(mat, line)
a=int(input())

x=(a-2)/2
if int(x) ==x:
    print(int(x)
else:
    print(int(x)+1)


### FIXED CODE ###

a=int(input())
 
x=(a-2)/2
if int(x) ==x:
    print(int(x))
else:
    print(int(x+1))
import sys
i = 1
while True:
    x = sys.stdin.read()
    if x == 0:
        break
    print('Case {}: {}'.format(i,x))
    x + 1

### FIXED CODE ###

l = []
y = 1
while True:
    x = int(input())
    if x == 0:
        break
    l.append(x)
    print('Case {}: {}'.format(y,x))
    y += 1
import sys
sys.setrecursionlimit(400*400)
from collections import Counter
def rec(union_id, i, j):
    symbol = S[i][j]
    if union_white[i][j] != 0:
        return
    if symbol == '.':
        union_white[i][j] = union_id
        next_symbol = '#'
    else:
        union_white[i][j] = -1
        next_symbol = '.'
        union_black[union_id] += 1

    if i >= 1 and S[i-1][j] == next_symbol:
        rec(union_id, i-1, j)
    if i < H-1 and S[i+1][j] == next_symbol:
        rec(union_id, i+1, j)
    if j >= 1 and S[i][j-1] == next_symbol:
        rec(union_id, i, j-1)
    if j < W-1 and S[i][j+1] == next_symbol:
        rec(union_id, i, j+1)

    return
H, W = map(int, input().split())
S = [input() for h in range(H)]
ans = 0
union_white = [[0 for w in range(W)]for h in range(H)]
union_black = Counter()
count_black = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.' or union_white[i][j] != 0:
            continue
        count_black += 1
        rec(count_black, i, j)

counter = Counter([x for Si in union_white for x in Si])
ans = 0
# print(counter)
# print(union_black)
# print(union_white)
for i in union_black.keys():
    ans += counter[i] * union_black[i]

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(400*400*1000)
from collections import Counter
def rec(union_id, i, j):
    symbol = S[i][j]
    if union_white[i][j] != 0:
        return
    if symbol == '.':
        union_white[i][j] = union_id
        next_symbol = '#'
    else:
        union_white[i][j] = -1
        next_symbol = '.'
        union_black[union_id] += 1

    if i >= 1 and S[i-1][j] == next_symbol:
        rec(union_id, i-1, j)
    if i < H-1 and S[i+1][j] == next_symbol:
        rec(union_id, i+1, j)
    if j >= 1 and S[i][j-1] == next_symbol:
        rec(union_id, i, j-1)
    if j < W-1 and S[i][j+1] == next_symbol:
        rec(union_id, i, j+1)

    return
H, W = map(int, input().split())
S = [input() for h in range(H)]
ans = 0
union_white = [[0 for w in range(W)]for h in range(H)]
union_black = Counter()
count_black = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.' or union_white[i][j] != 0:
            continue
        count_black += 1
        rec(count_black, i, j)

counter = Counter([x for Si in union_white for x in Si])
ans = 0
# print(counter)
# print(union_black)
# print(union_white)
for i in union_black.keys():
    ans += counter[i] * union_black[i]

print(ans)
x, n = map(int, input().split())
P = list(map(int, input().split()))

P.sort()
P.append(101)

excluded = P.pop(0)

ans, absolute = None, 101

for i in range(102):
    if i == excluded:
        excluded = P.pop(0)
    else:
        if abs(i - x) < absolute:
            ans = i
            absolute = abs(i - x)
    
print(ans)
        

### FIXED CODE ###

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

for d in range(x + 1):
    for s in [-1, +1]:
        a = x + s * d
        if P.count(a) == 0:
            print(a)
            exit(0)
N = int(input())
p = [int(input()) for _ in range(N)]

print(sum(p) - int(max(p)/2))

### FIXED CODE ###

n = int(input())
if n == 25:
    print("Christmas")
elif n == 24:
    print("Christmas Eve")
elif n == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")
a,b=map(int,input().split())
if a<b
 print('a<b')
 elif a>b
 print('a>b')

### FIXED CODE ###

a, b = map(int,input().split())
 
if a > b:
    print('a > b')
elif a < b:
    print('a < b')
else:
    print('a == b')
"""
https://abc080.contest.atcoder.jp/tasks/abc080_b
"""
n=input()
a=0
for i in range(len(n)):
    a=a+int(n[i])
if n%a==0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

"""
https://abc080.contest.atcoder.jp/tasks/abc080_b
"""
n=input()
a=0
for i in range(len(n)):
    a=a+int(n[i])
if int(n)%a==0:
    print("Yes")
else:
    print("No")
INF = 10 ** 20

def minimum_cost(rest, dp, tlst, end, n):
  if rest in dp:
    return dp[rest]
  if rest == end:
    return 0
  
  ret = INF
  for ind, to in enumerate(rest):
    if to == "0":
      tmp = minimum_cost(rest[:ind] + "1" + rest[ind + 1:], dp, tlst, end, n) + cost(ind, rest, tlst, n)
      if tmp < ret:
        ret = tmp
  dp[rest] = ret
  return ret

def cost(ind, rest, tlst, n):
  ts = tlst[ind - 1]
  ret = INF
  for c, v in zip(rest, ts):
    if v < ret and c == "1":
      ret = v
  return ret


def main():
  while True:
    n = int(input())
    if n == 0:
      break
    tlst = [list(map(int, input().split())) for _ in range(n)]
    dp = {}
    end = "1" * (n + 1)
    ans = minimum_cost("1" + "0" * n, dp, tlst, end, n)
    print(ans)

main()


### FIXED CODE ###

INF = 10 ** 20

def minimum_cost(rest, dp, tlst, tord, end, n):
  if rest in dp:
    return dp[rest]
  if rest == end:
    return 0
  
  ret = INF
  for ind, to in enumerate(rest):
    if to == "0":
      tmp = minimum_cost(rest[:ind] + "1" + rest[ind + 1:], dp, tlst, tord, end, n) + cost(ind, rest, tlst, tord, n)
      if tmp < ret:
        ret = tmp
  dp[rest] = ret
  return ret

def cost(ind, rest, tlst, tord, n):
  order = tord[ind - 1]
  for i in order:
    if rest[i] == "1":
      return tlst[ind - 1][i]


def main():
  while True:
    n = int(input())
    if n == 0:
      break
    tlst = [list(map(int, input().split())) for _ in range(n)]
    tord = []
    for lst in tlst:
      tmp = sorted(zip(lst, range(n + 1)))
      tord.append([i for _, i in tmp])
    dp = {}
    end = "1" * (n + 1)
    ans = minimum_cost("1" + "0" * n, dp, tlst, tord, end, n)
    print(ans)

main()
from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    a_max = alist[max_ind]

print(count)


### FIXED CODE ###

from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    if abs(max_ind) <= len(alist):
                        a_max = alist[max_ind]

print(count)
s = input()
k = int(input())

edge = 0
ans = 0
if len(set(s))==1:
    s = s*k
    print(len(s)//2)
else:
    if s[0] != s[-1]:
        ans = 0
        for i in range(len(s)):
            if i==0:
                n=1
                tmp = s[i]
            elif s[i]==tmp:
                n += 1
            else:
                if n!=1:
                    ans += 1
                tmp = s[i]
                n = 1
        print(ans*k)
        exit()
    a = s[0]
    b = s[-1]
    cnt_a, cnt_b = 0,0
    ite = 0
    
    while s[cnt_a] == a:
        cnt_a += 1
    while s[len(s)-cnt_b-1] == b:
        cnt_b += 1
    
    s1 = s[:cnt_a]
    s2 = s[cnt_a:len(s)-cnt_b]
    s3 = s[len(s)-cnt_b:]
    
    A = cnt_a//2
    B = cnt_b//2    
    X = 0
    if len(set(s2))==1:
        X = len(s2)//2
    else:
        for i in range(len(s2)):
            if i==0:
                n = 1
                tmp = s2[i]
            elif s2[i] == tmp:
                n += 1
            else:
                if n != 1:
                    X += n//2
                tmp = s2[i]
                n = 1
    C = (len(s1+s3))//2
    print(A+B+X*k+C*(k-1))

### FIXED CODE ###

s = input()
k = int(input())

if len(set(list(s)))==1:
    print(len(s)*k//2)

elif s[0] != s[-1]:
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s = s[:i]+'.'+s[i+1:]
    print(s.count('.')*k)
else:
    a,b = 0,0
    c = s[0]
    rev_s = s[::-1]
    for i in range(len(s)):
        if s[i]==c:
            a += 1
        else:
            break
    for i in range(len(s)):
        if rev_s[i]==c:
            b += 1
        else:
            break
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s = s[:i]+'.'+s[i+1:]
    print(s.count('.')*k - (a//2 + b//2 - (a+b)//2)*(k-1))
b = input()
if b=="A":
  print("T")
else if b=="T":
  print("A")
else if b=="G":
  print("C")
else if b=="c":
  print("G")


### FIXED CODE ###

b = raw_input()
if b=="A":
	print("T")
elif b=="T":
	print("A")
elif b=="G":
	print("C")
elif b=="C":
	print("G")
from itertools import product

s=input()

for op in product(["+","-"],repeat=len(s)-1):
  formula =""
  for i in range(len(s-1)):
    formula+=s[i]+op[i]
  formula+=s[-1]
  if eval(formula)==7:
    print(formula+"=7")
    exit()

### FIXED CODE ###

s=input()
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

if a+b+c+d==7:
  print("%d+%d+%d+%d=7"%(a,b,c,d))
  exit()
if a+b+c-d==7:
  print("%d+%d+%d-%d=7"%(a,b,c,d))
  exit()
if a+b-c+d==7:
  print("%d+%d-%d+%d=7"%(a,b,c,d))
  exit()
if a+b-c-d==7:
  print("%d+%d-%d-%d=7"%(a,b,c,d))
  exit()  
if a-b+c+d==7:
  print("%d-%d+%d+%d=7"%(a,b,c,d))
  exit()
if a-b+c-d==7:
  print("%d-%d+%d-%d=7"%(a,b,c,d))
  exit()
if a-b-c+d==7:
  print("%d-%d-%d+%d=7"%(a,b,c,d))
  exit()
if a-b-c-d==7:
  print("%d-%d-%d-%d=7"%(a,b,c,d))
  exit()
import math
a, b, n = map(int, input().split())

if n < b:
    x = n
    score = math.floor(a*x/b) - a * math.floor(x/b)
    print(score)
    
else:
    x = b-1
    score = math.floor(a*x/b) - a * math.floor(x/b)
    print(max_score)

### FIXED CODE ###

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

if n < b:
    score = math.floor(a*n/b) - a * math.floor(n/b)
    print(score)
    
else:
    max_score = -10000
    for i in range(1,10):
        x = (b-1)*i
        score = math.floor(a*x/b) - a * math.floor(x/b)
        max_score = max(max_score, score)
    print(max_score)
n,p=map(int,input().split())



def yakusuSub(p,d,arr):
    if p==1:return arr
    if p/d==int(p/d):
        arr.append(d)
        return yakusuSub(p/d,d,arr)
    else:
        return yakusuSub(p,d+1,arr)

def yakusu(p):
    return yakusuSub(p,2,[])

if n==1:
    print(p)
    exit()

y=yakusu(p)
if not y:
    print(1)
    exit()
ans=1
cnt=1
before=0
f=False
for i in y:
    if i==before:
        cnt+=1
    else:
        cnt=1
    if cnt>=n:
        ans*=i
        cnt=1
        f=True
    before=i
if f:
    print(ans)
else:
    print(p)

### FIXED CODE ###

n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    for i in range(1, round(p**(1/n))+1):
        if p % i**n ==0:
            res = i
    print(res)
#!/usr/bin/env python3

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

weight = []
value = []

for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

#dp = [[0]*110]*11010
#dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
dp=[[0 for _ in range(110)] for _ in range(11010)]


for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])


### FIXED CODE ###

#!/usr/bin/env python3

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

weight = []
value = []

for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

#dp = [[0]*110]*11010
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
#dp=[[0 for _ in range(110)] for _ in range(11010)]


for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])
while True:
    h=int(input())
    w=int(input())
    if a==0&b==0:
      break
    for i in range(h):
       print("#"*w)
    print()
    
    


### FIXED CODE ###

while True:
    v=input().split()
    a=int(v[0])
    b=int(v[1])
    if a==0 and b==0:
       break
    for i in range (a):
        print('#'*b)
    print()
N , i = list(map(int, input().split()))
print(n + 1 - i)


### FIXED CODE ###

n, i = list(map(int, input().split()))
print(n - i + 1 )
X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
i=0
for i in ans:
	if i<r[-1]:
		ans[i]=r.pop()
	else:
		break
print(sum(ans))



### FIXED CODE ###

X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
j=0
k=0
for i in ans:
	if len(r)>1:
		k=r[-1]
	elif len(r)==1:
		k=r[0]
	else:
		break
	if i<k:
		ans[j]=r.pop()
		j+=1
	else:
		break
print(sum(ans))