stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



const int MOD = (int)1e9+7;



int main(){

  long long N,A,B,C;

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

  vector<long long> l(N);

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



  long long ans=1e18;

  for(int bit=0;bit<(1<<(N*2));bit++){

    long long cost=0;

    vector<long long> a;

    vector<long long> b;

    vector<long long> c;

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

      if((bit&(1<<i)) && (bit&(1<<(i+1))))  c.push_back(i/2);

      else if((!(bit&(1<<i))) && (bit&(1<<(i+1))))  b.push_back(i/2);

      else if((bit&(1<<i)) && (!(bit&(1<<(i+1)))))  a.push_back(i/2);

    }

    if(a.size()==0 || b.size()==0 || c.size()==0) continue;

    

    long long ax=0;

    long long bx=0;

    long long cx=0;

    for(int i=0;i<a.size();i++){

      ax+=l.at(a.at(i));

      if(i!=0)  cost+=10;

    }

    for(int i=0;i<b.size();i++){

      bx+=l.at(b.at(i));

      if(i!=0)  cost+=10;

    }

    for(int i=0;i<c.size();i++){

      cx+=l.at(c.at(i));

      if(i!=0)  cost+=10;

    }

    cost=cost+abs(ax-A)+abs(bx-B)+abs(cx-C);

    ans=min(ans,cost);

  }

  cout << ans << endl;



  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const int MOD = (int)1e9+7;



void dfs(vector<int> &l,int N,vector<int> &ABC,int now,int a,int b,int c,int cost,int &ans){

	if(now>=N){

		if(a!=0 && b!=0 && c!=0)  ans=min(ans,cost+abs(ABC.at(0)-a)+abs(ABC.at(1)-b)+abs(ABC.at(2)-c));

		return;

	}

	dfs(l,N,ABC,now+1,a,b,c,cost,ans);

	dfs(l,N,ABC,now+1,a+l.at(now),b,c,cost+10*(a>0),ans);

	dfs(l,N,ABC,now+1,a,b+l.at(now),c,cost+10*(b>0),ans);

	dfs(l,N,ABC,now+1,a,b,c+l.at(now),cost+10*(c>0),ans);

}



int main(){

  int N;

  cin >> N;

  vector<int> ABC(3);

  for(int i=0;i<3;i++)  cin >> ABC.at(i);

  vector<int> l(N);

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



  int ans=1e9;

  dfs(l,N,ABC,0,0,0,0,0,ans);

  cout << ans << endl;



  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cmath>

#include <algorithm>

#include <stack>

#include <string>

#include <vector>

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

using namespace std;



int main(){

    int n;  cin >> n;

    int a[3];

    rep(i, 3)	cin >> a[i];

    vector<int>l(n);

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

    //solve

    int ans = 1000000000;

    stack<string>st;	//0:使用しない 1:a 2:b 3:c

    st.push("");

    while(!st.empty()){

	string now = st.top();

	st.pop();

	if(now.size() == n){	//それぞれの竹の割り振り完了時

	    int mp = 0;

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

	    rep(i, n){

		bam[now[i]-'0'].push_back(l[i]);

	    }

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

		while(bam[i].size() >= 2){  //それぞれを合成

		    bam[i][0] += bam[i][bam[i].size()-1];

		    bam[i].pop_back();

		    mp += 10;

		}

	    }

	    //この時点でbam[i]のそれぞれの要素は一つまたはゼロ

	    bool flag = true;	//true:各要素に一つ以上竹がある

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

		if(bam[i].empty()){

		    flag = false;

		}else{

		    mp += abs(a[i-1]-bam[i][0]);

		}

	    }

	    if(!flag)	continue;

	    ans = min(ans, mp);

	}else{

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

		string next = now + to_string(i);

		st.push(next);

	    }

	}

    }

    cout << ans << endl;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <utility>

#include <algorithm>

#include <vector>

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

const int INF = 1e9;

using namespace std;



int n;

vector<int>len(3);

int ans = INF;

vector<pair<int, int> >now(4, pair<int, int>(0, 0));

void dfs(int depth, vector<int>&l){

    if(depth < n){

	rep(i, 4){

	    now[i].first += l[depth];

	    now[i].second++;

	    dfs(depth+1, l);

	    now[i].first -= l[depth];

	    now[i].second -= 1;

	}

    }else{

	int tmp = 0;

	rep(i, 3){

	    if(now[i].second == 0)  return;

	    tmp += abs(len[i]-now[i].first)+10*(now[i].second-1);

	}

	ans = min(ans, tmp);

    }

}



int main(){

    cin >> n;

    rep(i, 3)	cin >> len[i];

    vector<int>l(n);

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

    dfs(0, l);

    cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;    

}

// Optimized solution to the same problem (faster):
#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;    

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

 

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


#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;

}


// Optimized solution to the same problem (faster):


#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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(""));

}






// Optimized solution to the same problem (faster):
#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));

}






// Fastest known solution for this problem: