AtCoder Beginner Contest 119 - Synthetic Kadomatsu

You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:
 - Extension Magic: Consumes 1 MP (magic point). Choose one bamboo and increase its length by 1.
 - Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
 - Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective?

-----Constraints-----
 - 3 \leq N \leq 8
 - 1 \leq C < B < A \leq 1000
 - 1 \leq l_i \leq 1000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N

-----Output-----
Print the minimum amount of MP needed to achieve the objective.

-----Sample Input-----
5 100 90 80
98
40
30
21
80

-----Sample Output-----
23

We are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98, 40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain bamboos of lengths 100, 90 by using the magics as follows at the total cost of 23 MP, which is optimal.
 - Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)
 - Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)
 - Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)
 - Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)

Difficulty: EASY

Starter code:

Solutions:
(N, *A) = map(int, input().split())
a = [[0] * 4]
r = [0, 1, 2]
for i in range(N):
	l = int(input())
	a = [[p[j] + l * (i == j) for j in r] + [p[3] + (i < 3) * 10] for i in r + [3] for p in a]
print(min((sum((abs(p[i] - A[i]) for i in r)) - 30 + p[3] for p in a if min(p[:3]) > 0)))


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	(N, A, B, C) = LI()
	ABC = (A, B, C)
	l = [I() for _ in range(N)]
	ans = INF
	for i in itertools.product(list(range(4)), repeat=N):
		a_cnt = i.count(0)
		b_cnt = i.count(1)
		c_cnt = i.count(2)
		if a_cnt > 0 and b_cnt > 0 and (c_cnt > 0):
			mp = 10 * (a_cnt + b_cnt + c_cnt - 3)
			len = [0] * 3
			for j in range(N):
				if 0 <= i[j] < 3:
					len[i[j]] += l[j]
			mp += sum([abs(j - k) for (j, k) in zip(ABC, len)])
			ans = min(mp, ans)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(N, A, B, C, *l) = map(int, open(0).read().split())
INF = 1000000000.0

def dfs(cur, a, b, c):
	if cur == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if a * b * c != 0 else INF
	v1 = dfs(cur + 1, a, b, c)
	v2 = dfs(cur + 1, a + l[cur], b, c) + 10
	v3 = dfs(cur + 1, a, b + l[cur], c) + 10
	v4 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(v1, v2, v3, v4)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]

def rec(i, a, b, c, d):
	if i == N:
		if a == 0 or b == 0 or c == 0:
			return float('inf')
		return abs(a - A) + abs(b - B) + abs(c - C) + d
	return min(rec(i + 1, a + l[i], b, c, d + 10), rec(i + 1, a, b + l[i], c, d + 10), rec(i + 1, a, b, c + l[i], d + 10), rec(i + 1, a, b, c, d))
print(rec(0, 0, 0, 0, -30))


(N, A, B, C) = [int(_) for _ in input().split()]
H = [int(input()) for _ in range(N)]
INF = 1000 * 1000

def dfs(h, a, b, c):
	if not h:
		return INF if a * b * c == 0 else abs(A - a) + abs(B - b) + abs(C - c)
	k = h[0]
	return min(dfs(h[1:], a, b, c), dfs(h[1:], a + k, b, c) + 10, dfs(h[1:], a, b + k, c) + 10, dfs(h[1:], a, b, c + k) + 10)
print(dfs(H, 0, 0, 0) - 30)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = []

def dfs(idx, a, b, c, mp10):
	if idx == N:
		if a and b and c:
			ans.append(abs(A - a) + abs(B - b) + abs(C - c) + mp10 * 10)
	else:
		dfs(idx + 1, a, b, c, mp10)
		dfs(idx + 1, a + L[idx], b, c, mp10 + 1)
		dfs(idx + 1, a, b + L[idx], c, mp10 + 1)
		dfs(idx + 1, a, b, c + L[idx], mp10 + 1)
dfs(0, 0, 0, 0, -3)
print(min(ans))


(N, A, B, C) = map(int, input().split())
Ln = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + Ln[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + Ln[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + Ln[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


from functools import lru_cache
(N, A, B, C, *L) = list(map(int, open(0).read().split()))

@lru_cache(None)
def popcnt(n):
	return bin(n).count('1')

@lru_cache(None)
def synth(bit):
	length = 0
	for i in range(N):
		if bit >> i & 1:
			length += L[i]
	return length
ans = 1 << 60
for bit1 in range(1, 1 << N):
	if popcnt(bit1) >= N - 1:
		continue
	length1 = synth(bit1)
	for bit2 in range(1, 1 << N):
		if bit1 & bit2:
			continue
		if popcnt(bit1 | bit2) == N:
			continue
		length2 = synth(bit2)
		for bit3 in range(1, 1 << N):
			if bit1 & bit3 or bit2 & bit3:
				continue
			length3 = synth(bit3)
			(c, b, a) = sorted([length1, length2, length3])
			cost = 10 * (popcnt(bit1 | bit2 | bit3) - 3) + abs(C - c) + abs(B - b) + abs(A - a)
			if cost < ans:
				ans = cost
print(ans)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
inf = 3000

def mp(g, a, b, c):
	if g == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else inf
	l0 = mp(g + 1, a + l[g], b, c) + 10
	l1 = mp(g + 1, a, b + l[g], c) + 10
	l2 = mp(g + 1, a, b, c + l[g]) + 10
	l3 = mp(g + 1, a, b, c)
	return min(l0, l1, l2, l3)
print(mp(0, 0, 0, 0))


from itertools import product
(N, A, B, C) = list(map(int, input().split(' ')))
L = [int(input()) for _ in range(N)]
ans = 10 ** 9
for groups in product(list(range(4)), repeat=N):
	length_a = 0
	length_b = 0
	length_c = 0
	cost_a = -10
	cost_b = -10
	cost_c = -10
	for (group, length) in zip(groups, L):
		if group == 1:
			length_a += length
			cost_a += 10
		elif group == 2:
			length_b += length
			cost_b += 10
		elif group == 3:
			length_c += length
			cost_c += 10
	if 0 in {length_a, length_b, length_c}:
		continue
	ans = min(ans, sum([abs(A - length_a), abs(B - length_b), abs(C - length_c), cost_a, cost_b, cost_c]))
print(ans)


(n, A, B, C) = map(int, input().split(' '))
l = [int(input()) for i in range(n)]
INF = 10 ** 9

def bfs(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	else:
		ret0 = bfs(cur + 1, a, b, c)
		ret1 = bfs(cur + 1, a + l[cur], b, c) + 10
		ret2 = bfs(cur + 1, a, b + l[cur], c) + 10
		ret3 = bfs(cur + 1, a, b, c + l[cur]) + 10
		return min(ret0, ret1, ret2, ret3)
print(bfs(0, 0, 0, 0))


def dfs(i, a, b, c):
	if i == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else float('inf')
	mx = dfs(i + 1, a, b, c)
	ma = dfs(i + 1, a + l[i], b, c) + 10
	mb = dfs(i + 1, a, b + l[i], c) + 10
	mc = dfs(i + 1, a, b, c + l[i]) + 10
	return min(mx, ma, mb, mc)
(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = []
for i in range(N):
	l.append(int(input()))
INF = 100000

def mp(j, a, b, c):
	if j == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = mp(j + 1, a, b, c)
	ret1 = mp(j + 1, a + l[j], b, c) + 10
	ret2 = mp(j + 1, a, b + l[j], c) + 10
	ret3 = mp(j + 1, a, b, c + l[j]) + 10
	return min(ret0, ret1, ret2, ret3)
print(mp(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
ko = [int(input()) for i in range(n)]
INF = 10 ** 9

def dfs(q, w, e, r):
	if q == n:
		return abs(a - w) + abs(b - e) + abs(c - r) - 30 if min(w, e, r) > 0 else INF
	re0 = dfs(q + 1, w, e, r)
	re1 = dfs(q + 1, w + ko[q], e, r) + 10
	re2 = dfs(q + 1, w, e + ko[q], r) + 10
	re3 = dfs(q + 1, w, e, r + ko[q]) + 10
	return min(re0, re1, re2, re3)
print(dfs(0, 0, 0, 0))


import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().strip()
NI = lambda : int(input())
NMI = lambda : map(int, input().split())
NLI = lambda : list(NMI())
SI = lambda : input()

def make_grid(h, w, num):
	return [[int(num)] * w for _ in range(h)]

def main():
	(N, A, B, C) = NMI()
	L = [NI() for _ in range(N)]

	def dfs(bamboo, a, b, c):
		if bamboo == N:
			if a * b * c == 0:
				return 10 ** 100
			(a, b, c) = sorted([a, b, c], reverse=True)
			res = abs(A - a) + abs(B - b) + abs(C - c)
			return res
		res = 10 ** 100
		res = min(res, dfs(bamboo + 1, a + L[bamboo], b, c) + 10) if a > 0 else min(res, dfs(bamboo + 1, a + L[bamboo], b, c))
		res = min(res, dfs(bamboo + 1, a, b + L[bamboo], c) + 10) if b > 0 else min(res, dfs(bamboo + 1, a, b + L[bamboo], c))
		res = min(res, dfs(bamboo + 1, a, b, c + L[bamboo]) + 10) if c > 0 else min(res, dfs(bamboo + 1, a, b, c + L[bamboo]))
		res = min(res, dfs(bamboo + 1, a, b, c))
		return res
	print(dfs(0, 0, 0, 0))

def __starting_point():
	main()
__starting_point()


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 10 ** 18
for i in range(4 ** n):
	(la, lb, lc, ca, cb, cc) = (0, 0, 0, 0, 0, 0)
	for j in range(n):
		if i >> 2 * j & 1 and (not i >> 2 * j + 1 & 1):
			ca += 1
			la += l[j]
		if not i >> 2 * j & 1 and i >> 2 * j + 1 & 1:
			cb += 1
			lb += l[j]
		if i >> 2 * j & 1 and i >> 2 * j + 1 & 1:
			cc += 1
			lc += l[j]
	if ca * cb * cc:
		ans = min((ca + cb + cc - 3) * 10 + abs(la - a) + abs(lb - b) + abs(lc - c), ans)
print(ans)


(n, a, b, c) = map(int, input().split())
x = [int(input()) for i in range(n)]
from itertools import product
z = [a, b, c]
d = [0, 1, 2, 3]
ans = 10 ** 8
for i in product(d, repeat=n):
	an = 0
	y = [[], [], [], []]
	for (j, k) in enumerate(i):
		y[k].append(x[j])
	if len(y[1]) == 0 or len(y[2]) == 0 or len(y[3]) == 0:
		continue
	for (k, j) in enumerate(y[1:]):
		an += (len(j) - 1) * 10 + abs(sum(j) - z[k])
	ans = min(an, ans)
print(ans)


(N, A, B, C) = map(int, input().split())
D = [A, B, C]
L = [0] * N
for i in range(N):
	L[i] = int(input())
MP = 3000
for i in range(4 ** N):
	E = [0, 0, 0]
	mp = 0
	for j in range(N):
		n = i % 4
		if n < 3:
			mp += 10 if E[n] else 0
			E[n] += L[j]
		i >>= 2
	for i in range(3):
		mp += abs(D[i] - E[i]) if E[i] else 3000
	MP = min(mp, MP)
print(MP)


from itertools import product

def solve():
	(N, A, B, C, *L) = list(map(int, open(0).read().split()))
	ans = float('inf')
	for X in product([0, 1], repeat=N):
		tmp = [L[i] for i in range(N) if X[i]]
		if len(tmp) < 3:
			continue
		for Y in product([0, 1, 2], repeat=len(tmp)):
			tmp_inner = [[] for _ in range(3)]
			for (j, y) in enumerate(Y):
				tmp_inner[y].append(tmp[j])
			if all((t for t in tmp_inner)):
				join_cost = sum(((len(li) - 1) * 10 for li in tmp_inner))
				expand_cost = sum((abs(sum(t) - a) for (t, a) in zip(tmp_inner, [A, B, C])))
				ans = min(ans, join_cost + expand_cost)
	return ans
print(solve())


def dfs(ka, kb, kc, cnta, cntb, cntc, phase):
	nonlocal ans
	if phase == n:
		if 0 < cnta and 0 < cntb and (0 < cntc):
			ans = min(ans, abs(a - ka) + abs(b - kb) + abs(c - kc) + 10 * (cnta + cntb + cntc - 3))
		return
	dfs(ka + l[phase], kb, kc, cnta + 1, cntb, cntc, phase + 1)
	dfs(ka, kb + l[phase], kc, cnta, cntb + 1, cntc, phase + 1)
	dfs(ka, kb, kc + l[phase], cnta, cntb, cntc + 1, phase + 1)
	dfs(ka, kb, kc, cnta, cntb, cntc, phase + 1)
(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 10 ** 9
dfs(0, 0, 0, 0, 0, 0, 0)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(N)]

def dfs(idx, a, b, c):
	if idx == N:
		if a == 0 or b == 0 or c == 0:
			return 1000000000.0
		return abs(A - a) + abs(B - b) + abs(C - c)
	x = dfs(idx + 1, a, b, c)
	y = dfs(idx + 1, a + L[idx], b, c) + 10 * (a != 0)
	z = dfs(idx + 1, a, b + L[idx], c) + 10 * (b != 0)
	w = dfs(idx + 1, a, b, c + L[idx]) + 10 * (c != 0)
	return min(x, y, z, w)
ans = dfs(0, 0, 0, 0)
print(ans)


(N, A, B, C) = [int(item) for item in input().split()]
take = [int(input()) for i in range(N)]

def dfs(n, a, b, c):
	if n == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10 ** 9
	ret0 = dfs(n + 1, a + take[n], b, c) + 10
	ret1 = dfs(n + 1, a, b + take[n], c) + 10
	ret2 = dfs(n + 1, a, b, c + take[n]) + 10
	ret3 = dfs(n + 1, a, b, c)
	return min(ret0, ret1, ret2, ret3)
ans = dfs(0, 0, 0, 0)
print(ans)


(N, A, B, C) = map(int, input().split())
from itertools import product
l = [int(input()) for i in range(N)]
ans = []
for i in product(range(4), repeat=N):
	a = 0
	b = 0
	c = 0
	d = 0
	for j in range(N):
		if i[j]:
			d += 1
			if i[j] == 1:
				a += l[j]
			elif i[j] == 2:
				b += l[j]
			else:
				c += l[j]
	if a * b * c:
		ans += [abs(A - a) + abs(B - b) + abs(C - c) + (d - 3) * 10]
print(min(ans))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else float('inf')
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = sorted([int(input()) for i in range(n)])

def kad(w, x, y, z):
	if w == n:
		if min(x, y, z) > 0:
			return abs(x - a) + abs(y - b) + abs(z - c) - 30
		else:
			return 100000.0
	c0 = kad(w + 1, x, y, z)
	c1 = kad(w + 1, x + l[w], y, z) + 10
	c2 = kad(w + 1, x, y + l[w], z) + 10
	c3 = kad(w + 1, x, y, z + l[w]) + 10
	return min(c0, c1, c2, c3)
print(kad(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(n)]

def calc(r, a, b, c):
	if r == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10 ** 9
	else:
		root1 = calc(r + 1, a, b, c)
		root2 = calc(r + 1, a + l[r], b, c) + 10
		root3 = calc(r + 1, a, b + l[r], c) + 10
		root4 = calc(r + 1, a, b, c + l[r]) + 10
		return min(root1, root2, root3, root4)
print(calc(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
banboo = [int(input()) for i in range(n)]

def dfs(num, A, B, C):
	if num == n:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(A, B, C) > 0 else float('inf')
	v1 = dfs(num + 1, A, B, C)
	v2 = dfs(num + 1, A + banboo[num], B, C) + 10
	v3 = dfs(num + 1, A, B + banboo[num], C) + 10
	v4 = dfs(num + 1, A, B, C + banboo[num]) + 10
	return min(v1, v2, v3, v4)
print(dfs(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
ls = [int(input()) for _ in range(n)]
inf = 10000

def dfs(i, a, b, c):
	if i == n:
		return inf if min(a, b, c) == 0 else abs(A - a) + abs(B - b) + abs(C - c) - 30
	i1 = i + 1
	lsi = ls[i]
	r0 = dfs(i1, a, b, c)
	r1 = dfs(i1, a + lsi, b, c) + 10
	r2 = dfs(i1, a, b + lsi, c) + 10
	r3 = dfs(i1, a, b, c + lsi) + 10
	return min(r0, r1, r2, r3)
print(dfs(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(n)]
INF = 10 ** 9

def dfs(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	x = dfs(cur + 1, a, b, c)
	y = dfs(cur + 1, a + l[cur], b, c) + 10
	z = dfs(cur + 1, a, b + l[cur], c) + 10
	w = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(x, y, z, w)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
L_list = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(a, b, c, n):
	if n == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
	ret1 = dfs(a, b, c, n + 1)
	ret2 = dfs(a + L_list[n], b, c, n + 1) + 10
	ret3 = dfs(a, b + L_list[n], c, n + 1) + 10
	ret4 = dfs(a, b, c + L_list[n], n + 1) + 10
	return min(ret1, ret2, ret3, ret4)
ans = dfs(0, 0, 0, 0)
print(ans)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]

def dfs(cur, a, b, c):
	if cur == N:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 10 * 3
		else:
			return 10 ** 9
	c0 = dfs(cur + 1, a, b, c)
	c1 = dfs(cur + 1, a + l[cur], b, c) + 10
	c2 = dfs(cur + 1, a, b + l[cur], c) + 10
	c3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(c0, c1, c2, c3)
print(dfs(0, 0, 0, 0))


from itertools import product
INF = 10 ** 9
(N, *A) = list(map(int, input().split()))
L = [int(input()) for _ in range(N)]

def estimate(lst):
	if any((not p for p in lst)):
		return INF
	ret = 0
	for (p, g) in zip(lst, A):
		ret += abs(g - sum(p)) + (len(p) - 1) * 10
	return ret
ans = INF
for prd in product(list(range(4)), repeat=N):
	pieces = [[] for _ in range(3)]
	for (bamboo_ind, target_kadomatsu) in enumerate(prd):
		if target_kadomatsu == 3:
			continue
		pieces[target_kadomatsu].append(L[bamboo_ind])
	if ans > (res := estimate(pieces)):
		ans = res
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]

def f(X):
	global N, A, B, C, L
	if len(X) == N:
		(a, b, c) = (0, 0, 0)
		for i in range(N):
			a += X[i][0]
			b += X[i][1]
			c += X[i][2]
		if min(a, b, c) == 0:
			return 10 ** 16
		else:
			return abs(A - a) + abs(B - b) + abs(C - c)
	return min(f(X + [[0, 0, 0]]), f(X + [[L[len(X)], 0, 0]]) + 10, f(X + [[0, L[len(X)], 0]]) + 10, f(X + [[0, 0, L[len(X)]]]) + 10)
print(f([]) - 30)


(n, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(n)]
INF = 10 ** 9

def dfs(cur, a, b, c):
	if cur == n:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return INF
	pat0 = dfs(cur + 1, a + l[cur], b, c) + 10
	pat1 = dfs(cur + 1, a, b + l[cur], c) + 10
	pat2 = dfs(cur + 1, a, b, c + l[cur]) + 10
	pat3 = dfs(cur + 1, a, b, c)
	return min(pat0, pat1, pat2, pat3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = list(map(int, input().split()))
l = []
for i in range(N):
	l.append(int(input()))
choiceList = []
for i in range(4 ** N):
	choice = [-1 for i in range(N)]
	for j in range(N):
		choice[j] = i // 4 ** j % 4
	choiceList.append(choice)
minCost = 10 ** 9
for choice in choiceList:
	cost = 10 ** 9
	aList = []
	bList = []
	cList = []
	for i in range(N):
		if choice[i] == 1:
			aList.append(l[i])
		elif choice[i] == 2:
			bList.append(l[i])
		elif choice[i] == 3:
			cList.append(l[i])
	if len(aList) == 0 or len(bList) == 0 or len(cList) == 0:
		cost = 10 ** 9
	else:
		aCost = (len(aList) - 1) * 10 + abs(sum(aList) - A)
		bCost = (len(bList) - 1) * 10 + abs(sum(bList) - B)
		cCost = (len(cList) - 1) * 10 + abs(sum(cList) - C)
		cost = aCost + bCost + cCost
	if minCost > cost:
		minCost = cost
print(minCost)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]

def dfs(k, a, b, c):
	global N, A, B, C, l
	if k == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 1000000
	det0 = dfs(k + 1, a + l[k], b, c) + 10
	det1 = dfs(k + 1, a, b + l[k], c) + 10
	det2 = dfs(k + 1, a, b, c + l[k]) + 10
	det3 = dfs(k + 1, a, b, c)
	return min(det0, det1, det2, det3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
ans = [[0, 0, 0, 0]]
for i in range(N):
	l = int(input())
	ans = [[p[j] + l * (i == j) for j in [0, 1, 2]] + [p[3] + (i < 3)] for p in ans for i in range(4)]
print(min((abs(p[0] - A) + abs(p[1] - B) + abs(p[2] - C) + p[3] * 10 - 30 for p in ans if min(p[:3]) > 0)))


from itertools import product
(N, *ABC) = map(int, input().split())
L = []
for _ in range(N):
	L.append(int(input()))
ans = 10 ** 9
for X in product((0, 1, 2, 3), repeat=N):
	(cnt, K, temp) = ([0] * 4, [0] * 4, 0)
	for i in range(N):
		cnt[X[i]] += 1
		K[X[i]] += L[i]
	if min(cnt[1:]) == 0:
		continue
	for i in range(3):
		temp += abs(ABC[i] - K[i + 1])
		temp += 10 * max(cnt[i + 1] - 1, 0)
	ans = min(ans, temp)
print(ans)


INF = float('inf')

def dfs(a=0, b=0, c=0, d=0):
	if d == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, min(b, c)) else INF
	ans = dfs(a, b, c, d + 1)
	ans = min(ans, dfs(a + l[d], b, c, d + 1) + 10)
	ans = min(ans, dfs(a, b + l[d], c, d + 1) + 10)
	ans = min(ans, dfs(a, b, c + l[d], d + 1) + 10)
	return ans
(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
print(dfs())


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
ans = float('inf')

def dfs(d=0, a=0, b=0, c=0, mp=0):
	if d == N:
		mp = mp + abs(A - a) + abs(B - b) + abs(C - c) - 30
		global ans
		if a * b * c > 0 and mp < ans:
			ans = mp
		return
	dfs(d + 1, a, b, c, mp)
	dfs(d + 1, a + l[d], b, c, mp + 10)
	dfs(d + 1, a, b + l[d], c, mp + 10)
	dfs(d + 1, a, b, c + l[d], mp + 10)
dfs()
print(ans)


(n, a, b, c) = list(map(int, input().split()))
l = []
for i in range(n):
	l.append(int(input()))
ans = 100000
for i in range(4 ** n):
	mp = 0
	f = 0
	x = []
	y = []
	z = []
	w = []
	for j in range(n):
		if i % 4 == 0:
			x.append(l[j])
		elif i % 4 == 1:
			y.append(l[j])
		elif i % 4 == 2:
			z.append(l[j])
		else:
			w.append(l[j])
		i = i // 4
	if sum(x) == 0 or sum(y) == 0 or sum(z) == 0:
		f = 1
	X = sum(x)
	Y = sum(y)
	Z = sum(z)
	mp += (len(x) + len(y) + len(z) - 3) * 10
	p = [X, Y, Z]
	q = [a, b, c]
	p = sorted(p)
	q = sorted(q)
	mp += abs(p[0] - q[0]) + abs(p[1] - q[1]) + abs(p[2] - q[2])
	if f != 1:
		ans = min(mp, ans)
print(ans)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]

def dfs(d, a, b, c):
	if d == N:
		res = abs(a - A) + abs(b - B) + abs(c - C) - 30
		return 1000000000.0 if min(a, b, c) == 0 else res
	ret = [0] * 4
	ret[0] = dfs(d + 1, a, b, c)
	ret[1] = dfs(d + 1, a + l[d], b, c) + 10
	ret[2] = dfs(d + 1, a, b + l[d], c) + 10
	ret[3] = dfs(d + 1, a, b, c + l[d]) + 10
	return min(ret)
print(dfs(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = []
for _ in range(n):
	d = int(input())
	l.append(d)

def dfs(cur, x, y, z):
	if cur == n and min(x, y, z) > 0:
		return abs(a - x) + abs(b - y) + abs(c - z) - 30
	elif cur == n:
		return 100000000000000000000
	ret0 = dfs(cur + 1, x, y, z)
	ret1 = dfs(cur + 1, x + l[cur], y, z) + 10
	ret2 = dfs(cur + 1, x, y + l[cur], z) + 10
	ret3 = dfs(cur + 1, x, y, z + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 8

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


import sys
sys.setrecursionlimit(10 ** 8)

def ii():
	return int(sys.stdin.readline())

def mi():
	return list(map(int, sys.stdin.readline().split()))

def li():
	return list(map(int, sys.stdin.readline().split()))

def li2(N):
	return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def dp2(ini, i, j):
	return [[ini] * i for _ in range(j)]
import itertools
(N, *A) = mi()
L = [ii() for _ in range(N)]
sum_a = sum(A)

def dfs(i, a, b, c, use):
	if 0 not in [a, b, c] and use > 2:
		nonlocal ans
		ans = min(ans, (use - 3) * 10 + abs(a - A[0]) + abs(b - A[1]) + abs(c - A[2]))
	if i > N - 1:
		return
	dfs(i + 1, a + L[i], b, c, use + 1)
	dfs(i + 1, a, b + L[i], c, use + 1)
	dfs(i + 1, a, b, c + L[i], use + 1)
	dfs(i + 1, a, b, c, use)
ans = float('inf')
dfs(0, 0, 0, 0, 0)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
ans = 10 ** 10
import itertools
for prod in itertools.product(range(4), repeat=N):
	bamboo = [0] * 4
	mp = 0
	for i in range(len(prod)):
		if prod[i] == 0:
			continue
		if bamboo[prod[i]] != 0:
			mp += 10
		bamboo[prod[i]] += L[i]
	if 0 in bamboo[1:]:
		continue
	mp += abs(A - bamboo[1]) + abs(B - bamboo[2]) + abs(C - bamboo[3])
	if ans > mp:
		ans = mp
print(ans)


(n, a, b, c) = list(map(int, input().split()))
L = [int(input()) for _ in range(n)]
ans = 10 ** 9
for x in range(4 ** n):
	(A, B, C) = (0, 0, 0)
	cost = 0
	for i in range(n):
		r = x % 4
		x //= 4
		if r == 1:
			A += L[i]
		elif r == 2:
			B += L[i]
		elif r == 3:
			C += L[i]
		if r > 0:
			cost += 10
	if A == 0 or B == 0 or C == 0:
		continue
	cost += -30 + abs(A - a) + abs(B - b) + abs(C - c)
	ans = min(ans, cost)
print(ans)


from itertools import product
(N, A, B, C) = map(int, input().split())
l = []
for _ in range(N):
	l.append(int(input()))
ans = 10 ** 18
for i in product(range(4), repeat=N):
	mp = 0
	bamboo = [0, 0, 0]
	for j in range(N):
		s = i[j]
		if s == 3:
			continue
		else:
			if bamboo[s] != 0:
				mp += 10
			bamboo[s] += l[j]
	if bamboo[0] == 0 or bamboo[1] == 0 or bamboo[2] == 0:
		continue
	mp += abs(A - bamboo[0])
	mp += abs(B - bamboo[1])
	mp += abs(C - bamboo[2])
	ans = min(ans, mp)
print(ans)


from itertools import product
(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]
ans = float('inf')
for choice in product([0, 1, 2, 3], repeat=n):
	items = [0] * 3
	totals = [0] * 3
	temp = 0
	if min([choice.count(i) for i in range(3)]) == 0:
		continue
	for (i, ch) in enumerate(choice):
		if ch == 3:
			continue
		totals[ch] += l[i]
		items[ch] += 1
		if items[ch] > 1:
			temp += 10
	temp += abs(a - totals[0])
	temp += abs(b - totals[1])
	temp += abs(c - totals[2])
	ans = min(ans, temp)
print(ans)


from itertools import product
(N, *ABC) = map(int, input().split())
L = list((int(input()) for _ in range(N)))
mp = 10 ** 9
for i in product([0, 1, 2, 3], repeat=N):
	if {0, 1, 2} <= set(i):
		m = [0, 0, 0]
		for (x, y) in zip(i, L):
			if x != 3:
				m[x] += y
		t = sum((abs(p - q) for (p, q) in zip(ABC, m)))
		r = sum((1 if k != 3 else 0 for k in i)) - 3
		mp = min(mp, t + r * 10)
print(mp)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
inf = 10 ** 9

def dfs(d, a, b, c):
	if d == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf
	ret0 = dfs(d + 1, a, b, c)
	ret1 = dfs(d + 1, a + l[d], b, c) + 10
	ret2 = dfs(d + 1, a, b + l[d], c) + 10
	ret3 = dfs(d + 1, a, b, c + l[d]) + 10
	ans = min(ret0, ret1, ret2, ret3)
	return ans
print(dfs(0, 0, 0, 0))


import itertools
(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
pattern = ['a', 'b', 'c', 'N']
lcombi = itertools.product(pattern, repeat=N)
ans = 1000 ** 3
for lc in list(lcombi):
	Alen = 0
	Blen = 0
	Clen = 0
	Acost = 0
	Bcost = 0
	Ccost = 0
	if 'a' not in lc or 'b' not in lc or 'c' not in lc:
		continue
	else:
		for i in range(N):
			if lc[i] == 'a':
				if Alen == 0:
					Alen += l[i]
				else:
					Alen += l[i]
					Acost += 10
			elif lc[i] == 'b':
				if Blen == 0:
					Blen += l[i]
				else:
					Blen += l[i]
					Bcost += 10
			elif lc[i] == 'c':
				if Clen == 0:
					Clen += l[i]
				else:
					Clen += l[i]
					Ccost += 10
		Acost += abs(Alen - A)
		Bcost += abs(Blen - B)
		Ccost += abs(Clen - C)
		ans = min(ans, Acost + Bcost + Ccost)
print(ans)


import sys
input = sys.stdin.readline
(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = float('inf')

def dfs(i, a, b, c):
	if i == N:
		if a == 0 or b == 0 or c == 0:
			return INF
		else:
			return abs(a - A) + abs(b - B) + abs(c - C)
	ans0 = dfs(i + 1, a, b, c)
	ans1 = dfs(i + 1, a + L[i], b, c) + (10 if a != 0 else 0)
	ans2 = dfs(i + 1, a, b + L[i], c) + (10 if b != 0 else 0)
	ans3 = dfs(i + 1, a, b, c + L[i]) + (10 if c != 0 else 0)
	ans = min(ans0, ans1, ans2, ans3)
	return ans

def main():
	print(dfs(0, 0, 0, 0))

def __starting_point():
	main()
__starting_point()


def to4(num):
	if num // 4 < 1:
		return str(num)
	else:
		return to4(num // 4) + str(num % 4)

def SyntheticKadomatsu():
	idata = list(map(int, input().split()))
	l = [int(input()) for _ in range(idata[0])]
	ans = float('inf')
	for i in range(4 ** idata[0]):
		bits = [0] * 4
		tmp = 0
		num = to4(i).zfill(idata[0])
		for j in range(idata[0]):
			v = int(num[-j - 1])
			if bits[v] != 0 and v != 3:
				tmp += 10
			bits[v] += l[j]
		if 0 in set(bits[:-1]):
			continue
		for j in range(3):
			tmp += abs(bits[j] - idata[j + 1])
		ans = min(ans, tmp)
	print(ans)

def __starting_point():
	SyntheticKadomatsu()
__starting_point()


(N, *T) = map(int, input().split())
L = [int(input()) for i in range(N)]
ans = 3000
for x in range(4 ** N):
	l = [0] * 4
	t = [0] * 4
	n = 4
	i = 0
	for i in range(N):
		l[x % n] += L[i]
		t[x % n] += 1
		x //= n
	if 0 in l[:3]:
		continue
	cost = 0
	for i in range(3):
		cost += (t[i] - 1) * 10
		cost += abs(l[i] - T[i])
	ans = min(ans, cost)
print(ans)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def bamboo(count, a, b, c):
	if count == N:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return INF
	rot0 = bamboo(count + 1, a, b, c)
	rot1 = bamboo(count + 1, a + l[count], b, c) + 10
	rot2 = bamboo(count + 1, a, b + l[count], c) + 10
	rot3 = bamboo(count + 1, a, b, c + l[count]) + 10
	return min(rot0, rot1, rot2, rot3)
print(bamboo(0, 0, 0, 0))


from itertools import product
(N, *T) = map(int, input().split())
L = [int(input()) for i in range(N)]
ans = 3000
for x in product([0, 1, 2, 3], repeat=N):
	cost = 0
	l = [0] * 4
	for (i, v) in enumerate(x):
		l[v] += L[i]
		if v < 3:
			cost += 10
	if 0 in l[:3]:
		continue
	cost -= 30
	for i in range(3):
		cost += abs(l[i] - T[i])
	ans = min(ans, cost)
print(ans)


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]

def dfs(i, x, y, z):
	if i == n:
		return abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(x, y, z) > 0 else 10 ** 9
	return min(dfs(i + 1, x, y, z), dfs(i + 1, x + l[i], y, z) + 10, dfs(i + 1, x, y + l[i], z) + 10, dfs(i + 1, x, y, z + l[i]) + 10)
print(dfs(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
L = []
r = 10000
for i in range(n):
	l = int(input())
	L.append(l)

def k(i, a, b, c, s):
	global r
	if i == n:
		if a != A and b != B and (c != C):
			s += abs(a) + abs(b) + abs(c) - 30
			r = min(r, s)
	else:
		k(i + 1, a - L[i], b, c, s + 10)
		k(i + 1, a, b - L[i], c, s + 10)
		k(i + 1, a, b, c - L[i], s + 10)
		k(i + 1, a, b, c, s)
a = A
b = B
c = C
k(0, a, b, c, 0)
print(r)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else float('inf')
	r1 = dfs(cur + 1, a, b, c)
	r2 = dfs(cur + 1, a + l[cur], b, c) + 10
	r3 = dfs(cur + 1, a, b + l[cur], c) + 10
	r4 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(r1, r2, r3, r4)
print(dfs(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]

def dfs(x, y, z, now):
	if now == n:
		return abs(x - a) + abs(y - b) + abs(z - c) - 30 if not 0 in (x, y, z) else 3000
	usea = dfs(x + l[now], y, z, now + 1) + 10
	useb = dfs(x, y + l[now], z, now + 1) + 10
	usec = dfs(x, y, z + l[now], now + 1) + 10
	nouse = dfs(x, y, z, now + 1)
	return min(usea, useb, usec, nouse)
print(dfs(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
l = list([int(input()) for _ in range(n)])
big = 10 ** 9

def dp(cur, a, b, c):
	if cur == n:
		if a == 0 or b == 0 or c == 0:
			return big
		else:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
	else:
		ret0 = dp(cur + 1, a, b, c)
		ret1 = dp(cur + 1, a + l[cur], b, c) + 10
		ret2 = dp(cur + 1, a, b + l[cur], c) + 10
		ret3 = dp(cur + 1, a, b, c + l[cur]) + 10
		return min([ret0, ret1, ret2, ret3])
ret = dp(0, 0, 0, 0)
print(ret)


(N, A, B, C) = map(int, input().split())
L = [0] * N
for i in range(N):
	L[i] = int(input())

def calc(m):
	s = [0, 0, 0, 0]
	sy = -3
	for i in range(N):
		s[m % 4] += L[i]
		if m % 4 != 0:
			sy += 1
		m = m // 4
	for i in range(1, 4):
		if s[i] == 0:
			return 10 ** 9
	return abs(A - s[1]) + abs(B - s[2]) + abs(C - s[3]) + sy * 10
ans = 10 ** 9
for i in range(pow(4, N)):
	ans = min(ans, calc(i))
print(ans)


(n, A, B, C) = map(int, input().split())
Q = [int(input()) for ii in range(n)]
inf = 10 ** 15

def dfs(now, a, b, c):
	if now == n:
		return abs(a - A) + abs(b - B) + abs(c - C) if 0 not in [a, b, c] else inf
	q1 = dfs(now + 1, a, b, c)
	q2 = dfs(now + 1, a + Q[now], b, c) + 10
	q3 = dfs(now + 1, a, b + Q[now], c) + 10
	q4 = dfs(now + 1, a, b, c + Q[now]) + 10
	return min(q1, q2, q3, q4)
print(dfs(0, 0, 0, 0) - 30)


import sys
sys.setrecursionlimit(10 ** 7)
(n, A, B, C) = map(int, input().split())
L_ls = [int(input()) for _ in range(n)]

def dfs(i, a, b, c):
	if i == n:
		if a == 0 or b == 0 or c == 0:
			return float('inf')
		else:
			return abs(a - A) + abs(b - B) + abs(c - C)
	Min = dfs(i + 1, a, b, c)
	if a == 0:
		Min = min(Min, dfs(i + 1, a + L_ls[i], b, c))
	else:
		Min = min(Min, dfs(i + 1, a + L_ls[i], b, c) + 10)
	if b == 0:
		Min = min(Min, dfs(i + 1, a, b + L_ls[i], c))
	else:
		Min = min(Min, dfs(i + 1, a, b + L_ls[i], c) + 10)
	if c == 0:
		Min = min(Min, dfs(i + 1, a, b, c + L_ls[i]))
	else:
		Min = min(Min, dfs(i + 1, a, b, c + L_ls[i]) + 10)
	return Min
print(dfs(0, 0, 0, 0))


import itertools
(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]
li = [0, 1, 2, 3]
it = list(itertools.product(li, repeat=n))
it = [i for i in it if 0 in i and 1 in i and (2 in i)]
INF = 100000007
ans = INF
for i in it:
	tmp = -30
	l_tmp = [0, 0, 0, 0]
	for j in range(n):
		l_tmp[i[j]] += l[j]
		if i[j] != 3:
			tmp += 10
	tmp = tmp + abs(l_tmp[0] - a) + abs(l_tmp[1] - b) + abs(l_tmp[2] - c)
	if tmp < ans:
		ans = tmp
print(ans)


s = list(map(int, input().split()))
n = s[0]
a = s[1:]
l = [int(input()) for i in range(n)]
num = 4 ** n
ans = 1000000000
for i in range(num):
	t = i
	use = [[] for _ in range(4)]
	for j in range(n):
		use[t % 4].append(l[j])
		t //= 4
	cost = 0
	for j in range(3):
		if len(use[j]) == 0:
			cost = 100000000000
		else:
			cost += (len(use[j]) - 1) * 10 + abs(sum(use[j]) - a[j])
	ans = min(ans, cost)
print(ans)


(n, a, b, c) = list(map(int, input().split()))
l = [int(input()) for i in range(n)]

def dfs(cur, ta, tb, tc):
	if cur == n:
		if ta <= 0 or tb <= 0 or tc <= 0:
			return 1000000000.0
		else:
			return abs(a - ta) + abs(b - tb) + abs(c - tc) - 30
	t1 = dfs(cur + 1, ta, tb, tc)
	t2 = dfs(cur + 1, ta + l[cur], tb, tc) + 10
	t3 = dfs(cur + 1, ta, tb + l[cur], tc) + 10
	t4 = dfs(cur + 1, ta, tb, tc + l[cur]) + 10
	return min(t1, t2, t3, t4)
print(dfs(0, 0, 0, 0))


A = [0, 0, 0]
(N, A[0], A[1], A[2]) = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = 10 ** 9
for i in range(4 ** N):
	G = [[] for _ in range(4)]
	for j in range(N):
		G[i // 4 ** j % 4].append(L[j])
	mp = 0
	for j in range(3):
		if len(G[j]) == 0:
			mp = 10 ** 9
			break
		mp += (len(G[j]) - 1) * 10
		mp += abs(sum(G[j]) - A[j])
	ans = min(ans, mp)
print(ans)


(n, a, b, c, *L) = map(int, open(0).read().split())
L.sort(reverse=True)
from itertools import product
from copy import deepcopy
li1 = [4, 1, 2, 3]
ans = 10 ** 10
for v in product(li1, repeat=n):
	num = 0
	(A, B, C, NO) = ([], [], [], [])
	for i in range(n):
		if v[i] == 1:
			A.append(L[i])
		elif v[i] == 2:
			B.append(L[i])
		elif v[i] == 3:
			C.append(L[i])
		elif v[i] == 4:
			NO.append(L[i])
	if A and B and C:
		num += abs(sum(A) - a) + max(0, (len(A) - 1) * 10) + abs(sum(B) - b) + max(0, (len(B) - 1) * 10) + abs(sum(C) - c) + max(0, (len(C) - 1) * 10)
		ans = min(ans, num)
print(ans)


(n, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(n)]
inf = 10 ** 9

def dfs(t, a, b, c):
	if t == n:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return inf
	ret0 = dfs(t + 1, a, b, c)
	ret1 = dfs(t + 1, a + l[t], b, c) + 10
	ret2 = dfs(t + 1, a, b + l[t], c) + 10
	ret3 = dfs(t + 1, a, b, c + l[t]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


import sys
sys.setrecursionlimit(1000000000)
INF = 10 ** 9
(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]

def dfs(i, x, y, z):
	if i == n:
		if min(x, y, z) > 0:
			return abs(x - a) + abs(y - b) + abs(z - c) - 30
		else:
			return INF
	ans = dfs(i + 1, x, y, z)
	ant = dfs(i + 1, x + l[i], y, z) + 10
	anu = dfs(i + 1, x, y + l[i], z) + 10
	anv = dfs(i + 1, x, y, z + l[i]) + 10
	return min(ans, ant, anu, anv)
print(dfs(0, 0, 0, 0))


from itertools import product
(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
ans = min((sum((abs(sum((x for (k, x) in zip(p, l) if k == r)) - y) + 10 * (p.count(r) - 1) for (r, y) in enumerate((A, B, C), 1))) for p in product(range(4), repeat=N) if {1, 2, 3} <= set(p)))
print(ans)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9 + 7

def dfs(count, a, b, c):
	if count == N:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return INF
	non = dfs(count + 1, a, b, c)
	useA = dfs(count + 1, a + l[count], b, c) + 10
	useB = dfs(count + 1, a, b + l[count], c) + 10
	useC = dfs(count + 1, a, b, c + l[count]) + 10
	return min(non, useA, useB, useC)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]

def dfs(num, a, b, c):
	if N == num:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) >= 1 else 10 ** 10
	ret = []
	ret.append(dfs(num + 1, a, b, c))
	ret.append(dfs(num + 1, a + l[num], b, c) + 10)
	ret.append(dfs(num + 1, a, b + l[num], c) + 10)
	ret.append(dfs(num + 1, a, b, c + l[num]) + 10)
	return min(ret)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def search(now, a, b, c):
	if now == N:
		return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else INF
	MP0 = search(now + 1, a, b, c)
	MP1 = search(now + 1, a + l[now], b, c) + 10
	MP2 = search(now + 1, a, b + l[now], c) + 10
	MP3 = search(now + 1, a, b, c + l[now]) + 10
	return min(MP0, MP1, MP2, MP3)
print(search(0, 0, 0, 0) - 30)


from itertools import product
(N, *P) = map(int, input().split())
L = []
for _ in range(N):
	L.append(int(input()))
res = []
for p in product((0, 1, 2, 3), repeat=N):
	tmp = [0] * 4
	cnt = [0] * 4
	for i in range(N):
		tmp[p[i]] += L[i]
		cnt[p[i]] += 1
	if cnt[1] >= 1 and cnt[2] >= 1 and (cnt[3] >= 1):
		res.append(sum((abs(tmp[i] - P[i - 1]) + (cnt[i] - 1) * 10 for i in range(1, 4))))
print(min(res))


def main():
	(N, A, B, C) = list(map(int, input().split()))
	ls = [None] * N
	for i in range(N):
		ls[i] = int(input())
	abc_mp = []

	def rec(i, a, b, c, mp, ls):
		if i == len(ls):
			if a > 0 and b > 0 and (c > 0):
				abc_mp.append([a, b, c, mp - 30])
		else:
			rec(i + 1, a + ls[i], b, c, mp + 10, ls)
			rec(i + 1, a, b + ls[i], c, mp + 10, ls)
			rec(i + 1, a, b, c + ls[i], mp + 10, ls)
			rec(i + 1, a, b, c, mp, ls)
	rec(0, 0, 0, 0, 0, ls)
	(a0, b0, c0, mp0) = abc_mp[0]
	ans = mp0 + abs(A - a0) + abs(B - b0) + abs(C - c0)
	for (a, b, c, mp) in abc_mp:
		cand = mp + abs(A - a) + abs(B - b) + abs(C - c)
		if cand < ans:
			ans = cand
	return ans
print(main())


(N, A, B, C) = map(int, input().split())
ls = [int(input()) for i in range(N)]

def func(pos, a, b, c):
	return abs(a - A) + abs(b - B) + abs(c - C) - 30 + 9999 * max(0, 1 - a * b * c) if pos == N else min((func(pos + 1, a + ls[pos] * (i == 0), b + ls[pos] * (i == 1), c + ls[pos] * (i == 2)) + 10 * (i < 3) for i in range(4)))
print(func(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
l = list((int(input()) for _ in range(n)))

def dfs(depth, a, b, c):
	if depth == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10 ** 9
	x = dfs(depth + 1, a, b, c)
	y = dfs(depth + 1, a + l[depth], b, c) + 10
	z = dfs(depth + 1, a, b + l[depth], c) + 10
	w = dfs(depth + 1, a, b, c + l[depth]) + 10
	return min(x, y, z, w)
print(dfs(0, 0, 0, 0))


def B10N(X, B):
	if X // B != 0:
		return B10N(X // B, B) + str(X % B)
	return str(X % B)
(N, A, B, C) = (int(X) for X in input().split())
Li = [int(input()) for X in range(0, N)]
CostM = pow(10, 9)
for T in range(0, pow(4, N)):
	Cho = list(B10N(T, 4).zfill(N))
	if Cho.count('1') > 0 and Cho.count('2') > 0 and (Cho.count('3') > 0):
		Cost = 0
		ALi = [Li[X] for (X, Y) in enumerate(Cho) if Y == '1']
		BLi = [Li[X] for (X, Y) in enumerate(Cho) if Y == '2']
		CLi = [Li[X] for (X, Y) in enumerate(Cho) if Y == '3']
		SyC = (len(ALi) + len(BLi) + len(CLi) - 3) * 10
		LeC = abs(sum(ALi) - A) + abs(sum(BLi) - B) + abs(sum(CLi) - C)
		if SyC + LeC < CostM:
			CostM = SyC + LeC
print(CostM)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
	if cur == N:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return INF
	res0 = dfs(cur + 1, a, b, c)
	res1 = dfs(cur + 1, a + l[cur], b, c) + 10
	res2 = dfs(cur + 1, a, b + l[cur], c) + 10
	res3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(res0, res1, res2, res3)
print(dfs(0, 0, 0, 0))


from itertools import product
p = 4
(n, a, b, c) = map(int, input().split())
banboo = [0] * n
for i in range(n):
	banboo[i] = int(input())
Bit_4 = list(product(range(p), repeat=n))
ans = 10 ** 6
for Bi in Bit_4:
	tmp = [0] * 4
	magic = 0
	if 1 in Bi and 2 in Bi and (3 in Bi):
		for i in range(n):
			tmp[Bi[i]] += banboo[i]
			if tmp[Bi[i]] != banboo[i] and Bi[i] != 0:
				magic += 10
		magic += abs(tmp[1] - a)
		magic += abs(tmp[2] - b)
		magic += abs(tmp[3] - c)
		ans = min(magic, ans)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(N)]

def f(a, b, c, k):
	if k == N:
		if not a or not b or (not c):
			return 10 ** 9
		return abs(a - A) + abs(b - B) + abs(c - C) - 30
	ans0 = f(a, b, c, k + 1)
	ans1 = f(a + L[k], b, c, k + 1) + 10
	ans2 = f(a, b + L[k], c, k + 1) + 10
	ans3 = f(a, b, c + L[k], k + 1) + 10
	return min(ans0, ans1, ans2, ans3)
print(f(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
X = [0, A, B, C]
L = [int(input()) for i in range(N)]
d = 4 ** N
ans = float('inf')
for i in range(d):
	F = [0 for i in range(4)]
	cnt = [0 for i in range(4)]
	for j in range(N):
		F[i % 4] += L[j]
		cnt[i % 4] += 1
		i //= 4
	p = True
	for k in range(1, 4):
		if F[k] == 0:
			p = False
			break
	tmp = 0
	if p:
		for k in range(1, 4):
			tmp += cnt[k] * 10 + abs(X[k] - F[k]) - 10
		ans = min(ans, tmp)
print(ans)


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

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

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	(n, A, B, C) = i_map()
	l = [i_input() for i in range(n)]

	def dfs(cur, a, b, c):
		if cur == n:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
		ret0 = dfs(cur + 1, a, b, c)
		ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
		ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
		ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
		return min(ret0, ret1, ret2, ret3)
	print(dfs(0, 0, 0, 0))

def __starting_point():
	main()
__starting_point()


(N, A, B, C) = map(int, input().split())
T = [int(input()) for i in range(N)]
INF = 10 ** 15

def solve(n, a, b, c):
	if n == N:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return INF
	else:
		ret0 = solve(n + 1, a, b, c)
		ret1 = solve(n + 1, a + T[n], b, c) + 10
		ret2 = solve(n + 1, a, b + T[n], c) + 10
		ret3 = solve(n + 1, a, b, c + T[n]) + 10
		return min(ret0, ret1, ret2, ret3)
print(solve(0, 0, 0, 0))


def main():
	(n, *target) = list(map(int, input().split()))
	l = [int(input()) for _ in range(n)]
	ans = float('inf')
	base = 4
	for i in range(pow(base, n)):
		now_l = [0] * base
		add = [0] * base
		now = i
		for j in range(n):
			now_l[now % base] += l[j]
			add[now % base] += 1
			now //= base
		if 0 in now_l[:base - 1]:
			continue
		now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
		ans = min(ans, now_ans)
	print(0 if all((t in l for t in target)) else ans)

def __starting_point():
	main()
__starting_point()


(N, A, B, C) = list(map(int, input().split()))
l = []
Inf = float('Inf')
for i in range(N):
	l.append(int(input()))

def Answer(cnt, a, b, c):
	if cnt == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else Inf
	pt1 = Answer(cnt + 1, a, b, c)
	pt2 = Answer(cnt + 1, a + l[cnt], b, c) + 10
	pt3 = Answer(cnt + 1, a, b + l[cnt], c) + 10
	pt4 = Answer(cnt + 1, a, b, c + l[cnt]) + 10
	return min(pt1, pt2, pt3, pt4)
print(Answer(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 1 << 20

def perm(n, a, b, c):
	if n == N:
		if all([a, b, c]):
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return INF
	return min(perm(n + 1, a, b, c), perm(n + 1, a + l[n], b, c) + 10, perm(n + 1, a, b + l[n], c) + 10, perm(n + 1, a, b, c + l[n]) + 10)
print(perm(0, 0, 0, 0))


(N, A, B, C) = [int(i) for i in input().split()]
l = []
for i in range(N):
	l.append(int(input()))

def magic(cur, a, b, c):
	if cur == N:
		if a * b * c != 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return 10 ** 9
	r0 = magic(cur + 1, a, b, c)
	r1 = magic(cur + 1, a + l[cur], b, c) + 10
	r2 = magic(cur + 1, a, b + l[cur], c) + 10
	r3 = magic(cur + 1, a, b, c + l[cur]) + 10
	return min(r0, r1, r2, r3)
print(magic(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]

def dfs(i, a, b, c, x):
	if i == N:
		return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (x - 3) if a * b * c != 0 else 10 ** 9
	ret1 = dfs(i + 1, a, b, c, x)
	ret2 = dfs(i + 1, a + l[i], b, c, x + 1)
	ret3 = dfs(i + 1, a, b + l[i], c, x + 1)
	ret4 = dfs(i + 1, a, b, c + l[i], x + 1)
	return min(ret1, ret2, ret3, ret4)
print(dfs(0, 0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
tree = [a, b, c]
ls = [int(input()) for _ in range(n)]
ans = 10000
for i in range(4 ** n):
	group = [[] for _ in range(4)]
	for j in range(n):
		(k, i) = (i % 4, i // 4)
		group[k].append(ls[j])
	buf = 0
	for l in range(3):
		group_len = len(group[l])
		if group_len == 0:
			buf = 10000
			break
		buf += (group_len - 1) * 10 + abs(sum(group[l]) - tree[l])
	ans = min(ans, buf)
print(ans)


from itertools import *
(n, a, b, c, *l) = map(int, open(0).read().split())
a = (a, b, c)
m = 10 ** 18
for s in product(*[range(4)] * n):
	if all((i in s for i in (0, 1, 2))):
		(t, c) = ([0] * 4, [0] * 4)
		for (i, v) in zip(s, l):
			t[i] += v
			c[i] += 1
		m = min(m, sum((abs(x - y) + ~-z * 10 for (x, y, z) in zip(a, t, c))))
print(m)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(N)]

def f(i, a, b, c):
	if i == N:
		if min(a, b, c) <= 0:
			return 10 ** 9
		return abs(a - A) + abs(b - B) + abs(c - C) - 30
	costx = f(i + 1, a, b, c)
	costA = f(i + 1, a + L[i], b, c) + 10
	costB = f(i + 1, a, b + L[i], c) + 10
	costC = f(i + 1, a, b, c + L[i]) + 10
	return min(costx, costA, costB, costC)
print(f(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]

def dfs(cur, q, w, e):
	if cur == n:
		return abs(a - q) + abs(b - w) + abs(c - e) - 30 if min(q, w, e) != 0 else 10 ** 18
	return min(dfs(cur + 1, q + l[cur], w, e) + 10, dfs(cur + 1, q, w + l[cur], e) + 10, dfs(cur + 1, q, w, e + l[cur]) + 10, dfs(cur + 1, q, w, e))
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
ans = float('inf')
for i in range(4 ** N):
	(a, b, c) = ([], [], [])
	cost = 0
	for j in range(N):
		r = i // 4 ** j % 4
		if r == 1:
			a.append(l[j])
		elif r == 2:
			b.append(l[j])
		elif r == 3:
			c.append(l[j])
	if a and b and c:
		cost += sum((max(len(x) - 1, 0) * 10 for x in [a, b, c]))
		a = sum(a)
		b = sum(b)
		c = sum(c)
		cost += sum((abs(x - y) for (x, y) in [(a, A), (b, B), (c, C)]))
		ans = min(ans, cost)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
INF = 10 ** 8

def dfs(n, a, b, c):
	if n == N:
		if a * b * c > 0:
			ret = abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			ret = INF
	else:
		ret = dfs(n + 1, a, b, c)
		reta = dfs(n + 1, a + L[n], b, c) + 10
		retb = dfs(n + 1, a, b + L[n], c) + 10
		retc = dfs(n + 1, a, b, c + L[n]) + 10
		ret = min(ret, reta, retb, retc)
	return ret
print(dfs(0, 0, 0, 0))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()
(n, a, b, c) = LI()
l = [I() for _ in range(n)]
answer = inf

def f(lst, ind):
	nonlocal answer
	if ind == n:
		ac = lst.count(1)
		bc = lst.count(2)
		cc = lst.count(3)
		if ac == 0 or bc == 0 or cc == 0:
			return min(answer, inf)
		_a = _b = _c = 0
		for (i, x) in enumerate(lst):
			if x == 1:
				_a += l[i]
			elif x == 2:
				_b += l[i]
			elif x == 3:
				_c += l[i]
		sm = 0
		sm += max(0, ac - 1) * 10
		sm += max(0, bc - 1) * 10
		sm += max(0, cc - 1) * 10
		sm += abs(a - _a)
		sm += abs(b - _b)
		sm += abs(c - _c)
		return min(answer, sm)
	else:
		for i in range(4):
			lst[ind] = i
			answer = min(answer, f(lst, ind + 1))
	return answer
lst = [-1] * n
print(f(lst, 0))


from itertools import product as p
(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
ans = 10 ** 12
for i in p(range(4), repeat=N):
	if not (i.count(1) >= 1 and i.count(2) >= 1 and (i.count(3) >= 1)):
		continue
	(a, b, c) = (0, 0, 0)
	cost = 0
	tt = N - i.count(0)
	for (k, j) in enumerate(i):
		if j == 1:
			a += l[k]
		elif j == 2:
			b += l[k]
		elif j == 3:
			c += l[k]
	cost = abs(a - A) + abs(b - B) + abs(c - C)
	cost += 10 * (tt - 3)
	ans = min(ans, cost)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(N)]

def dfs(x, a, b, c):
	if x == N:
		if min(a, b, c) > 0:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
		else:
			return 1000000000.0 + 7
	ret0 = dfs(x + 1, a, b, c)
	ret1 = dfs(x + 1, a + L[x], b, c) + 10
	ret2 = dfs(x + 1, a, b + L[x], c) + 10
	ret3 = dfs(x + 1, a, b, c + L[x]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = []
for _ in range(n):
	lt = int(input())
	l.append(lt)
from itertools import product
count = 10 ** 10
for i in product([0, 1, 2, 3], repeat=n):
	if i.count(0) >= 1 and i.count(2) >= 1 and (i.count(1) >= 1):
		temp = 0
		at = 0
		bt = 0
		ct = 0
		for j in range(n):
			if i[j] == 0:
				at += l[j]
				temp += 1
			elif i[j] == 1:
				bt += l[j]
				temp += 1
			elif i[j] == 2:
				ct += l[j]
				temp += 1
		count = min(count, abs(a - at) + abs(b - bt) + abs(c - ct) + 10 * (temp - 3))
print(count)


(N, A, B, C) = map(int, input().split())
L = [A, B, C]
l = []
for n in range(N):
	l.append(int(input()))
mp = []
for i in range(4 ** N):
	Test = [0, 0, 0]
	MP = 0
	for j in range(N):
		n = i % 4
		if n < 3:
			MP += 10 if Test[n] else 0
			Test[n] += l[j]
		i >>= 2
	for i in range(3):
		MP += abs(L[i] - Test[i]) if Test[i] else 3000
	mp.append(MP)
print(min(mp))


(n, a, b, c) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))
ans = 10 ** 9
for ci in range(4 ** n):
	ci_ = [-1] * n
	cnt = [0] * 3
	(ca, cb, cc) = (0, 0, 0)
	for cj in range(n):
		cx = ci & 3
		if cx == 0:
			ca += l[cj]
			cnt[0] += 1
		elif cx == 1:
			cb += l[cj]
			cnt[1] += 1
		elif cx == 2:
			cc += l[cj]
			cnt[2] += 1
		ci >>= 2
	if ca == 0 or cb == 0 or cc == 0:
		continue
	cost = 0
	for i in range(3):
		if cnt[i] > 1:
			cost += 10 * (cnt[i] - 1)
	cost += abs(a - ca) + abs(b - cb) + abs(c - cc)
	ans = min(ans, cost)
print(ans)


(n, A, B, C) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))

def dfs(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10 ** 12
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


from collections import Counter
import itertools
(N, A, B, C) = map(int, input().split())
l = []
for i in range(N):
	l.append(int(input()))
ans = float('inf')
for item in itertools.product(range(4), repeat=N):
	c = Counter(item)
	if c[0] == 0 or c[1] == 0 or c[2] == 0:
		continue
	d = [0, 0, 0, 0]
	for i in range(N):
		d[item[i]] += l[i]
	kans = abs(A - d[0]) + abs(B - d[1]) + abs(C - d[2]) + 10 * (c[0] + c[1] + c[2] - 3)
	ans = min(ans, kans)
print(ans)


(N, A, B, C) = list(map(int, input().split()))
data = [int(input()) for i in range(N)]
INF = 10 ** 11

def magic(i, a, b, c):
	if i == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min([a, b, c]) > 0 else INF
	ret0 = magic(i + 1, a, b, c)
	ret1 = magic(i + 1, a + data[i], b, c) + 10
	ret2 = magic(i + 1, a, b + data[i], c) + 10
	ret3 = magic(i + 1, a, b, c + data[i]) + 10
	return min([ret0, ret1, ret2, ret3])
print(magic(0, 0, 0, 0))


import sys
input = sys.stdin.readline
(n, a, b, c) = map(int, input().split())
la = [a, b, c]
lt = [int(input()) for i in range(n)]
import itertools as it
ans = 3000
for p in it.product(range(4), repeat=n):
	ll = [0] * 4
	lc = [0] * 4
	for i in range(n):
		ll[p[i]] += lt[i]
		lc[p[i]] += 1
	if lc[0] * lc[1] * lc[2] > 0:
		mp = 10 * (sum(lc[:3]) - 3) + sum((abs(ll[i] - la[i]) for i in range(3)))
		ans = min(ans, mp)
print(ans)


(N, A, B, C) = map(int, input().split())
list = [int(input()) for _ in range(N)]

def dfs(cnt, a, b, c):
	if cnt == N:
		return abs(A - a) + abs(B - b) + abs(C - c) if min(a, b, c) > 0 else 10 ** 9
	l = dfs(cnt + 1, a, b, c)
	la = dfs(cnt + 1, a + list[cnt], b, c) + (10 if a != 0 else 0)
	lb = dfs(cnt + 1, a, b + list[cnt], c) + (10 if b != 0 else 0)
	lc = dfs(cnt + 1, a, b, c + list[cnt]) + (10 if c != 0 else 0)
	return min(l, la, lb, lc)
print(dfs(0, 0, 0, 0))


import itertools
(n, a, b, c) = list(map(int, input().split()))
nums = [int(input()) for _ in range(n)]
ans = 10 ** 10
for usage_info in itertools.product(list(range(4)), repeat=n):
	mp = 0
	length = [0, 0, 0]
	for (idx, usage) in enumerate(usage_info):
		if usage == 3:
			continue
		if length[usage] > 0:
			mp += 10
		length[usage] += nums[idx]
	if min(length) == 0:
		continue
	mp += abs(length[0] - a) + abs(length[1] - b) + abs(length[2] - c)
	ans = min(ans, mp)
print(ans)


(n, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(n)]
r = 10 ** 5

def dsf(i, a, b, c, p):
	global r
	if i == n:
		if a != 0 and b != 0 and (c != 0):
			p += abs(A - a) + abs(B - b) + abs(C - c) - 30
			r = min(r, p)
		return
	dsf(i + 1, a + L[i], b, c, p + 10)
	dsf(i + 1, a, b + L[i], c, p + 10)
	dsf(i + 1, a, b, c + L[i], p + 10)
	dsf(i + 1, a, b, c, p)
dsf(0, 0, 0, 0, 0)
print(r)


import copy
from itertools import combinations
import sys
input = sys.stdin.readline
(N, A, B, C) = (int(i) for i in input().split())
l = [0] * N
for i in range(N):
	l[i] = int(input())
mp = []
for na in range(1, N - 1):
	for ja in combinations(l, na):
		l_b = copy.copy(l)
		for i2 in ja:
			if i2 in l_b:
				l_b.remove(i2)
		for nb in range(1, N):
			for jb in combinations(l_b, nb):
				l_c = copy.copy(l_b)
				for i3 in jb:
					if i3 in l_c:
						l_c.remove(i3)
				for nc in range(1, N + 1):
					for jc in combinations(l_c, nc):
						AA = abs(A - sum(ja)) + 10 * (na - 1)
						BB = abs(B - sum(jb)) + 10 * (nb - 1)
						CC = abs(C - sum(jc)) + 10 * (nc - 1)
						mp.append(AA + BB + CC)
print(min(mp))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 1 << 20
score = INF
import itertools
for ms in itertools.product(range(-1, 3), repeat=N):
	lens = [0] * 3
	tmp_score = -30
	for (i, group) in enumerate(ms):
		if group >= 0:
			lens[group] += l[i]
			tmp_score += 10
	if all(lens):
		score = min(score, tmp_score + abs(lens[0] - A) + abs(lens[1] - B) + abs(lens[2] - C))
print(score)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(N)]

def dps(a, b, c, index):
	if index == N:
		return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) != 0 else float('infinity')
	take = L[index]
	mp1 = dps(a, b, c, index + 1)
	mp2 = dps(a + take, b, c, index + 1) + 10
	mp3 = dps(a, b + take, c, index + 1) + 10
	mp4 = dps(a, b, c + take, index + 1) + 10
	return min(mp1, mp2, mp3, mp4)
print(dps(0, 0, 0, 0) - 30)


from itertools import product
(N, *ABC) = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = float('inf')
for prod in product(range(4), repeat=N):
	abc = [0] * 3
	mp = -30
	for (p, l) in zip(prod, L):
		if p != 3:
			abc[p] += l
			mp += 10
	if abc[0] and abc[1] and abc[2]:
		mp += sum(map(lambda x, y: abs(x - y), ABC, abc))
		ans = min(ans, mp)
print(ans)


(N, A, B, C) = list(map(int, input().split()))
L = [int(input()) for _ in range(N)]

def rec(itr, a, b, c, mp):
	if itr == N:
		if a == 0 or b == 0 or c == 0:
			return 10 ** 9
		return abs(a - A) + abs(b - B) + abs(c - C) + mp - 30
	res = rec(itr + 1, a, b, c, mp)
	res = min(res, rec(itr + 1, a + L[itr], b, c, mp) + 10)
	res = min(res, rec(itr + 1, a, b + L[itr], c, mp) + 10)
	res = min(res, rec(itr + 1, a, b, c + L[itr], mp) + 10)
	return res
print(rec(0, 0, 0, 0, 0))


from itertools import product
(n, a, b, c) = list(map(int, input().split()))
l = [int(input()) for _ in range(n)]
ans = 1001001001
for x in product(list(range(4)), repeat=n):
	s = [0] * 4
	t = -3
	for i in range(n):
		t += x[i] < 3
		s[x[i]] += l[i]
	s.pop()
	if 0 in s:
		continue
	ans = min(ans, t * 10 + abs(s[0] - a) + abs(s[1] - b) + abs(s[2] - c))
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
ans = float('inf')
for a in range(1 << N):
	at = []
	for i in range(N):
		if a & 1 << i:
			at.append(L[i])
	if not at:
		continue
	ap = 10 * (len(at) - 1) + abs(A - sum(at))
	for b in range(1 << N):
		if a & b:
			continue
		bt = []
		for i in range(N):
			if b & 1 << i:
				bt.append(L[i])
		if not bt:
			continue
		bp = 10 * (len(bt) - 1) + abs(B - sum(bt))
		for c in range(1 << N):
			if a & c or b & c:
				continue
			ct = []
			for i in range(N):
				if c & 1 << i:
					ct.append(L[i])
			if not ct:
				continue
			cp = 10 * (len(ct) - 1) + abs(C - sum(ct))
			ans = min(ans, ap + bp + cp)
print(ans)


import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal

def s():
	return input()

def i():
	return int(input())

def S():
	return input().split()

def I():
	return map(int, input().split())

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

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

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 9
mod = 10 ** 9 + 7
(N, A, B, C) = I()
l = [i() for _ in range(N)]

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


(n, A, B, C) = map(int, input().split())
l = []
for _ in range(n):
	l.append(int(input()))

def solve(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else float('INF')
	ret0 = solve(cur + 1, a, b, c)
	ret1 = solve(cur + 1, a + l[cur], b, c) + 10
	ret2 = solve(cur + 1, a, b + l[cur], c) + 10
	ret3 = solve(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(solve(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 4

def dfs(cur, a, b, c):
	if cur == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
	else:
		cost0 = dfs(cur + 1, a, b, c)
		cost1 = dfs(cur + 1, a + l[cur], b, c) + 10
		cost2 = dfs(cur + 1, a, b + l[cur], c) + 10
		cost3 = dfs(cur + 1, a, b, c + l[cur]) + 10
		return min(cost0, cost1, cost2, cost3)
print(dfs(0, 0, 0, 0))


from itertools import product
(n, *X) = map(int, input().split())
L = [int(input()) for _ in range(n)]
P = product(range(4), repeat=n)
ans = float('inf')
for i in P:
	cnt = [0] * 3
	length = [0] * 3
	for k in range(n):
		if i[k] == 3:
			continue
		cnt[i[k]] += 1
		length[i[k]] += L[k]
	if min(cnt) > 0:
		tmp = sum([abs(length[i] - X[i]) + 10 * (cnt[i] - 1) for i in range(3)])
		ans = min(ans, tmp)
print(ans)


(N, A, B, C) = map(int, input().split())
L = []
for _ in range(N):
	L.append(int(input()))

def rec(i, a, b, c):
	if i == N:
		if not a or not b or (not c):
			return float('inf')
		return abs(a - A) + abs(b - B) + abs(c - C)
	ret = rec(i + 1, a, b, c)
	ret = min(ret, rec(i + 1, a + L[i], b, c) + (10 if a else 0))
	ret = min(ret, rec(i + 1, a, b + L[i], c) + (10 if b else 0))
	ret = min(ret, rec(i + 1, a, b, c + L[i]) + (10 if c else 0))
	return ret
print(rec(0, 0, 0, 0))


from itertools import product
(n, *B) = map(int, input().split())
A = [int(input()) for i in range(n)]
s = 10 ** 9
for P in product([0, 1, 2, 3], repeat=n):
	if {0, 1, 2} <= set(P):
		m = [0, 0, 0]
		for (x, y) in zip(P, A):
			if x != 3:
				m[x] += y
		t = sum((abs(m - y) for (m, y) in zip(m, B)))
		l = sum((1 for j in P if j != 3)) - 3
		s = min(s, t + l * 10)
print(s)


(n, a, b, c) = [int(i) for i in input().split()]
ts = [a, b, c]
ls = []
for _ in range(n):
	ls.append(int(input()))
r = 10 ** 18
for i in range(4 ** n):
	xs = [[] for _ in range(4)]
	for j in range(n):
		(k, i) = (i % 4, i // 4)
		xs[k].append(ls[j])
	ir = 0
	for l in range(3):
		if len(xs[l]) == 0:
			ir = 10 ** 18
			break
		ir += 10 * (len(xs[l]) - 1) + abs(ts[l] - sum(xs[l]))
	r = min(r, ir)
print(r)


(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]
ans = float('inf')
for i in range(4 ** n):
	abc = [[] for i in range(4)]
	for j in range(n):
		abc[i % 4].append(l[j])
		i //= 4
	(A, B, C, x) = abc
	if len(A) == 0 or len(B) == 0 or len(C) == 0:
		continue
	ans = min(ans, abs(sum(A) - a) + abs(sum(B) - b) + abs(sum(C) - c) + (len(A) + len(B) + len(C) - 3) * 10)
print(ans)


(n, a, b, c) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))

def solve(w, x, y, z):
	if w == n:
		if min(x, y, z) > 0:
			return abs(x - a) + abs(y - b) + abs(z - c) - 30
		else:
			return 100000.0
	can0 = solve(w + 1, x, y, z)
	can1 = solve(w + 1, x + l[w], y, z) + 10
	can2 = solve(w + 1, x, y + l[w], z) + 10
	can3 = solve(w + 1, x, y, z + l[w]) + 10
	return min(can0, can1, can2, can3)
print(solve(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = list((int(input()) for _ in range(N)))
inf = 10 ** 9

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf
	re0 = dfs(cur + 1, a, b, c)
	re1 = dfs(cur + 1, a + l[cur], b, c) + 10
	re2 = dfs(cur + 1, a, b + l[cur], c) + 10
	re3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(re0, re1, re2, re3)
print(dfs(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))
m = [a, b, c]
ans = 4000
for i in range(4 ** n):
	p = [0] * n
	k = i
	for j in range(n):
		p[j] = k % 4
		k //= 4
	cost = [-1, -1, -1]
	q = [[] for _ in range(4)]
	for j in range(n):
		q[p[j]].append(l[j])
	for j in range(3):
		if len(q[j + 1]) != 0:
			cost[j] = 10 * (len(q[j + 1]) - 1) + abs(sum(q[j + 1]) - m[j])
	if cost[0] != -1 and cost[1] != -1 and (cost[2] != -1):
		ans = min(ans, cost[0] + cost[1] + cost[2])
print(ans)


from itertools import product
(n, *A) = map(int, input().split())
L = [int(input()) for _ in range(n)]
m_ = sum((abs(A[i] - L[i]) for i in range(3)))
for P in product(range(4), repeat=n):
	C = [[] for _ in range(4)]
	m = 0
	for i in range(n):
		C[P[i]].append(L[i])
	C = C[1:]
	if [] in C:
		continue
	for i in range(3):
		m += (len(C[i]) - 1) * 10 + abs(sum(C[i]) - A[i])
	m_ = min(m_, m)
print(m_)


(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]
import itertools
bumboo = ['A', 'B', 'C', 'D']
prod = list(itertools.product(bumboo, repeat=n))
temp = []
for i in prod:
	tempa = 0
	tempb = 0
	tempc = 0
	for j in range(n):
		if i[j] == 'A':
			tempa += l[j]
		elif i[j] == 'B':
			tempb += l[j]
		elif i[j] == 'C':
			tempc += l[j]
	if tempa * tempb * tempc == 0:
		pass
	else:
		temp.append(abs(tempa - a) + abs(tempb - b) + abs(tempc - c) + 10 * (n - 3 - i.count('D')))
print(min(temp))


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 10000
for i in range(2 ** (2 * n)):
	v = [0, 0, 0, 0]
	assign = [i >> 2 * j & 3 for j in range(n)]
	cost = 0
	for j in range(n):
		if assign[j] > 0 and v[assign[j]] > 0:
			cost += 10
		v[assign[j]] += l[j]
	if v[1] == 0 or v[2] == 0 or v[3] == 0:
		continue
	ans = min(ans, cost + abs(v[1] - a) + abs(v[2] - b) + abs(v[3] - c))
print(ans)


from itertools import product
(N, *ABC) = map(int, input().split())
L = [int(input()) for i in range(N)]
MP = 10 ** 9
for P in product([0, 1, 2, 3], repeat=N):
	if {0, 1, 2} <= set(P):
		m = [0, 0, 0]
		for (p, l) in zip(P, L):
			if p != 3:
				m[p] += l
		cost1 = sum((abs(m - l) for (m, l) in zip(m, ABC)))
		cost2 = sum((1 for i in P if i != 3)) - 3
		MP = min(MP, cost1 + cost2 * 10)
print(MP)


(n, a, b, c) = map(int, input().split())
bamboos = []
for i in range(n):
	bamboo = int(input())
	bamboos.append(bamboo)

def Base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy > 0:
		out = str(X_dumy % n) + out
		X_dumy = int(X_dumy / n)
	return out

def calc_score(group, target):
	score = 0
	if len(group) > 1:
		score += 10 * (len(group) - 1)
	length = sum(group)
	score += abs(length - target)
	return score
min_score = 10 ** 12
for i in range(4 ** n):
	num = Base_10_to_n(i, 4).zfill(n)
	score = 0
	group_A = []
	group_B = []
	group_C = []
	for j in range(n):
		if num[j] == '1':
			group_A.append(bamboos[j])
		elif num[j] == '2':
			group_B.append(bamboos[j])
		elif num[j] == '3':
			group_C.append(bamboos[j])
	if len(group_A) == 0 or len(group_B) == 0 or len(group_C) == 0:
		continue
	else:
		score += calc_score(group_A, a)
		score += calc_score(group_B, b)
		score += calc_score(group_C, c)
	if score < min_score:
		min_score = score
print(min_score)


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
inf = 10 ** 10

def mp(i, a, b, c):
	if i == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else inf
	mp0 = mp(i + 1, a, b, c)
	mp1 = mp(i + 1, a + l[i], b, c) + 10
	mp2 = mp(i + 1, a, b + l[i], c) + 10
	mp3 = mp(i + 1, a, b, c + l[i]) + 10
	return min(mp0, mp1, mp2, mp3)
print(mp(0, 0, 0, 0))


import sys
from itertools import product
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, *A) = list(map(int, readline().split()))
	(*L,) = list(map(int, read().split()))
	ans = INF
	for p in product(list(range(4)), repeat=N):
		num = [0] * 3
		length = [0] * 3
		for (i, j) in enumerate(p):
			if j < 3:
				num[j] += 1
				length[j] += L[i]
		res = 0
		for j in range(3):
			if num[j] == 0:
				res = INF
				break
			else:
				res += (num[j] - 1) * 10 + abs(length[j] - A[j])
		if ans > res:
			ans = res
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


import sys
from itertools import product
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, A, B, C) = list(map(int, readline().split()))
	(*L,) = list(map(int, read().split()))

	def rec(i, a, b, c):
		if i == N:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
		res0 = rec(i + 1, a, b, c)
		res1 = rec(i + 1, a + L[i], b, c) + 10
		res2 = rec(i + 1, a, b + L[i], c) + 10
		res3 = rec(i + 1, a, b, c + L[i]) + 10
		return min(res0, res1, res2, res3)
	print(rec(0, 0, 0, 0))
	return

def __starting_point():
	main()
__starting_point()


(n, a, b, c) = map(int, input().split())
l = list((int(input()) for i in range(n)))
ans = 10 ** 6
for i in range(4 ** n):
	m = i
	j = 0
	(x, xp, y, yp, z, zp) = (0, 0, 0, 0, 0, 0)
	while m > 0:
		p = m % 4
		if p == 1:
			x += l[j]
			xp += 1
		elif p == 2:
			y += l[j]
			yp += 1
		elif p == 3:
			z += l[j]
			zp += 1
		else:
			pass
		m = m // 4
		j += 1
	if xp != 0 and yp != 0 and (zp != 0):
		t = abs(a - x) + abs(b - y) + abs(c - z) + (xp - 1) * 10 + (yp - 1) * 10 + (zp - 1) * 10
		ans = min(ans, t)
print(ans)


z = list(map(int, input().split()))
n = z[0]
l = [int(input()) for _ in range(n)]
ans = float('inf')
loop = 0
while loop < 4 ** n:
	ps = [loop // 4 ** j % 4 for j in range(n)]
	loop += 1
	s = [[], [], [], []]
	for (cnt, p) in enumerate(ps):
		s[p].append(l[cnt])
	if not all(s[1:]):
		continue
	score = [(len(s[i]) - 1) * 10 + abs(sum(s[i]) - z[i]) for i in range(4)]
	ans = min(ans, sum(score[1:]))
print(ans)


(N, A, B, C) = map(int, input().split())
lis = [int(input()) for i in range(N)]

def kado(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10 ** 9
	cal1 = kado(cur + 1, a, b, c)
	cal2 = kado(cur + 1, a + lis[cur], b, c) + 10
	cal3 = kado(cur + 1, a, b + lis[cur], c) + 10
	cal4 = kado(cur + 1, a, b, c + lis[cur]) + 10
	return min(cal1, cal2, cal3, cal4)
print(kado(0, 0, 0, 0))


import itertools
(n, a, b, c) = map(int, input().split())
ans = float('inf')
l = []
for i in range(n):
	l.append(int(input()))
for i in itertools.product([1, 2, 3, 0], repeat=n):
	if i.count(1) and i.count(2) and i.count(3):
		m = [0, 0, 0, 0]
		for j in range(n):
			m[i[j]] += l[j]
		ans = min(ans, abs(m[1] - a) + abs(m[2] - b) + abs(m[3] - c) + (n - i.count(0) - 3) * 10)
print(ans)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()
(n, a, b, c) = LI()
l = [I() for _ in range(n)]

def dfs(cnt, aa, bb, cc):
	if cnt == n:
		if aa == 0 or bb == 0 or cc == 0:
			return inf
		return abs(aa - a) + abs(bb - b) + abs(cc - c) - 30
	aaa = dfs(cnt + 1, aa + l[cnt], bb, cc) + 10
	bbb = dfs(cnt + 1, aa, bb + l[cnt], cc) + 10
	ccc = dfs(cnt + 1, aa, bb, cc + l[cnt]) + 10
	ddd = dfs(cnt + 1, aa, bb, cc)
	return min(aaa, bbb, ccc, ddd)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l_list = [int(input()) for _ in range(N)]

def dfs(now, a, b, c):
	if now == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else float('inf')
	res0 = dfs(now + 1, a, b, c)
	res1 = dfs(now + 1, a + l_list[now], b, c) + 10
	res2 = dfs(now + 1, a, b + l_list[now], c) + 10
	res3 = dfs(now + 1, a, b, c + l_list[now]) + 10
	return min(res0, res1, res2, res3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = list(map(int, input().split()))
l = []
for i in range(N):
	l.append(int(input()))
from itertools import product
P = product(list(range(4)), repeat=N)
ans = 1000000000
for p in P:
	A_len = 0
	B_len = 0
	C_len = 0
	temp = 0
	for i in range(N):
		n = int(p[i])
		if n == 3:
			if A_len != 0:
				temp += 10
			A_len += l[i]
		elif n == 2:
			if B_len != 0:
				temp += 10
			B_len += l[i]
		elif n == 1:
			if C_len != 0:
				temp += 10
			C_len += l[i]
	if A_len != 0 and B_len != 0 and (C_len != 0):
		temp += abs(A - A_len)
		temp += abs(B - B_len)
		temp += abs(C - C_len)
		ans = min(ans, temp)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [0] * N
for i in range(N):
	L[i] = int(input())
INF = 10 ** 9

def dfs(times, a, b, c):
	if times == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	no_pattern = dfs(times + 1, a, b, c)
	a_pattern = dfs(times + 1, a + L[times], b, c) + 10
	b_pattern = dfs(times + 1, a, b + L[times], c) + 10
	c_pattern = dfs(times + 1, a, b, c + L[times]) + 10
	return min(no_pattern, a_pattern, b_pattern, c_pattern)
print(dfs(0, 0, 0, 0))


import itertools
(n, *abc) = map(int, input().split())
llst = [int(input()) for _ in range(n)]
ans = 10 ** 10
for abc_lst in itertools.product(range(4), repeat=n):
	tmp = 0
	labc = [[0, 0] for _ in range(3)]
	for i in range(n):
		pos = abc_lst[i]
		if pos == 3:
			continue
		labc[pos][0] += llst[i]
		labc[pos][1] += 1
	if [0, 0] in labc:
		continue
	for i in range(3):
		tmp += abs(abc[i] - labc[i][0])
		tmp += 10 * (labc[i][1] - 1)
	ans = min(ans, tmp)
print(ans)


import sys, math, collections, itertools
input = sys.stdin.readline
(N, A, B, C) = list(map(int, input().split()))
l = [int(input()) for _ in range(N)]
use_list = list(itertools.product(list(range(4)), repeat=N))
point = float('inf')
for i in range(len(use_list)):
	ABC = [0] * 3
	count = [0] * 3
	if 0 not in use_list[i] or 1 not in use_list[i] or 2 not in use_list[i]:
		continue
	for j in range(len(use_list[i])):
		if use_list[i][j] != 3:
			ABC[use_list[i][j]] += l[j]
			count[use_list[i][j]] += 1
	p = (sum(count) - len(count)) * 10 + abs(ABC[0] - A) + abs(ABC[1] - B) + abs(ABC[2] - C)
	point = min(point, p)
print(point)


import math
(N, A, B, C) = list(map(int, input().split(' ')))
ls = []
for i in range(N):
	ls.append(int(input()))

def fun(rec, a, b, c):
	if rec == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if a * b * c != 0 else 1e+21
	ans = [fun(rec + 1, a, b, c), fun(rec + 1, a + ls[rec], b, c) + 10, fun(rec + 1, a, b + ls[rec], c) + 10, fun(rec + 1, a, b, c + ls[rec]) + 10]
	return min(ans)
print(fun(0, 0, 0, 0))


def dfs(cnt, a, b, c):
	if cnt == N:
		_sum = abs(A - a) + abs(B - b) + abs(C - c) - 30
		return _sum if min(a, b, c) > 0 else 10 ** 9
	ret0 = dfs(cnt + 1, a, b, c)
	ret1 = dfs(cnt + 1, a + l[cnt], b, c) + 10
	ret2 = dfs(cnt + 1, a, b + l[cnt], c) + 10
	ret3 = dfs(cnt + 1, a, b, c + l[cnt]) + 10
	return min(ret0, ret1, ret2, ret3)
(N, A, B, C, *l) = map(int, open(0).read().split())
print(dfs(0, 0, 0, 0))


from itertools import combinations
(n, a, b, c) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))
ans = 10 ** 6
f = lambda li, k: abs(sum(li) - k) + 10 * (len(li) - 1)
for i in range(4 ** n):
	li = [[] for _ in range(4)]
	for j in range(n):
		li[i // 4 ** j % 4].append(l[j])
	if len(li[0]) * len(li[1]) * len(li[2]) == 0:
		continue
	ans = min(ans, f(li[0], a) + f(li[1], b) + f(li[2], c))
print(ans)


import sys
from itertools import product
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	(n, A, B, C) = list(map(int, input().split()))
	goal = [A, B, C]
	L = list((int(input()) for _ in range(n)))
	res = f_inf
	for pattern in product([0, 1, 2, 3], repeat=n):
		cnt = [0] * 3
		length = [0] * 3
		for (idx, p) in enumerate(pattern):
			if p != 0:
				length[p - 1] += L[idx]
				cnt[p - 1] += 1
		mp = 0
		for i in range(3):
			if cnt[i] == 0:
				break
			mp += abs(goal[i] - length[i]) + (cnt[i] - 1) * 10
		else:
			res = min(res, mp)
	print(res)

def __starting_point():
	resolve()
__starting_point()


import itertools

def diff(a, b, c):
	return abs(A - a) + abs(B - b) + abs(C - c)
(N, A, B, C, *l) = map(int, open(0).read().split())
_min = 10 ** 6
for i in itertools.product([0, 1, 2, 3], repeat=N):
	cnt = 0
	abc = [0, 0, 0]
	for j in range(N):
		if i[j] != 3:
			abc[i[j]] += l[j]
			cnt += 1
	if 0 in abc:
		continue
	_min = min(_min, 10 * cnt - 30 + diff(abc[0], abc[1], abc[2]))
print(_min)


(N, A, B, C) = map(int, input().split())
L = []
for i in range(N):
	L.append(int(input()))

def dfs(n, a, b, c):
	if n == N:
		if min(a, b, c) > 0:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return 10000
	root1 = dfs(n + 1, a + L[n], b, c) + 10
	root2 = dfs(n + 1, a, b + L[n], c) + 10
	root3 = dfs(n + 1, a, b, c + L[n]) + 10
	root4 = dfs(n + 1, a, b, c)
	return min(root1, root2, root3, root4)
print(dfs(0, 0, 0, 0))


def dfs(i, a, b, c, t):
	global ans
	if a * b * c > 0:
		ans = min(ans, abs(A - a) + abs(B - b) + abs(C - c) + 10 * (t - 3))
	if i > N - 1:
		return 0
	dfs(i + 1, a, b, c, t)
	dfs(i + 1, a + L[i], b, c, t + 1)
	dfs(i + 1, a, b + L[i], c, t + 1)
	dfs(i + 1, a, b, c + L[i], t + 1)
	return ans
(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
ans = 10 ** 9
print(dfs(0, 0, 0, 0, 0))


import itertools
(N, A, B, C) = map(int, input().split())
l = [int(input()) for i in range(N)]
ans = []
for X in itertools.product(range(4), repeat=N):
	P = [[] for _ in range(4)]
	for (i, x) in enumerate(X):
		P[x].append(l[i])
	if min(map(len, P[1:])) == 0:
		continue
	tmp = 0
	for (Q, D) in zip(P[1:], [A, B, C]):
		tmp += 10 * (len(Q) - 1) + abs(D - sum(Q))
	ans.append(tmp)
print(sorted(ans)[0])


(N, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(N)]
ans = []
for i in range(4 ** N):
	A = []
	B = []
	C = []
	p = i
	for j in range(N):
		if p % 4 == 1:
			A.append(l[j])
		elif p % 4 == 2:
			B.append(l[j])
		elif p % 4 == 3:
			C.append(l[j])
		p = (p - p % 4) // 4
	if len(A) > 0 and len(B) > 0 and (len(C) > 0):
		ans.append(abs(sum(A) - a) + 10 * (len(A) - 1) + abs(sum(B) - b) + 10 * (len(B) - 1) + abs(sum(C) - c) + 10 * (len(C) - 1))
print(min(ans))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for n in range(N)]
inf = 10 ** 18

def dfs(cur, a, b, c):
	if cur == N:
		if min(a, b, c) > 0:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return inf
	res0 = dfs(cur + 1, a, b, c)
	res1 = dfs(cur + 1, a + l[cur], b, c) + 10
	res2 = dfs(cur + 1, a, b + l[cur], c) + 10
	res3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(res0, res1, res2, res3)
print(dfs(0, 0, 0, 0))


import itertools
(N, A, B, C) = list(map(int, input().split()))
l = [int(input()) for _ in range(N)]
ans = 10 ** 10
for x in itertools.product([0, 1, 2, 3], repeat=N):
	bamboo = [0] * 4
	tmp = 0
	for i in range(N):
		if x[i] in [1, 2, 3] and bamboo[x[i]] > 0:
			tmp += 10
		bamboo[x[i]] += l[i]
	if 0 in bamboo[1:]:
		continue
	tmp += abs(bamboo[1] - A) + abs(bamboo[2] - B) + abs(bamboo[3] - C)
	ans = min(ans, tmp)
print(ans)


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]

def dfs(cur, x, y, z):
	if cur == n:
		return abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(x, y, z) > 0 else 10 ** 9
	ret1 = dfs(cur + 1, x, y, z)
	ret2 = dfs(cur + 1, x + l[cur], y, z) + 10
	ret3 = dfs(cur + 1, x, y + l[cur], z) + 10
	ret4 = dfs(cur + 1, x, y, z + l[cur]) + 10
	return min(ret1, ret2, ret3, ret4)
print(dfs(0, 0, 0, 0))


import itertools
(N, *A) = map(int, input().split())
l = [int(input()) for i in range(N)]
li = itertools.product(range(4), repeat=N)
ans = float('inf')
for i in li:
	cnt = [0] * 3
	length = [0] * 3
	for k in range(N):
		if i[k] == 3:
			continue
		cnt[i[k]] += 1
		length[i[k]] += l[k]
	if min(cnt) > 0:
		cost = sum([abs(length[i] - A[i]) + 10 * cnt[i] for i in range(3)]) - 30
		ans = min(ans, cost)
print(ans)


import sys
from itertools import product
input = sys.stdin.readline

def main():
	(N, A, B, C) = list(map(int, input().split()))
	L = [0] * N
	for i in range(N):
		L[i] = int(input())
	ans = float('inf')
	for comb in product(list(range(4)), repeat=N):
		mp = -30
		a = b = c = 0
		for (i, j) in enumerate(comb):
			if j == 0:
				continue
			elif j == 1:
				a += L[i]
			elif j == 2:
				b += L[i]
			elif j == 3:
				c += L[i]
			mp += 10
		if min(a, b, c) == 0:
			continue
		mp += abs(A - a) + abs(B - b) + abs(C - c)
		if mp < ans:
			ans = mp
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, A, B, C) = map(int, input().split())
take = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(num, a, b, c):
	if num == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(num + 1, a, b, c)
	ret1 = dfs(num + 1, a + take[num], b, c) + 10
	ret2 = dfs(num + 1, a, b + take[num], c) + 10
	ret3 = dfs(num + 1, a, b, c + take[num]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


from itertools import product, permutations
(N, A, B, C) = list(map(int, input().split(' ')))
L = [int(input()) for _ in range(N)]
ans = 10 ** 9
for groups in product(list(range(4)), repeat=N):
	items = []
	group_a = []
	group_b = []
	group_c = []
	for (group, length) in zip(groups, L):
		if group == 0:
			items.append((length, 0))
		elif group == 1:
			group_a.append(length)
		elif group == 2:
			group_b.append(length)
		elif group == 3:
			group_c.append(length)
	if group_a:
		items.append((sum(group_a), (len(group_a) - 1) * 10))
	if group_b:
		items.append((sum(group_b), (len(group_b) - 1) * 10))
	if group_c:
		items.append((sum(group_c), (len(group_c) - 1) * 10))
	if len(items) < 3:
		continue
	for (one, two, three) in permutations((A, B, C), r=3):
		cost = 0
		_items = list(items)
		_items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))
		cost += abs(_items[0][0] - one) + _items[0][1]
		_items.pop(0)
		_items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))
		cost += abs(_items[0][0] - two) + _items[0][1]
		_items.pop(0)
		_items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))
		cost += abs(_items[0][0] - three) + _items[0][1]
		ans = min(ans, cost)
print(ans)


(N, A, B, C) = (int(x) for x in input().split())
L = [int(input()) for _ in range(N)]
INF = 10 ** 9

def magic(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = magic(cur + 1, a, b, c)
	ret1 = magic(cur + 1, a + L[cur], b, c) + 10
	ret2 = magic(cur + 1, a, b + L[cur], c) + 10
	ret3 = magic(cur + 1, a, b, c + L[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(magic(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]

def dfs(k, p, q, r):
	if k == n:
		if min(p, q, r) > 0:
			return abs(p - a) + abs(q - b) + abs(r - c) - 30
		else:
			return 10 ** 7
	t1 = dfs(k + 1, p, q, r)
	t2 = dfs(k + 1, p + l[k], q, r) + 10
	t3 = dfs(k + 1, p, q + l[k], r) + 10
	t4 = dfs(k + 1, p, q, r + l[k]) + 10
	return min(t1, t2, t3, t4)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def chk(i, a, b, c):
	if i == N:
		if min(a, b, c) > 0:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return INF
	r0 = chk(i + 1, a, b, c)
	r1 = chk(i + 1, a + l[i], b, c) + 10
	r2 = chk(i + 1, a, b + l[i], c) + 10
	r3 = chk(i + 1, a, b, c + l[i]) + 10
	return min(r0, r1, r2, r3)
print(chk(0, 0, 0, 0))


(n, A, B, C) = list(map(int, input().split()))
l = [int(input()) for _ in range(n)]
INF = 10 ** 9

def dfs(now, a, b, c):
	if now == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	way1 = dfs(now + 1, a, b, c)
	way2 = dfs(now + 1, a + l[now], b, c) + 10
	way3 = dfs(now + 1, a, b + l[now], c) + 10
	way4 = dfs(now + 1, a, b, c + l[now]) + 10
	return min(way1, way2, way3, way4)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]

def f(n, a, b, c):
	if n == N:
		if a == 0 or b == 0 or c == 0:
			return 1000000
		else:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30
	x = f(n + 1, a, b, c)
	y = f(n + 1, a + l[n], b, c) + 10
	z = f(n + 1, a, b + l[n], c) + 10
	w = f(n + 1, a, b, c + l[n]) + 10
	return min(x, y, z, w)
print(f(0, 0, 0, 0))


def ttt(x, y, z, i, m, p, q, r):
	if i == n and (p == 0 or q == 0 or r == 0):
		return 10000000
	if i == n:
		m += abs(x - a) + abs(y - b) + abs(z - c)
		return m
	else:
		return min(ttt(x, y, z, i + 1, m, p, q, r), ttt(x + l[i], y, z, i + 1, m + 10, p + 1, q, r), ttt(x, y + l[i], z, i + 1, m + 10, p, q + 1, r), ttt(x, y, z + l[i], i + 1, m + 10, p, q, r + 1))
(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]
print(ttt(0, 0, 0, 0, 0, 0, 0, 0) - 30)


(n, a, b, c) = [int(i) for i in input().split()]
l = [int(input()) for _ in range(n)]
INF = 10 ** 9

def dfs(times, A, B, C):
	if times == n:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(A, B, C) > 0 else INF
	non_ans = dfs(times + 1, A, B, C)
	a_ans = dfs(times + 1, A + l[times], B, C) + 10
	b_ans = dfs(times + 1, A, B + l[times], C) + 10
	c_ans = dfs(times + 1, A, B, C + l[times]) + 10
	return min(non_ans, a_ans, b_ans, c_ans)
print(dfs(0, 0, 0, 0))


(N, A, B, C, *L) = map(int, open(0).read().split())
ans = float('inf')
for i in range(2 ** (N * 2)):
	a = b = c = 0
	mp = 0
	for (j, x) in enumerate(L):
		f = i >> 2 * j & 3
		if f == 0:
			if a:
				mp += 10
			a += x
		elif f == 1:
			if b:
				mp += 10
			b += x
		elif f == 2:
			if c:
				mp += 10
			c += x
	if any([a == 0, b == 0, c == 0]):
		continue
	mp += abs(A - a) + abs(B - b) + abs(C - c)
	if ans > mp:
		ans = mp
	if ans == 0:
		break
print(ans)


(N, A, B, C) = list(map(int, input().split()))
abc = [C, B, A]
l = [0] * N
for i in range(N):
	l[i] = int(input())
import numpy
mpp = 10 ** 10
L = [0] * 3
t = [-10] * 3
for i in range(1, 4 ** N):
	b = numpy.base_repr(i, 4, N)[-N:]
	L = [A, B, C]
	t = [-10] * 3
	if '1' not in b or '2' not in b or '3' not in b:
		continue
	for j in range(N):
		for k in range(3):
			if b[j] == str(k + 1):
				L[k] -= l[j]
				t[k] += 10
	mpp = min(mpp, sum(t) + sum([abs(x) for x in L]))
print(mpp)


(N, A, B, C) = map(int, input().split())
T = [A, B, C]
L = [int(input()) for i in range(N)]
ans = 1999999999
for i in range(4 ** N):
	L_ = [[] for i in range(4)]
	for k in range(N):
		r = i % 4
		i = (i - r) // 4
		L_[r].append(L[k])
	if len(L_[0]) * len(L_[1]) * len(L_[2]) == 0:
		continue
	MP = 10 * (len(L_[0]) + len(L_[1]) + len(L_[2]) - 3)
	for r in range(3):
		s = 0
		for l in L_[r]:
			s += l
		MP += abs(s - T[r])
	ans = min(ans, MP)
print(ans)


(n, *a) = map(int, input().split())
l = [int(input()) for i in range(n)]
ans = float('inf')
for i in range(4 ** n):
	table = [0 for g in range(3)]
	temp = i
	pre = 0
	for j in range(n):
		if temp % 4 == 3:
			temp //= 4
			continue
		if table[temp % 4]:
			table[temp % 4] += l[j]
			pre += 10
		else:
			table[temp % 4] = l[j]
		temp //= 4
	if 0 in table:
		continue
	for g in range(3):
		pre += abs(a[g] - table[g])
	ans = min(ans, pre)
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
input_nums = lambda : list(map(int, input().split()))
INF = 10 ** 9

def main():
	(N, A, B, C) = input_nums()
	ll = [int(input()) for _ in range(N)]

	def dfs(idx, a, b, c):
		if idx == N:
			return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
		ret0 = dfs(idx + 1, a, b, c)
		ret1 = dfs(idx + 1, a + ll[idx], b, c) + 10
		ret2 = dfs(idx + 1, a, b + ll[idx], c) + 10
		ret3 = dfs(idx + 1, a, b, c + ll[idx]) + 10
		return min(ret0, ret1, ret2, ret3)
	print(dfs(0, 0, 0, 0))

def __starting_point():
	main()
__starting_point()


def main():
	(n, a, b, c) = list(map(int, input().split()))
	L = [int(input()) for _ in range(n)]
	INF = 1000000

	def dfs(i, la, lb, lc):
		if i == n:
			return abs(la - a) + abs(lb - b) + abs(lc - c) if min(la, lb, lc) > 0 else INF
		res = []
		res.append(dfs(i + 1, la, lb, lc))
		res.append(dfs(i + 1, la + L[i], lb, lc) + 10 if la != 0 else dfs(i + 1, la + L[i], lb, lc))
		res.append(dfs(i + 1, la, lb + L[i], lc) + 10 if lb != 0 else dfs(i + 1, la, lb + L[i], lc))
		res.append(dfs(i + 1, la, lb, lc + L[i]) + 10 if lc != 0 else dfs(i + 1, la, lb, lc + L[i]))
		return min(res)
	print(dfs(0, 0, 0, 0))

def __starting_point():
	main()
__starting_point()


(n, a, b, c, *l) = map(int, open(0).read().split())

def dfs(x, y, z, r):
	if r == n:
		return abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(x, y, z) > 0 else 10 ** 9
	return min(dfs(x + l[r], y, z, r + 1) + 10, dfs(x, y + l[r], z, r + 1) + 10, dfs(x, y, z + l[r], r + 1) + 10, dfs(x, y, z, r + 1))
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split(' '))
INF = 10 ** 9
tmp = [int(input()) for _ in range(N)]

def calc(num, a, b, c):
	if num == N:
		if min(a, b, c) > 0:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return INF
	res = calc(num + 1, a, b, c)
	res1 = calc(num + 1, a + tmp[num], b, c) + 10
	res2 = calc(num + 1, a, b + tmp[num], c) + 10
	res3 = calc(num + 1, a, b, c + tmp[num]) + 10
	return min(res, res1, res2, res3)
print(calc(0, 0, 0, 0))


from itertools import product
(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]
minscore = 10 ** 9
for p in product(range(-1, 3), repeat=N):
	flag = 0
	score = 0
	n_abc = [0, 0, 0]
	sumlen = [0, 0, 0]
	for i in range(N):
		if p[i] != -1:
			n_abc[p[i]] += 1
			sumlen[p[i]] += l[i]
	for j in range(3):
		if n_abc[j] == 0:
			flag = 1
			break
		score += (n_abc[j] - 1) * 10 + abs(sumlen[j] - [A, B, C][j])
	if flag:
		continue
	if score < minscore:
		minscore = score
print(minscore)


import itertools
(n, a, b, c) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))
mp = float('inf')
for i in itertools.product([0, 1, 2, 3], repeat=n):
	if 0 not in i or 1 not in i or 2 not in i:
		continue
	(la, lb, lc) = (0, 0, 0)
	temp = 0
	for j in range(3):
		temp += (i.count(j) - 1) * 10
	for j in range(n):
		if i[j] == 0:
			la += l[j]
		elif i[j] == 1:
			lb += l[j]
		elif i[j] == 2:
			lc += l[j]
	for (j, k) in [[la, a], [lb, b], [lc, c]]:
		temp += abs(j - k)
	mp = min(mp, temp)
print(mp)


import sys
sys.setrecursionlimit(10 ** 8)

def ii():
	return int(sys.stdin.readline())

def mi():
	return list(map(int, sys.stdin.readline().split()))

def li():
	return list(map(int, sys.stdin.readline().split()))

def li2(N):
	return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

def dp2(ini, i, j):
	return [[ini] * i for _ in range(j)]
import itertools
(N, *A) = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N
A = sorted(A)
tmp = [0] * 3
ans = float('inf')
for k in itertools.product([0, 1], repeat=N_):
	N = sum(k)
	if N < 3:
		continue
	L = []
	for x in range(N_):
		if k[x]:
			L.append(L_[x] * k[x])
	sum_l = sum(L)
	for i in range(1, N + 1):
		for koho_i in range(1, 2 ** i):
			for koho_j in range(1, 2 ** i):
				j = i
				if koho_i & koho_j:
					continue
				tmp[0] = sum([L[x] * min(koho_i & 1 << x, 1) for x in range(i)])
				tmp[1] = sum([L[x] * min(koho_j & 1 << x, 1) for x in range(j)])
				tmp[2] = sum_l - tmp[0] - tmp[1]
				if 0 in tmp:
					continue
				tmp = sorted(tmp)
				cost = (N - 3) * 10 + sum([abs(tmp[x] - A[x]) for x in range(3)])
				ans = min(ans, cost)
print(ans)


(N, A, B, C) = map(int, input().split())
bms = [int(input()) for _ in range(N)]

def dfs(cur, a, b, c):
	if cur == N:
		s = abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else 10 ** 9
		return s
	s_0 = dfs(cur + 1, a, b, c)
	s_a = dfs(cur + 1, a + bms[cur], b, c) + 10
	s_b = dfs(cur + 1, a, b + bms[cur], c) + 10
	s_c = dfs(cur + 1, a, b, c + bms[cur]) + 10
	return min(s_0, s_a, s_b, s_c)
print(dfs(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]

def check(t):
	ca = t.count('a')
	cb = t.count('b')
	cc = t.count('c')
	if ca == 0 or cb == 0 or cc == 0:
		return False
	return True

def calc(t):
	(A, B, C) = (0, 0, 0)
	d = (t.count('a') - 1 + t.count('b') - 1 + t.count('c') - 1) * 10
	for (i, j) in enumerate(t):
		if j == 'a':
			A += l[i]
		elif j == 'b':
			B += l[i]
		elif j == 'c':
			C += l[i]
	d += abs(A - a) + abs(B - b) + abs(C - c)
	return d
ary = ['a', 'b', 'c', 'd']
take = []

def dfs(s):
	if len(s) == n:
		if check(s):
			take.append(calc(s))
		return
	for i in range(4):
		dfs(s + ary[i])
dfs('')
print(min(take))


import sys
readline = sys.stdin.readline
(N, A, B, C) = map(int, readline().split())
L = [int(readline()) for i in range(N)]
ans = 10 ** 10
import itertools
for prod in itertools.product(range(4), repeat=N):
	if len(set(prod) & set(range(3))) != 3:
		continue
	take = [0] * 3
	cost = 0
	for i in range(len(prod)):
		if prod[i] == 3:
			continue
		if take[prod[i]] != 0:
			cost += 10
		take[prod[i]] += L[i]
	cost += abs(A - take[0]) + abs(B - take[1]) + abs(C - take[2])
	if ans > cost:
		ans = cost
print(ans)


import itertools
(n, a, b, c) = map(int, input().split())
l = [int(input()) for i in range(n)]
ans = 10 ** 9
for k in itertools.product(range(4), repeat=n):
	A = [[] for i in range(4)]
	for i in range(n):
		A[k[i]] += [l[i]]
	if A[1] and A[2] and A[3]:
		tmp = 10 * (n - len(A[0]) - 3)
		tmp += abs(a - sum(A[1]))
		tmp += abs(b - sum(A[2]))
		tmp += abs(c - sum(A[3]))
		ans = min(tmp, ans)
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
(n, A, B, C) = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))
inf = 10 ** 9

def dfs(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


from itertools import *
(n, a, b, c, *l) = map(int, open(0).read().split())
ans = float('inf')
for i in product(range(4), repeat=n):
	take = [[], [], []]
	for (k, j) in enumerate(i):
		if j == 3:
			continue
		take[j].append(l[k])
	(*tmp,) = map(len, take)
	if all(tmp):
		(x, y, z) = map(sum, take)
		ans = min(ans, (sum(tmp) - 3) * 10 + abs(x - a) + abs(y - b) + abs(z - c))
print(ans)


(n, A, B, C) = map(int, input().split())
L = [int(input()) for _ in range(n)]
INF = 10 ** 9

def rec(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = rec(cur + 1, a, b, c)
	ret1 = rec(cur + 1, a + L[cur], b, c) + 10
	ret2 = rec(cur + 1, a, b + L[cur], c) + 10
	ret3 = rec(cur + 1, a, b, c + L[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(rec(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split(' '))
l = [int(input()) for x in range(N)]
b = []
for x in range(4 ** N):
	o = []
	s = -30
	for y in range(N):
		o.append(x // 4 ** y % 4)
	if 0 in o and 1 in o and (2 in o):
		a = [A, B, C]
		for y in range(N):
			if o[y] != 3:
				a[o[y]] -= l[y]
				s += 10
		b.append(sum(map(lambda x: x if x > 0 else -x, a)) + s)
print(min(b))


(n, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(n)]
t = 10 ** 9

def dfs(level, a, b, c):
	if level == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else t
	k1 = dfs(level + 1, a, b, c)
	k2 = dfs(level + 1, a + l[level], b, c) + 10
	k3 = dfs(level + 1, a, b + l[level], c) + 10
	k4 = dfs(level + 1, a, b, c + l[level]) + 10
	return min(k1, k2, k3, k4)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
from itertools import product
ans = 10 ** 9
for p in product(range(4), repeat=N):
	l = [0] * 3
	cost = 0
	for (i, t) in enumerate(p):
		if t < 3:
			if l[t] > 0:
				cost += 10
			l[t] += L[i]
	if min(l) > 0:
		ans = min(ans, cost + abs(A - l[0]) + abs(B - l[1]) + abs(C - l[2]))
print(ans)


from itertools import product
(N, A, B, C) = map(int, input().split())
abc = [C, B, A]
lst = [int(input()) for _ in range(N)]
ans = []
for l in product([0, 1, 2, 3], repeat=N):
	cnt = [[], [], [], []]
	for (i, ll) in enumerate(l):
		cnt[ll].append(lst[i])
	mp = 0
	p = []
	for i in cnt[:3]:
		if len(i) != 0:
			mp += (len(i) - 1) * 10
		p.append(sum(i))
	p.sort()
	if p[0] != 0:
		for i in range(3):
			mp += abs(p[i] - abc[i])
		ans.append(mp)
print(min(ans))


(N, A, B, C) = list(map(int, input().split()))
L_list = [int(input()) for i in range(N)]
import itertools
Target = itertools.product([0, 1, 2, 3], repeat=N)
INF = 10 ** 9
ans = INF
for T in Target:
	A_sum = 0
	B_sum = 0
	C_sum = 0
	A_cost = 0
	B_cost = 0
	C_cost = 0
	for i in range(N):
		if T[i] == 0:
			continue
		if T[i] == 1:
			if A_sum == 0:
				A_sum += L_list[i]
			else:
				A_sum += L_list[i]
				A_cost += 10
		if T[i] == 2:
			if B_sum == 0:
				B_sum += L_list[i]
			else:
				B_sum += L_list[i]
				B_cost += 10
		if T[i] == 3:
			if C_sum == 0:
				C_sum += L_list[i]
			else:
				C_sum += L_list[i]
				C_cost += 10
	if min(A_sum, B_sum, C_sum) == 0:
		continue
	ans = min(ans, abs(A - A_sum) + A_cost + abs(B - B_sum) + B_cost + abs(C - C_sum) + C_cost)
print(ans)


(N, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(N)]
R = [0] * N
ans = 10 ** 9

def myadd(i):
	if R[i] == 3:
		R[i] = 0
		myadd(i + 1)
	else:
		R[i] += 1
for i in range(4 ** N - 1):
	myadd(0)
	if 1 in R and 2 in R and (3 in R):
		tmp = -30
		(t1, t2, t3) = (0, 0, 0)
		for j in range(N):
			if R[j] == 0:
				continue
			if R[j] == 1:
				t1 += L[j]
			elif R[j] == 2:
				t2 += L[j]
			elif R[j] == 3:
				t3 += L[j]
			tmp += 10
		tmp += abs(A - t1) + abs(B - t2) + abs(C - t3)
		ans = min(tmp, ans)
print(ans)


(N, A, B, C) = list(map(int, input().split()))
l = []
for i in range(N):
	l.append(int(input()))

def dfs(i, a, b, c):
	if i == N:
		if min(a, b, c) == 0:
			return float('INF')
		else:
			return abs(a - A) + abs(b - B) + abs(c - C)
	else:
		ans0 = dfs(i + 1, a, b, c)
		ans1 = dfs(i + 1, a + l[i], b, c) + (10 if a != 0 else 0)
		ans2 = dfs(i + 1, a, b + l[i], c) + (10 if b != 0 else 0)
		ans3 = dfs(i + 1, a, b, c + l[i]) + (10 if c != 0 else 0)
	return min(ans0, ans1, ans2, ans3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]

def f(a, b, c, n):
	if n == N:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else 10 ** 9
	ans = f(a, b, c, n + 1)
	ans = min(ans, f(a + l[n], b, c, n + 1) + 10)
	ans = min(ans, f(a, b + l[n], c, n + 1) + 10)
	ans = min(ans, f(a, b, c + l[n], n + 1) + 10)
	return ans
print(f(0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
li = [int(input()) for _ in range(n)]
inf = 1000000

def cost(N, x, y, z):
	if N == n:
		if x * y * z == 0:
			return inf
		return abs(x - a) + abs(y - b) + abs(z - c)
	cost1 = cost(N + 1, x, y, z)
	cost2 = cost(N + 1, x + li[N], y, z) + 10
	cost3 = cost(N + 1, x, y + li[N], z) + 10
	cost4 = cost(N + 1, x, y, z + li[N]) + 10
	return min(cost1, cost2, cost3, cost4)
print(cost(0, 0, 0, 0) - 30)


from itertools import product
a = [0, 0, 0]
(N, a[0], a[1], a[2]) = list(map(int, input().split()))
l = []
for i in range(N):
	l.append(int(input()))
mm = float('inf')
for p in product(range(4), repeat=N):
	c = [0] * 4
	s = [0] * 4
	for i in range(N):
		c[p[i]] += 1
		s[p[i]] += l[i]
	if min(c[:3]) == 0:
		continue
	m = 0
	for j in range(3):
		m += max(0, c[j] - 1) * 10
		m += abs(a[j] - s[j])
	mm = min(mm, m)
print(mm)


def MAP():
	return list(map(int, input().split()))
(n, A, B, C) = MAP()
l = [int(input()) for _ in range(n)]
INF = 10 ** 9

def dfs(cur, a, b, c):
	if cur == n:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = [0] * N
for i in range(N):
	l[i] = int(input())

def dfs(i, a, b, c):
	if i == N:
		if a == 0 or b == 0 or c == 0:
			return 100000
		else:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
	else:
		return min(dfs(i + 1, a + l[i], b, c) + 10, dfs(i + 1, a, b + l[i], c) + 10, dfs(i + 1, a, b, c + l[i]) + 10, dfs(i + 1, a, b, c))
print(dfs(0, 0, 0, 0))


(N, A, B, C) = map(int, input().split())
l = []
for i in range(N):
	l.append(int(input()))

def dfs(bamboo, a, b, c):
	if bamboo == N:
		if min(a, b, c) > 0:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return 10 ** 10
	else:
		ans1 = dfs(bamboo + 1, a, b, c)
		ans2 = dfs(bamboo + 1, a + l[bamboo], b, c) + 10
		ans3 = dfs(bamboo + 1, a, b + l[bamboo], c) + 10
		ans4 = dfs(bamboo + 1, a, b, c + l[bamboo]) + 10
		return min(ans1, ans2, ans3, ans4)
print(dfs(0, 0, 0, 0))


from itertools import product
(n, a, b, c) = list(map(int, input().split()))
L = [int(input()) for _ in range(n)]
INF = 10 ** 18
ans = INF
for subset in product(list(range(4)), repeat=n):
	cost = 0
	ABC = [[] for _ in range(3)]
	for (i, s) in enumerate(subset):
		if not s:
			continue
		ABC[s - 1].append(L[i])
	if any((not X for X in ABC)):
		continue
	for (x, X) in zip((a, b, c), ABC):
		cost += (len(X) - 1) * 10
		cost += abs(x - sum(X))
	if cost < ans:
		ans = cost
print(ans)


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 100000000000
for i in range(4 ** n):
	A = []
	B = []
	C = []
	D = []
	current = 0
	for j in range(n):
		if i >> 2 * j & 3 == 0:
			A.append(l[j])
		elif i >> 2 * j & 3 == 1:
			B.append(l[j])
		elif i >> 2 * j & 3 == 2:
			C.append(l[j])
		elif i >> 2 * j & 3 == 3:
			D.append(l[j])
	if A and B and C:
		current += (len(A) - 1) * 10 + abs(sum(A) - a)
		current += (len(B) - 1) * 10 + abs(sum(B) - b)
		current += (len(C) - 1) * 10 + abs(sum(C) - c)
		ans = min(ans, current)
print(ans)


(n, A, B, C) = map(int, input().split())
L = [int(input()) for i in range(n)]
INF = 10 ** 9

def dfs(cnt, a, b, c):
	if cnt == n:
		if min(a, b, c) > 0:
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		else:
			return INF
	else:
		res0 = dfs(cnt + 1, a, b, c)
		res1 = dfs(cnt + 1, a + L[cnt], b, c) + 10
		res2 = dfs(cnt + 1, a, b + L[cnt], c) + 10
		res3 = dfs(cnt + 1, a, b, c + L[cnt]) + 10
		return min(res0, res1, res2, res3)
print(dfs(0, 0, 0, 0))


(N, A, B, C) = list(map(int, input().split()))
L = []
for _ in range(N):
	L.append(int(input()))

def test(n, a, b, c, na, nb, nc):
	if n == N:
		if min(na, nb, nc) == 0:
			return 10 ** 9
		else:
			mp = 0
			mp += (na - 1) * 10 if na else 0
			mp += (nb - 1) * 10 if nb else 0
			mp += (nc - 1) * 10 if nc else 0
			mp += abs(A - a) + abs(B - b) + abs(C - c)
			return mp
	else:
		mp1 = test(n + 1, a, b, c, na, nb, nc)
		mp2 = test(n + 1, a + L[n], b, c, na + 1, nb, nc)
		mp3 = test(n + 1, a, b + L[n], c, na, nb + 1, nc)
		mp4 = test(n + 1, a, b, c + L[n], na, nb, nc + 1)
		return min(mp1, mp2, mp3, mp4)
print(test(0, 0, 0, 0, 0, 0, 0))


(n, a, b, c) = map(int, input().split())
l = [int(input()) for _ in range(n)]

def kadomatsu(li, x):
	cost = 0
	cost += 10 * (len(li) - 1)
	cost += abs(sum(li) - x)
	return cost
ansli = []
for i in range(4 ** n):
	amari = []
	while True:
		if i >= 4:
			amari.append(i % 4)
			i = i // 4
		else:
			amari.append(i)
			break
	gyaku = amari[::-1]
	gya = [0] * (n - len(gyaku)) + gyaku
	al = []
	bl = []
	cl = []
	for j in range(n):
		if gya[j] == 1:
			al += [l[j]]
		elif gya[j] == 2:
			bl += [l[j]]
		elif gya[j] == 3:
			cl += [l[j]]
	if al and bl and cl:
		ans = kadomatsu(al, a) + kadomatsu(bl, b) + kadomatsu(cl, c)
		ansli += [ans]
print(min(ansli))