import std.stdio, std.string, std.conv;
import std.algorithm;

void main()
{
    auto buf = readln.chomp.split;
    immutable n = buf[0].to!size_t;
    auto target = buf[1..$].to!(int[]);
    int[] current;
    foreach (i; 0..n)
        current ~= readln.chomp.to!int;
    solve(n, target, current).writeln;
}

int solve(in size_t n, in int[] target, in int[] current)
{
    auto ret = int.max;
outer:
    foreach (p; 0..1<<(n*2))
    {
        auto sums = new int[3], counts = new int[3];
        auto _p = p;
        foreach (i; 0..n)
        {
            auto r = _p & 3;
            _p >>= 2;
            if (r < 3)
            {
                sums[r] += current[i];
                counts[r] += 1;
            }
        }
        int cs;
        foreach (r; 0..3)
        {
            if (!sums[r])
                continue outer;
            cs += (counts[r] - 1) * 10;
            if (sums[r] > target[r])
                cs += sums[r] - target[r];
            else
                cs += target[r] - sums[r];
        }
        ret = ret.min(cs);
    }
    return ret;
}
