stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define all(v) v.begin(), v.end()



// #include <boost/multiprecision/cpp_dec_float.hpp>

// #include <boost/multiprecision/cpp_int.hpp>

// namespace mp = boost::multiprecision;

// using Bint = mp::cpp_int;

// using Real = mp::number<mp::cpp_dec_float<1024>>;



int main(){

    int n, a, b, c;

    cin >> n >> a >> b >> c;

    vector<int> L(n);

    rep(i, n) cin >> L.at(i);

    int ans = INF;

    for(int i = 0; i < (1 << (2 * n)); i++){

        int tmp = i;

        vector<vector<int>> bmb(4);

        rep(j, n){

            bmb.at(tmp % 4).push_back(L.at(j));

            tmp /= 4;

        }

        if(bmb.at(0).size() == 0 || bmb.at(1).size() == 0 || bmb.at(2).size() == 0) continue;

        

        int a_bmb = 0, b_bmb = 0, c_bmb = 0;



        rep(j, bmb.at(0).size()){

            a_bmb += bmb.at(0).at(j);

        }

        rep(j, bmb.at(1).size()){

            b_bmb += bmb.at(1).at(j);

        }

        rep(j, bmb.at(2).size()){

            c_bmb += bmb.at(2).at(j);

        }



        int mp = abs(a_bmb - a) + abs(b_bmb - b) + abs(c_bmb - c);

        rep(j, 3){

            mp += 10 * (bmb.at(j).size() - 1);

        }



        ans = min(ans, mp);

    }



    cout << ans << endl;    

}

// Faster C++ solution for the same problem (measured speedup: 1.2744936447172717x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define all(v) v.begin(), v.end()



// #include <boost/multiprecision/cpp_dec_float.hpp>

// #include <boost/multiprecision/cpp_int.hpp>

// namespace mp = boost::multiprecision;

// using Bint = mp::cpp_int;

// using Real = mp::number<mp::cpp_dec_float<1024>>;



int N, A, B, C;

vector<int> L(10);



int dfs(int cur, int a, int b, int c){

    if(cur == N){

        if(a > 0 && b > 0 && c > 0) return abs(a-A) + abs(b-B) + abs(c-C) - 30;

        else return INF;

    }

    int v1 = dfs(cur + 1, a, b, c);

    int v2 = dfs(cur + 1, a + L.at(cur), b, c) + 10;

    int v3 = dfs(cur + 1, a, b + L.at(cur), c) + 10;

    int v4 = dfs(cur + 1, a, b, c + L.at(cur)) + 10;

    return min(v1, min(v2, min(v3, v4)));

}



int main(){

    cin >> N >> A >> B >> C;

    rep(i, N) cin >> L.at(i);

    int ans = dfs(0, 0, 0, 0);

    cout << ans << endl;    

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <cmath>

using namespace std;



const int INF = 1<<29;



int N;

vector<int> L;

vector<int> A; // A, B, C





// 再帰する

// sums[0] = A に選んだ竹の長さの総和、nums[0] = A に選んだ竹の数

// sums[1] = B に選んだ竹の長さの総和、nums[1] = B に選んだ竹の数

// sums[2] = C に選んだ竹の長さの総和、nums[2] = C に選んだ竹の数

long long rec(vector<int> sums, vector<int> nums, int id) {

    // n 個全部考えたら集計

    if (id == N) {



        // A, B, C いずれも竹は 1 本は必ず使ってないとダメ (これをしないと example 3 は通らない)

        for (int i = 0; i < 3; ++i) {

            if (nums[i] == 0) return INF;

        }

        

        long long score = 0;

        for (int i = 0; i < 3; ++i) {

            score += abs(sums[i] - A[i]); // +1 したり -1 したりする分

            score += (nums[i] - 1) * 10; // 合体した回数

        }

        return score;

    }



    long long res = 1LL<<60; // 無限



    // 今ある竹を採用しない場合

    res = min(res, rec(sums, nums, id+1));



    for (int i = 0; i < 3; ++i) {

        // i = 0: A に採用する場合

        // i = 1: B に採用する場合

        // i = 2: C に採用する場合

        sums[i] += L[id], nums[i]++;

        res = min(res, rec(sums, nums, id+1));

        sums[i] -= L[id], nums[i]--; // 一旦元に戻す (こういうのをバックトラックと呼ぶ)

    }

    

    return res;

}



int main() {

    // 入力

    cin >> N;

    A.resize(3);

    for (int i = 0; i < 3; ++i) cin >> A[i];

    L.resize(N);

    for (int i = 0; i< N; ++i) cin >> L[i];



    // 再帰する

    vector<int> sums(3, 0), nums(3, 0);

    cout << rec(sums, nums, 0) << endl;

}


// Faster C++ solution for the same problem (measured speedup: 4.238829876390509x):
#include <iostream>

#include <vector>

#include <cmath>

using namespace std;

void chmin(int &a, int b) { if (a > b) a = b; }

const int INF = 1<<29;



int N, A, B, C;

vector<int> L;



int rec(int i, int a, int b, int c) {

    // 終端処理

    if (i == N) {

        if (!a || !b || !c) return INF; // A, B, C いずれも竹は 1 本は必ず使ってないとダメ

        return abs(a - A) + abs(b - B) + abs(c - C); // 合体してできた a, b, c を A, B, C にするコスト

    }



    // 今ある竹を採用しない場合

    int res = INF;

    chmin(res, rec(i+1, a, b, c));

    

    // A, B, C を使う場合

    chmin(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));

    chmin(res, rec(i+1, a, b + L[i], c) + (b ? 10 : 0));

    chmin(res, rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));

    

    return res;

}



int main() {

    // 入力

    cin >> N >> A >> B >> C;

    L.resize(N); for (int i = 0; i< N; ++i) cin >> L[i];

    

    // 再帰する

    cout << rec(0, 0, 0, 0) << endl;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <cmath>

using namespace std;



const int INF = 1<<29;



int N;

vector<int> L;

vector<int> A; // A, B, C





// 再帰する

// sums[0] = A に選んだ竹の長さの総和、nums[0] = A に選んだ竹の数

// sums[1] = B に選んだ竹の長さの総和、nums[1] = B に選んだ竹の数

// sums[2] = C に選んだ竹の長さの総和、nums[2] = C に選んだ竹の数

int rec(vector<int> sums, vector<int> nums, int id) {

    // n 個全部考えたら集計

    if (id == N) {



        // A, B, C いずれも竹は 1 本は必ず使ってないとダメ (これをしないと example 3 は通らない)

        for (int i = 0; i < 3; ++i) {

            if (nums[i] == 0) return INF;

        }

        

        long long score = 0;

        for (int i = 0; i < 3; ++i) {

            score += abs(sums[i] - A[i]); // +1 したり -1 したりする分

            score += (nums[i] - 1) * 10; // 合体した回数

        }

        return score;

    }



    int res = INF; // 無限



    // 今ある竹を採用しない場合

    res = min(res, rec(sums, nums, id+1));



    for (int i = 0; i < 3; ++i) {

        // i = 0: A に採用する場合

        // i = 1: B に採用する場合

        // i = 2: C に採用する場合

        sums[i] += L[id], nums[i]++;

        res = min(res, rec(sums, nums, id+1));

        sums[i] -= L[id], nums[i]--; // 一旦元に戻す (こういうのをバックトラックと呼ぶ)

    }

    

    return res;

}



int main() {

    // 入力

    cin >> N;

    A.resize(3);

    for (int i = 0; i < 3; ++i) cin >> A[i];

    L.resize(N);

    for (int i = 0; i< N; ++i) cin >> L[i];



    // 再帰する

    vector<int> sums(3, 0), nums(3, 0);

    cout << rec(sums, nums, 0) << endl;

}


// Faster C++ solution for the same problem (measured speedup: 4.135764006420285x):
#include <iostream>

#include <vector>

#include <cmath>

using namespace std;

void chmin(int &a, int b) { if (a > b) a = b; }

const int INF = 1<<29;



int N, A, B, C;

vector<int> L;



int rec(int i, int a, int b, int c) {

    // 終端処理

    if (i == N) {

        if (!a || !b || !c) return INF; // A, B, C いずれも竹は 1 本は必ず使ってないとダメ

        return abs(a - A) + abs(b - B) + abs(c - C); // 合体してできた a, b, c を A, B, C にするコスト

    }



    // 今ある竹を採用しない場合

    int res = INF;

    chmin(res, rec(i+1, a, b, c));

    

    // A, B, C を使う場合

    chmin(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));

    chmin(res, rec(i+1, a, b + L[i], c) + (b ? 10 : 0));

    chmin(res, rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));

    

    return res;

}



int main() {

    // 入力

    cin >> N >> A >> B >> C;

    L.resize(N); for (int i = 0; i< N; ++i) cin >> L[i];

    

    // 再帰する

    cout << rec(0, 0, 0, 0) << endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(n);i++)

#define ALL(v) (v).begin(),(v).end()

#define int long long

using namespace std;

typedef vector<int>   vint;

typedef pair<int,int> pint;



signed main()

{

    int N,A,B,C;

    cin>>N>>A>>B>>C;

    vint l(N);

    REP(i,N) cin>>l[i];



    int ans=1e9;

    REP(_S,pow(4,N)){

        int a=0,b=0,c=0,cost=0;

        for(int i=0,S=_S;i<N;i++,S/=4){

            int x=S%4;

            if(x==0) if(a>0) cost+=10,a+=l[i]; else a+=l[i];

            if(x==1) if(b>0) cost+=10,b+=l[i]; else b+=l[i];

            if(x==2) if(c>0) cost+=10,c+=l[i]; else c+=l[i];

        }

        if(a and b and c){

            cost+=abs(a-A)+abs(b-B)+abs(c-C);

            ans=min(ans,cost);

        }

    }

    cout<<ans<<endl;

 

}


// Faster C++ solution for the same problem (measured speedup: 4.186119038499713x):
#include<bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(n);i++)

#define ALL(v) (v).begin(),(v).end()

#define int long long

using namespace std;

typedef vector<int>   vint;

typedef pair<int,int> pint;



int N,A,B,C;

vint l;



int rec(int i,int a,int b,int c){

    if(i==N){

        if(!a or !b or !c) return 1e9;

        return abs(a-A)+abs(b-B)+abs(c-C);

    }

    int res=rec(i+1,a,b,c);

    res=min(res,rec(i+1,a+l[i],b,c)+(a>0? 10:0));

    res=min(res,rec(i+1,a,b+l[i],c)+(b>0? 10:0));

    res=min(res,rec(i+1,a,b,c+l[i])+(c>0? 10:0));

    return res;

}



signed main()

{

    cin>>N>>A>>B>>C; 

    l.resize(N);

    REP(i,N) cin>>l[i];

    cout<<rec(0,0,0,0)<<endl;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<algorithm>

using namespace std;



const int INF = 10000000;



int mp(vector<int> used, vector<int> target, vector<int> banboo){

    if (used[0] == target[0]){

        if (min(min(used[1], used[2]), used[3]) == 0)

            return INF;

        else

            return abs(used[1] - target[1]) + abs(used[2] - target[2]) + abs(used[3] - target[3]) - 30;

    }

    int retA = mp({used[0]+1, used[1]+banboo[used[0]], used[2], used[3]}, target, banboo) + 10;

    int retB = mp({used[0]+1, used[1], used[2]+banboo[used[0]], used[3]}, target, banboo) + 10;

    int retC = mp({used[0]+1, used[1], used[2], used[3]+banboo[used[0]]}, target, banboo) + 10;

    int ret0 = mp({used[0]+1, used[1], used[2], used[3]}, target, banboo);

    return min(min(retA, retB), min(retC, ret0));

}



int main(){

    int N, A, B ,C;

    cin >> N >> A >> B >> C;

    vector<int> banboo(N, 0);

    for (size_t i; i < N; ++i){

        cin >> banboo[i];        

    }

    int ret = mp({0,0,0,0}, {N, A, B, C}, banboo);

    cout << ret << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.524108120308448x):
#include "bits/stdc++.h"

using namespace std;

using ll     = long long;

using pii    = pair<int, int>;

using pll    = pair<ll, ll>;

using vi     = vector<int>;

using vl     = vector<ll>;

using vvi    = vector<vi>;

using vvl    = vector<vl>;

const ll INF = 1LL << 60;

const ll MOD = 1000000007;

template <class T>

bool chmax(T &a, const T &b) {

    return (a < b) ? (a = b, 1) : 0;

}

template <class T>

bool chmin(T &a, const T &b) {

    return (b < a) ? (a = b, 1) : 0;

}

template <class C>

void print(const C &c, std::ostream &os = std::cout) {

    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));

    os << std::endl;

}



int n, a, b, c;



int dfs(int x1, int x2, int x3, vi &l, int xn) {

    if (xn == n) {

        if (x1 == 0 || x2 == 0 || x3 == 0)

            return 100000000;

        else

            return abs(x1 - a) + abs(x2 - b) + abs(x3 - c) - 30;

    }

    int ret = 100000000;

    chmin(ret, dfs(x1, x2, x3, l, xn + 1));

    chmin(ret, 10 + dfs(x1 + l[xn], x2, x3, l, xn + 1));

    chmin(ret, 10 + dfs(x1, x2 + l[xn], x3, l, xn + 1));

    chmin(ret, 10 + dfs(x1, x2, x3 + l[xn], l, xn + 1));

    return ret;

}



int main() {

    cin >> n >> a >> b >> c;

    vi l(n);

    for (int i = 0; i < n; ++i) {

        cin >> l[i];

    }

    cout << dfs(0, 0, 0, l, 0) << "\n";

    return 0;

}
// Slower C++ solution:


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define i_7 (ll)(1E9+7)

//#define i_7 998244353

#define i_5 i_7-2

ll mod(ll a){

    ll c=a%i_7;

    if(c>=0)return c;

    else return c+i_7;

}

typedef pair<ll,ll> l_l;

ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)

#define pb push_back

ll max(ll a,ll b){if(a<b)return b;else return a;}

ll min(ll a,ll b){if(a>b)return b;else return a;}

void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);

void Min(ll &pos,ll val){pos=min(pos,val);}

void Add(ll &pos,ll val){pos=mod(pos+val);}

long double EPS=1E-9;

#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

////////////////////////////////////////



ll cal(vector<ll>v,ll s){

    ll sum=0;for(auto x:v)sum+=x;

    ll res=(v.size()-1)*10+abs(sum-s);

    return res;

}



int main(){fastio;

    

    ll n,a[3];cin>>n;rep(i,0,2)cin>>a[i];

    ll l[n];rep(i,0,n-1)cin>>l[i];

    ll ans=inf;

    rep(i,0,(1<<(2*n))-1){

        vector<ll>x[4];

        for(ll j=0;j<=2*n-2;j+=2){

            ll k=(i>>j)&3;

            x[k].pb(l[j/2]);

        }

        ll sum=0;

        rep(u,0,2){

            if(x[u].size()==0)sum=inf;

            else sum+=cal(x[u],a[u]);

        }

        Min(ans,sum);

    }

    cout<<ans<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.333441043801772x):


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define i_7 (ll)(1E9+7)

//#define i_7 998244353

#define i_5 i_7-2

ll mod(ll a){

    ll c=a%i_7;

    if(c>=0)return c;

    else return c+i_7;

}

typedef pair<ll,ll> l_l;

ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)

#define pb push_back

ll max(ll a,ll b){if(a<b)return b;else return a;}

ll min(ll a,ll b){if(a>b)return b;else return a;}

void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);

void Min(ll &pos,ll val){pos=min(pos,val);}

void Add(ll &pos,ll val){pos=mod(pos+val);}

long double EPS=1E-9;

#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

////////////////////////////////////////

#define N 10

ll n,x,y,z;

ll l[N];



ll dfs(ll p,ll a,ll b,ll c){

    if(p==n){

        if(a*b*c==0)return inf;

        ll res=abs(a-x)+abs(b-y)+abs(c-z)-30;

        return res;

    }

    ll res=inf;

    Min(res,dfs(p+1,a,b,c));

    Min(res,dfs(p+1,a+l[p],b,c)+10);

    Min(res,dfs(p+1,a,b+l[p],c)+10);

    Min(res,dfs(p+1,a,b,c+l[p])+10);

    return res;

}



int main(){fastio;

    cin>>n>>x>>y>>z;

    rep(i,0,n-1)cin>>l[i];

    cout<<dfs(0,0,0,0)<<endl;

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <map>

#include <list>

#include <stack>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <queue>

#define mkp(a, b) make_pair(a, b)

#define pb(t) push_back(t)

#define ft first

#define sc second

#define pt(num) cout << num << "\n"

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

#define max(a, b) ((a)>(b) ? (a):(b))

#define min(a, b) ((a)<(b) ? (a):(b))

#define chmax(a, b) (a<b ? a=b : 0)

#define chmin(a, b) (a>b ? a=b : 0)

#define INF 1000000000000000000

#define MOD 1000000007LL

#define MAX 101010

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

typedef map<ll, ll> Map;



ll N;

ll l[10];

ll a, b, c;



ll dfs(string s) {

    ll res=INF;

    

    if(s.size()==N) {

        ll ta=0, tb=0, tc=0;

        ll cnt=N;

        for(ll i=0; i<N; i++) {

            if(s[i]=='0') ta+=l[i];

            else if(s[i]=='1') tb+=l[i];

            else if(s[i]=='2') tc+=l[i];

            else cnt--;

        }

        

        if(ta==0 || tb==0 || tc==0) return INF;

        return abs(ta-a)+abs(tb-b)+abs(tc-c)+10*(cnt-3);

    }

    

    for(char c='0'; c<'4'; c++)

        chmin(res, dfs(s+c));

    

    return res;

}



int main(void) {

    cin >> N;

    cin >> a >> b >> c;

    for(ll i=0; i<N; i++) cin >> l[i];

    

    pt(dfs(""));

}






// Faster C++ solution for the same problem (measured speedup: 1.2608793154599007x):
#include <iostream>

#include <cmath>

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <map>

#include <list>

#include <stack>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <queue>

#define mkp(a, b) make_pair(a, b)

#define pb(t) push_back(t)

#define ft first

#define sc second

#define pt(num) cout << num << "\n"

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

#define max(a, b) ((a)>(b) ? (a):(b))

#define min(a, b) ((a)<(b) ? (a):(b))

#define chmax(a, b) (a<b ? a=b : 0)

#define chmin(a, b) (a>b ? a=b : 0)

#define INF 1000000000000000000

#define MOD 1000000007LL

#define MAX 101010

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

typedef map<ll, ll> Map;



ll N;

ll l[10];

ll a, b, c;



ll dfs(ll cur, ll ta, ll tb, ll tc) {

    if(cur==N) {

        if(min(ta, min(tb, tc))>0)

            //-30:竹の分類先を決めるたびに+10しているのでそれぞれ一回分余計に合成のMPが足されているため

            //(k本の竹を1本にするのに必要なMPは(k-1)*10)

            return abs(a-ta)+abs(b-tb)+abs(c-tc)-30;

        

        else

            return INF;

    }

    

    ll res=INF;

    chmin(res, dfs(cur+1, ta, tb, tc));

    chmin(res, dfs(cur+1, ta+l[cur], tb, tc)+10);

    chmin(res, dfs(cur+1, ta, tb+l[cur], tc)+10);

    chmin(res, dfs(cur+1, ta, tb, tc+l[cur])+10);

    return res;

}



int main(void) {

    cin >> N;

    cin >> a >> b >> c;

    for(ll i=0; i<N; i++) cin >> l[i];

    

    pt(dfs(0, 0, 0, 0));

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)

#define TO(x,t,f) ((x)?(t):(f))

#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted

#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted

#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted

#define REV(x) (reverse(x.begin(),x.end())) //reverse

ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}

ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu

#define NEXTP(x) next_permutation(x.begin(),x.end())

const ll INF=1e18+7;

const ll MOD=1e9+7;



int main(){

	ll N,A,B,C;

	cin >> N >> A >> B >> C;

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	ll ans = INF;

	ll K = 1;

	FOR(i,0,N)K*=3;

	FOR(i,0,K){

		ll p = i;

		vector<ll> a,b,c;

		FOR(j,0,N){

			if(p%3==0)a.push_back(L[j]);

			if(p%3==1)b.push_back(L[j]);

			if(p%3==2)c.push_back(L[j]);

			p /= 3;

		}

		vector<P> dpa,dpb,dpc;

		for(auto x:a){

			vector<P> d;

			d.push_back({x,0});

			for(auto y:dpa){

				d.push_back(y);

				d.push_back({y.first+x,y.second+10});

			}

			dpa = d;

		}

		for(auto x:b){

			vector<P> d;

			d.push_back({x,0});

			for(auto y:dpb){

				d.push_back(y);

				d.push_back({y.first+x,y.second+10});

			}

			dpb = d;

		}

		for(auto x:c){

			vector<P> d;

			d.push_back({x,0});

			for(auto y:dpc){

				d.push_back(y);

				d.push_back({y.first+x,y.second+10});

			}

			dpc = d;

		}

		ll mina=INF,minb=INF,minc=INF;

		for(auto x:dpa)mina = min(mina,x.second+abs(x.first-A));

		for(auto x:dpb)minb = min(minb,x.second+abs(x.first-B));

		for(auto x:dpc)minc = min(minc,x.second+abs(x.first-C));

		ans = min(ans,minc+minb+mina);

	}

	cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.204518412131228x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

const ll INF=1e16+7;

int main(){

	ll N,A[3],ans=INF,K=1;

	cin >> N >> A[0] >> A[1] >> A[2];

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	FOR(i,0,N)K*=4;

	FOR(t,0,K){

		vector<P> a={{0,0},{0,0},{0,0}};

		ll p = t;

		FOR(i,0,N){

			if(p%4!=3){

				a[p%4].first+=L[i];

				a[p%4].second++;

			}

			p /= 4;

		}

		FOR(i,0,3)p+=abs(a[i].first-A[i]);

		FOR(i,0,3)p+=(a[i].second-1)*10;

		FOR(i,0,3)if(a[i].second==0)p=INF;

		ans = min(ans,p);

	}

	cout << ans << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

const ll INF=1e18+7;

int main(){

	ll N;

	vector<ll> A(3);

	cin >> N >> A[0] >> A[1] >> A[2];

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	ll ans = INF;

	ll K = 1;

	FOR(i,0,N)K*=3;

	FOR(i,0,K){

		ll p = i;

		vector<ll> a[3];

		FOR(j,0,N)a[p%3].push_back(L[j]),p/=3;

		vector<P> dp[3];

		FOR(j,0,3){

			for(auto x:a[j]){

				vector<P> dpp;

				dpp.push_back({x,0});

				for(auto y:dp[j]){

					dpp.push_back(y);

					dpp.push_back({y.first+x,y.second+10});

				}

				dp[j] = dpp;

			}

		}

		vector<ll> mina(3,INF);

		FOR(j,0,3)

			for(auto x:dp[j])

				mina[j] = min(mina[j],x.second+abs(x.first-A[j]));

		ans = min(ans,mina[0]+mina[1]+mina[2]);

	}

	cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 2.234780698883307x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

const ll INF=1e16+7;

int main(){

	ll N,A[3],ans=INF,K=1;

	cin >> N >> A[0] >> A[1] >> A[2];

	vector<ll> L(N);

	FOR(i,0,N)cin>>L[i];

	FOR(i,0,N)K*=4;

	FOR(t,0,K){

		vector<P> a={{0,0},{0,0},{0,0}};

		ll p = t;

		FOR(i,0,N){

			if(p%4!=3){

				a[p%4].first+=L[i];

				a[p%4].second++;

			}

			p /= 4;

		}

		FOR(i,0,3)p+=abs(a[i].first-A[i]);

		FOR(i,0,3)p+=(a[i].second-1)*10;

		FOR(i,0,3)if(a[i].second==0)p=INF;

		ans = min(ans,p);

	}

	cout << ans << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const long long INF = 1LL << 60;



template <class T> bool chmin(T& a, T b)

{

  if (a > b) {

    a = b; return true;

  } else return false;

}



template <class T> bool chmax(T& a, T b)

{

  if (a < b) {

    a = b; return true;

  } else return false;

}





int main()

{

  int N, A, B, C;

  cin >> N >> A >> B >> C;

  vector<int> l(N);

  for (int i = 0; i < N; i++) cin >> l.at(i);

  

  long long ans = INF;

  

  for (int i = 0; i < pow(4, N); i++)

  {

    long long at = 0, bt = 0, ct = 0;

    long long al = 0, bl = 0, cl = 0;

    

    for (int j = 0; j < N; j++)

    {

      int p = pow(4, j);

      int Z = (i / p) % 4;

      if (Z == 1) {at++; al += l.at(j);}

      else if (Z == 2) {bt++; bl += l.at(j);}

      else if (Z == 3) {ct++; cl += l.at(j);}

    }

    

    if (at > 0 && bt > 0 && ct > 0)

    {

      long long MP = (at + bt + ct - 3) * 10 

                    + abs(A - al) + abs(B - bl) + abs(C - cl);

      chmin(ans, MP);

    }

  }

  

  cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.1349337397679438x):
#include <bits/stdc++.h>

using namespace std;



const long long INF = 1LL << 60;



template <class T> bool chmin(T& a, T b)

{

  if (a > b) {

    a = b; return true;

  } else return false;

}



template <class T> bool chmax(T& a, T b)

{

  if (a < b) {

    a = b; return true;

  } else return false;

}





int main()

{

  int N, A, B, C;

  cin >> N >> A >> B >> C;

  vector<int> l(N);

  for (int i = 0; i < N; i++) cin >> l.at(i);

  

  long long ans = INF;

  

  for (int i = 0; i < pow(4, N); i++)

  {

    long long at = 0, bt = 0, ct = 0;

    long long al = 0, bl = 0, cl = 0;

    

    for (int j = 0, p = 1; j < N; j++)

    {

      int Z = (i / p) % 4;

      if (Z == 1) {at++; al += l.at(j);}

      else if (Z == 2) {bt++; bl += l.at(j);}

      else if (Z == 3) {ct++; cl += l.at(j);}

      p *= 4;

    }

    

    if (at > 0 && bt > 0 && ct > 0)

    {

      long long MP = (at + bt + ct - 3) * 10 

                    + abs(A - al) + abs(B - bl) + abs(C - cl);

      chmin(ans, MP);

    }

  }

  

  cout << ans << endl;

}