Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ll=[i for i in range(1,n+1)]
x=[]
for i in range(1,n+1):
    z=list(itertools.combinations(l,i))
    zz=list(itertools.combinations(ll,i))
    for j in range(len(z)):
        x.append([sum(z[j]),(i-1)*10,list(zz[j])])
x.sort()
#print(x)
A=[];B=[];C=[]
for i in range(len(x)):
    A.append([x[i][1]+abs(a-x[i][0]),x[i][2]])
    B.append([x[i][1]+abs(b-x[i][0]),x[i][2]])
    C.append([x[i][1]+abs(c-x[i][0]),x[i][2]])
#A.sort();B.sort();C.sort()
m=len(A)
ans=float('inf')
for i in range(m):
    for j in range(m):
        for k in range(m):
            if len(A[i][1]+B[j][1]+C[k][1])!=len((set(A[i][1]+B[j][1]+C[k][1]))):
                continue
            else:
                #print(A[i][1]+B[j][1]+C[k][1])
                ans=min(ans,A[i][0]+B[j][0]+C[k][0])
print(ans)    
    

Fixed submission:
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
l.sort()
ll=[i for i in range(1,n+1)]
x=[]
for i in range(1,n+1):
    z=list(itertools.combinations(l,i))
    zz=list(itertools.combinations(ll,i))
    for j in range(len(z)):
        x.append([sum(z[j]),(i-1)*10,list(zz[j])])
x.sort()
#print(x)
A=[];B=[];C=[]
for i in range(len(x)):
    A.append([x[i][1]+abs(a-x[i][0]),x[i][2]])
    B.append([x[i][1]+abs(b-x[i][0]),x[i][2]])
    C.append([x[i][1]+abs(c-x[i][0]),x[i][2]])
A.sort();B.sort();C.sort()
#print(A)
#print(B)
#print(C)
m=len(A)
ans=float('inf')
for i in range(m):
    for j in range(m):
        for k in range(m):
            if len(A[i][1]+B[j][1]+C[k][1])>=9:
                break
            elif len(A[i][1]+B[j][1]+C[k][1])==len((set(A[i][1]+B[j][1]+C[k][1]))):
                ans=min(ans,A[i][0]+B[j][0]+C[k][0])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ll=[i for i in range(1,n+1)]
x=[]
for i in range(1,n+1):
    z=list(itertools.combinations(l,i))
    zz=list(itertools.combinations(ll,i))
    for j in range(len(z)):
        x.append([sum(z[j]),(i-1)*10,list(zz[j])])
x.sort()
#print(x)
A=[];B=[];C=[]
for i in range(len(x)):
    A.append([x[i][1]+abs(a-x[i][0]),x[i][2]])
    B.append([x[i][1]+abs(b-x[i][0]),x[i][2]])
    C.append([x[i][1]+abs(c-x[i][0]),x[i][2]])
A.sort();B.sort();C.sort()
m=len(A)
ans=float('inf')
for i in range(m):
    for j in range(m):
        for k in range(m):
            if len(A[i][1]+B[j][1]+C[k][1])!=len((set(A[i][1]+B[j][1]+C[k][1]))):
                continue
            else:
                #print(A[i][1]+B[j][1]+C[k][1])
                ans=min(ans,A[i][0]+B[j][0]+C[k][0])
print(ans)
                
    

Fixed submission:
import itertools
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
l.sort()
ll=[i for i in range(1,n+1)]
x=[]
for i in range(1,n+1):
    z=list(itertools.combinations(l,i))
    zz=list(itertools.combinations(ll,i))
    for j in range(len(z)):
        x.append([sum(z[j]),(i-1)*10,list(zz[j])])
x.sort()
#print(x)
A=[];B=[];C=[]
for i in range(len(x)):
    A.append([x[i][1]+abs(a-x[i][0]),x[i][2]])
    B.append([x[i][1]+abs(b-x[i][0]),x[i][2]])
    C.append([x[i][1]+abs(c-x[i][0]),x[i][2]])
A.sort();B.sort();C.sort()
#print(A)
#print(B)
#print(C)
m=len(A)
ans=float('inf')
for i in range(m):
    for j in range(m):
        for k in range(m):
            if len(A[i][1]+B[j][1]+C[k][1])>=9:
                break
            elif len(A[i][1]+B[j][1]+C[k][1])==len((set(A[i][1]+B[j][1]+C[k][1]))):
                ans=min(ans,A[i][0]+B[j][0]+C[k][0])
print(ans)