def able(lens):
    ret = [0]
    for i in lens:
        temp = []
        for j in ret:
            temp.append(i + j)
        
        for k in temp:
            ret.append(k)
    ret.remove(0)
    return ret

def choice(ls, tar):
    mind = max(ls)
    theni = len(ls)
    #tar = 1000
    for i in range (len(ls)-1):
        if abs(ls[i] - tar) < mind:
            mind = abs(ls[i] - tar)
            theni = i
            if mind == 0:
                break
    #print(theni, mind)
    #print(theni, mind)
    #print(ls)
    return [theni, mind]

def conv(n):
    t_ = list(map(int, list(str(bin(n))[2:])))
    t_.reverse()
    return t_

ins = list(map(int, input().split()))
n = ins[0]
targs = (ins[1:]).sort()
lengths = [int(input()) for i in range(n)]


def solve(ls,ts):
    point = 0
    for tar in ts:
        com = choice(able(ls), tar)
        point += com[1]
        target = conv(com[0] + 1)
        point += (sum(target) - 1) * 10
        
        k = 0
        for i in range(len(target)):
            
            if (target[i] == 1) and (len(ls)-1 > i-k):
                #print(i-k)
                ls.pop(i - k)
                k += 1
        print(lengths, point)
        
    return point
    
print(solve(lengths, targs))