local n = io.read("n")
local c = io.read("n")
local b = io.read("n")
local a = io.read("n")
function pay(x,y,z)
    return math.abs(x-a)+math.abs(y-b)+math.abs(z-c)
end
local mem = {}
function dfs(arr)
    local arrstr = table.concat(arr,":")
    if mem[arrstr] then
        return mem[arrstr]
    end
    mem[arrstr] = math.huge
    for i=1,#arr do
        for j=i+1, #arr do
            for k=j+1, #arr do
                cnt = pay(arr[i],arr[j],arr[k])
                if cnt < mem[arrstr] then
                    mem[arrstr] = cnt
                end
            end
        end
    end

    if #arr > 3 then
        for i=1,#arr do
            for j=i+1,#arr do
                local newarr = {}
                for k=1,#arr do
                    if k ~= i and k ~= j then
                        newarr[#newarr+1] = arr[k]
                    end
                end
                newarr[#newarr+1] = arr[i]+arr[j]
                table.sort(newarr)
                local newv = 10 + dfs(newarr)
                if newv < mem[arrstr] then
                    mem[arrstr] = newv
                end
            end
        end
    end

    return mem[arrstr]
end

local bamboos = {}


for i=1,n do
    bamboos[i] = io.read("n")
end
table.sort(bamboos)
print(dfs(bamboos))