N,*A=list(map(int,input().split()));a=[[0]*4];r=[0,1,2]

for i in range(N):l=int(eval(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)))
N,*A=list(map(int,input().split()));a=[[0]*4];r=[0,1,2]

for i in range(N):l=int(eval(input()));a+=[[p[j]+l*(i==j)for j in r]+[p[3]+10]for i in r 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)))
N, *A = list(map(int, input().split()))
a = [[0] * 4]
r = [0, 1, 2]
for i in range(N):
    l = int(eval(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)))

N, *A = list(map(int, input().split()))
a = [[0] * 4]
r = [0, 1, 2]
for i in range(N):
    l = int(eval(input()))
    a += [[p[j] + l * (i == j) for j in r] + [p[3] + 10] for i in r 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)))

-    a = [ -        [p[j] + l * (i == j) for j in r] + [p[3] + (i < 3) * 10] -        for i in r + [3] -        for p in a -    ] +    a += [[p[j] + l * (i == j) for j in r] + [p[3] + 10] for i in r for p in a]