from itertools import permutations
n,a,b,c=map(int,input().split())
target=[a,b,c]
lst=[int(input()) for _ in range(n)]
p=list(permutations(lst,3))
ans=float("inf")

def Base_10_to_n(X, n,keta):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    out="0"*(keta-len(out))+out
    return out
for q in range(len(p)):
    base_tri=list(p[q])
    extra=lst[:]
    for i in base_tri:
        extra.remove(i)
    tmp=0
    for i in range(3):
        tmp+=abs(base_tri[i]-target[i])
    ans=min(tmp,ans)
    for i in range(1,4**(n-3)):
        tmp=0
        tri=base_tri[:]
        yonshin=Base_10_to_n(i,4,n-3)
        for j in range(n-3):
            if yonshin[j]=="1":
                tri[0]+=extra[j]
                tmp+=10
            elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
            elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
        for j in range(3):
            tmp+=abs(tri[j]-target[j])
        ans=min(tmp,ans)
print(ans) from itertools import permutations n,a,b,c=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split a b c target=[a,b,c] target [a,b,c] a b c int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input lst=[int(input()) for _ in range(n)] lst [int(input()) for _ in range(n)] p=list(permutations(lst,3)) p list(permutations(lst,3)) list permutations(lst,3) permutations lst 3 ans=float("inf") ans float("inf") float "inf" def Base_10_to_n(X, n,keta):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    out="0"*(keta-len(out))+out
    return out Base_10_to_n X_dumy = X X_dumy X out = '' out '' while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
     X_dumy>0 X_dumy 0 out = str(X_dumy%n)+out out str(X_dumy%n)+out str(X_dumy%n) str X_dumy%n X_dumy n out X_dumy = int(X_dumy/n) X_dumy int(X_dumy/n) int X_dumy/n X_dumy n out="0"*(keta-len(out))+out out "0"*(keta-len(out))+out "0"*(keta-len(out)) "0" keta-len(out) keta len(out) len out out return out out X X n n keta keta for q in range(len(p)):
    base_tri=list(p[q])
    extra=lst[:]
    for i in base_tri:
        extra.remove(i)
    tmp=0
    for i in range(3):
        tmp+=abs(base_tri[i]-target[i])
    ans=min(tmp,ans)
    for i in range(1,4**(n-3)):
        tmp=0
        tri=base_tri[:]
        yonshin=Base_10_to_n(i,4,n-3)
        for j in range(n-3):
            if yonshin[j]=="1":
                tri[0]+=extra[j]
                tmp+=10
            elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
            elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
        for j in range(3):
            tmp+=abs(tri[j]-target[j])
        ans=min(tmp,ans) q range(len(p)) range len(p) len p base_tri=list(p[q]) base_tri list(p[q]) list p[q] p q extra=lst[:] extra lst[:] lst : for i in base_tri:
        extra.remove(i)
     i base_tri extra.remove(i) extra.remove extra remove i tmp=0 tmp 0 for i in range(3):
        tmp+=abs(base_tri[i]-target[i])
     i range(3) range 3 tmp+=abs(base_tri[i]-target[i]) tmp abs(base_tri[i]-target[i]) abs base_tri[i]-target[i] base_tri[i] base_tri i target[i] target i ans=min(tmp,ans) ans min(tmp,ans) min tmp ans for i in range(1,4**(n-3)):
        tmp=0
        tri=base_tri[:]
        yonshin=Base_10_to_n(i,4,n-3)
        for j in range(n-3):
            if yonshin[j]=="1":
                tri[0]+=extra[j]
                tmp+=10
            elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
            elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
        for j in range(3):
            tmp+=abs(tri[j]-target[j])
        ans=min(tmp,ans) i range(1,4**(n-3)) range 1 4**(n-3) 4 n-3 n 3 tmp=0 tmp 0 tri=base_tri[:] tri base_tri[:] base_tri : yonshin=Base_10_to_n(i,4,n-3) yonshin Base_10_to_n(i,4,n-3) Base_10_to_n i 4 n-3 n 3 for j in range(n-3):
            if yonshin[j]=="1":
                tri[0]+=extra[j]
                tmp+=10
            elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
            elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
         j range(n-3) range n-3 n 3 if yonshin[j]=="1":
                tri[0]+=extra[j]
                tmp+=10
            elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
            elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
         yonshin[j]=="1" yonshin[j] yonshin j "1" tri[0]+=extra[j] tri[0] tri 0 extra[j] extra j tmp+=10 tmp 10 elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
             yonshin[j]=="2" yonshin[j] yonshin j "2" tri[1]+=extra[j] tri[1] tri 1 extra[j] extra j tmp+=10 tmp 10 elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
         yonshin[j]=="3" yonshin[j] yonshin j "3" tri[2]+=extra[j] tri[2] tri 2 extra[j] extra j tmp+=10 tmp 10 for j in range(3):
            tmp+=abs(tri[j]-target[j])
         j range(3) range 3 tmp+=abs(tri[j]-target[j]) tmp abs(tri[j]-target[j]) abs tri[j]-target[j] tri[j] tri j target[j] target j ans=min(tmp,ans) ans min(tmp,ans) min tmp ans print(ans) print ans target=[a,b,c] [a,b,c] target tmp=0 0 tmp tmp+=abs(base_tri[i]-target[i]) abs(base_tri[i]-target[i]) tmp tmp+=10 10 tmp lst=[int(input()) for _ in range(n)] [int(input()) for _ in range(n)] lst p=list(permutations(lst,3)) list(permutations(lst,3)) p tmp+=abs(tri[j]-target[j]) abs(tri[j]-target[j]) tmp ans=min(tmp,ans) min(tmp,ans) ans yonshin=Base_10_to_n(i,4,n-3) Base_10_to_n(i,4,n-3) yonshin def Base_10_to_n(X, n,keta):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    out="0"*(keta-len(out))+out
    return out def Base_10_to_n(X, n,keta):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    out="0"*(keta-len(out))+out
    return out Base_10_to_n a,b,c=map(int,input().split()) map(int,input().split()) a c=map(int,input().split()) map(int,input().split()) c base_tri=list(p[q]) list(p[q]) base_tri extra=lst[:] lst[:] extra n,a,b,c=map(int,input().split()) map(int,input().split()) n tri=base_tri[:] base_tri[:] tri tmp+=10 10 tmp ans=min(tmp,ans) min(tmp,ans) ans tmp+=10 10 tmp b,c=map(int,input().split()) map(int,input().split()) b ans=float("inf") float("inf") ans tmp=0 0 tmp
from itertools import permutations
n,a,b,c=map(int,input().split())
target=[a,b,c]
lst=[int(input()) for _ in range(n)]
p=list(permutations(lst,3))
ans=float("inf")

def Base_10_to_n(X, n,keta):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    out="0"*(keta-len(out))+out
    return out
for q in range(len(p)):
    base_tri=list(p[q])
    extra=lst[:]
    for i in base_tri:
        extra.remove(i)
    tmp=0
    for i in range(3):
        tmp+=abs(base_tri[i]-target[i])
    ans=min(tmp,ans)
    for i in range(1,4**(n-3)):
        tmp=0
        tri=base_tri[:]
        yonshin=Base_10_to_n(i,4,n-3)
        for j in range(n-3):
            if yonshin[j]=="1":
                tri[0]+=extra[j]
                tmp+=10
            elif yonshin[j]=="2":
                tri[1]+=extra[j]
                tmp+=10
            elif yonshin[j]=="3":
                tri[2]+=extra[j]
                tmp+=10
        for j in range(3):
            tmp+=abs(tri[j]-target[j])
        ans=min(tmp,ans)
print(ans)