#include <bits/stdc++.h>

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using usize = std::size_t;
using namespace std;

#define rep(i, max) for(usize i = 0; i < max; ++i)
#define loop while(true)
#define allOf(collection) collection.begin(), collection.end()

unique_ptr<string> readLine() { unique_ptr<string> line(new string()); getline(cin, *line); return line; }
template<typename T1, typename T2> pair<T1, T2> readPair() { T1 res1; cin >> res1; T2 res2; cin >> res2; readLine(); return make_pair(res1, res2);}
template<typename T> unique_ptr<vector<T>> readVector(usize num) { unique_ptr<vector<T>> list(new vector<T>(num)); rep(i, num) cin >> (*list)[i]; readLine(); return list; }
void readValues() { readLine(); }
template<typename H, typename... T> void readValues(H& head, T&&... tails){ H a; cin >> a; head = a; readValues(forward<T>(tails)...); }
void writeLine() { cout << endl; }
template<typename T> void write(const T& arg) { cout << arg; }
template<typename T> void writeLine(const vector<T>& arg){ if(arg.empty()) { writeLine(); return; } write(arg[0]); for(int i = 1; i < arg.size(); ++i){ write(" "); write(arg[i]); } writeLine(); }
template<typename T> void writeLine(const T& arg) { cout << arg << endl; }
void recursiveCombination(vector<i32>& indexes, i32 s, i32 rest, function<void(vector<i32>&)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursiveCombination(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursiveCombination(indexes, s - 1, rest - 1, f); } }
void foreachWithCombination(i32 n, i32 k, function<void(vector<i32>&)> f) { auto indexes = vector<i32>(k); recursiveCombination(indexes, n - 1, k, f); }
void foreachWithPermutaton(i32 n, function<void(vector<i32>&)> f) { auto indexes = vector<i32>(); indexes.reserve(n); rep(i, (usize)n) indexes.push_back(i); do f(indexes); while (next_permutation(allOf(indexes))); }
void foreachWithPermutaton(i32 n, i32 k, function<void(vector<i32>&)> f){ foreachWithCombination(n, k, [=](vector<i32>& combIndexes){ foreachWithPermutaton(k, [=](vector<i32>& permIndexes){ auto indexes = vector<i32>(); indexes.reserve(k); rep(i, (usize)k){ indexes.push_back(combIndexes[permIndexes[i]]); } f(indexes); }); }); }
void program();
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    program();
}

struct informations{
    i32 index;
    i32 joinCount;
    i32 aSum;
    i32 bSum;
    i32 cSum;

    informations(i32 index, i32 joinCount, i32 aSum, i32 bSum, i32 cSum) {
        this->index = index;
        this->joinCount = joinCount;
        this->aSum = aSum;
        this->bSum = bSum;
        this->cSum = cSum;
    }
};

void program() {
    i32 n, a, b, c;
    readValues(n, a, b, c);
    vector<i32> l;
    l = *readVector<i32>(n);

    i32 minimum = INT32_MAX;
    stack<informations> stak = stack<informations>();
    stak.emplace(0, 0, 0, 0, 0);
    while(!stak.empty()){
        informations info = stak.top();
        stak.pop();
        if(info.index == n) {
            if(info.aSum != 0 && info.bSum != 0 && info.cSum != 0)
                minimum = min(minimum, 10 * info.joinCount + abs(info.aSum - a) + abs(info.bSum - b) + abs(info.cSum - c));
        }else{
            stak.emplace(info.index + 1, info.joinCount, info.aSum, info.bSum, info.cSum);
            stak.emplace(info.index + 1, info.aSum == 0 ? info.joinCount : info.joinCount + 1, info.aSum + l[info.index], info.bSum, info.cSum);
            stak.emplace(info.index + 1, info.bSum == 0 ? info.joinCount : info.joinCount + 1, info.aSum, info.bSum + l[info.index], info.cSum);
            stak.emplace(info.index + 1, info.cSum == 0 ? info.joinCount : info.joinCount + 1, info.aSum, info.bSum, info.cSum + l[info.index]);
        }
    }

    writeLine(minimum);
}

Measured memory_bytes: 3604