#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {
    ll N,C,B,A;

    vector<ll> l;
    cin >> N >> A >> B >> C;
    for (int i = 0; i < 8; ++i) {
        ll la;
        if(i < N) {
            cin >> la;
            l.push_back(la);
        }else{
            l.push_back(0);
        }
    }

    int a =0;
    int b =0;
    int c =0;
    
    ll result = 3000000;

    sort(l.begin(),l.end());
    for (int l0 = 0; l0 < 4; ++l0) {
        for (int l1 = 0; l1 < 4; ++l1) {
            for (int l2 = 0; l2 < 4; ++l2) {
                for (int l3 = 0; l3 < 4; ++l3) {
                    for (int l4 = 0; l4 < 4; ++l4) {
                        for (int l5 = 0; l5 < 4; ++l5) {
                            for (int l6 = 0; l6 < 4; ++l6) {
                                for (int l7 = 0; l7 < 4; ++l7) {
                                    a = b = c = 0;
                                    int count = 0;
                                    if(l0 == 0){
                                        if(a != 0 && l[0] != 0){
                                            count++;
                                        }
                                        a += l[0];
                                    }
                                    if(l0 == 1){
                                        if(b != 0 && l[0] != 0){
                                            count++;
                                        }
                                        b += l[0];
                                    }
                                    if(l0 == 2){
                                        if(c != 0 && l[0] != 0){
                                            count++;
                                        }
                                        c += l[0];
                                    }
                                    if(l1 == 0){
                                        if(a != 0 && l[1] != 0){
                                            count++;
                                        }
                                        a += l[1];
                                    }
                                    if(l1 == 1){
                                        if(b != 0 && l[1] != 0){
                                            count++;
                                        }
                                        b += l[1];
                                    }
                                    if(l1 == 2){
                                        if(c != 0 && l[1] != 0){
                                            count++;
                                        }
                                        c += l[1];
                                    }
                                    if(l2 == 0){
                                        if(a != 0 && l[2] != 0){
                                            count++;
                                        }
                                        a += l[2];
                                    }
                                    if(l2 == 1){
                                        if(b != 0 && l[2] != 0){
                                            count++;
                                        }
                                        b += l[2];
                                    }
                                    if(l2 == 2){
                                        if(c != 0 && l[2] != 0){
                                            count++;
                                        }
                                        c += l[2];
                                    }
                                    if(l3 == 0){
                                        if(a != 0 && l[3] != 0){
                                            count++;
                                        }
                                        a += l[3];
                                    }
                                    if(l3 == 1){
                                        if(b != 0 && l[3] != 0){
                                            count++;
                                        }
                                        b += l[3];
                                    }
                                    if(l3 == 2){
                                        if(c != 0 && l[3] != 0){
                                            count++;
                                        }
                                        c += l[3];
                                    }
                                    if(l4 == 0){
                                        if(a != 0 && l[4] != 0){
                                            count++;
                                        }
                                        a += l[4];
                                    }
                                    if(l4 == 1){
                                        if(b != 0 && l[4] != 0){
                                            count++;
                                        }
                                        b += l[4];
                                    }
                                    if(l4 == 2){
                                        if(c != 0 && l[4] != 0){
                                            count++;
                                        }
                                        c += l[4];
                                    }
                                    if(l5 == 0){
                                        if(a != 0 && l[5] != 0){
                                            count++;
                                        }
                                        a += l[5];
                                    }
                                    if(l5 == 1){
                                        if(b != 0 && l[5] != 0){
                                            count++;
                                        }
                                        b += l[5];
                                    }
                                    if(l5 == 2){
                                        if(c != 0 && l[5] != 0){
                                            count++;
                                        }
                                        c += l[5];
                                    }
                                    if(l6 == 0){
                                        if(a != 0 && l[6] != 0){
                                            count++;
                                        }
                                        a += l[6];
                                    }
                                    if(l6 == 1){
                                        if(b != 0 && l[6] != 0){
                                            count++;
                                        }
                                        b += l[6];
                                    }
                                    if(l6 == 2){
                                        if(c != 0 && l[6] != 0){
                                            count++;
                                        }
                                        c += l[6];
                                    }
                                    if(l7 == 0){
                                        if(a != 0 && l[7] != 0){
                                            count++;
                                        }
                                        a += l[7];
                                    }
                                    if(l7 == 1){
                                        if(b != 0 && l[7] != 0){
                                            count++;
                                        }
                                        b += l[7];
                                    }
                                    if(l7 == 2){
                                        if(c != 0 && l[7] != 0){
                                            count++;
                                        }
                                        c += l[7];
                                    }
                                    ll r = abs(A - a) + abs(B - b) + abs(C - c)+ count * 10;
                                    if(r < result && a != 0 && b!= 0 && c != 0){
                                        //cout << "absA" << abs(A-a) << " absB" << abs(B-b)<< " absC" << abs(C -c) << " count" << count << endl;
                                        result = r;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << result << endl;


    return 0;
}

Measured memory_bytes: 256