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

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

#define pb(q) push_back(q)

typedef long long ll;

using namespace std;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n,a,b,c,ans=10000000,num=0,suma=0,sumb=0,sumc=0;

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

    int l[n];

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

    	cin>>l[i];

    }

  ll ma=pow(4,n);

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

    	vector<int> v;

        ll maki=i;

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

           v.pb(maki%4);

           maki/=4;

        }

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

    			if(v[i]==0){

    				if(suma!=0){

    						num+=10;

    					}

    					suma+=l[i];

                }

    			else if(v[i]==1){

                     if(sumb!=0){

    						num+=10;

    					}

    					sumb+=l[i];         

                }

    			else if(v[i]==2){

    					if(sumc!=0){

    						num+=10;

    					}

    					sumc+=l[i];

    				}

    		}

    		num+=(abs(a-suma)+abs(b-sumb)+abs(c-sumc));

    		if(suma!=0 && sumb!=0 && sumc!=0){

    			ans=min(ans,num);

    		}

    		num=0,suma=0,sumb=0,sumc=0;

    

    	

    }

    cout <<ans<<endl;

    return 0;

}




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

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

#define pb(q) push_back(q)

typedef long long ll;

using namespace std;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n,a,b,c,ans=1e9,num=0,suma=0,sumb=0,sumc=0;

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

    int l[n];

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

        cin>>l[i];

    }

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

        int v;

        int w=i;

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

            v=w%4;

            w/=4;

            if(v==0){

                if(suma){

                    num+=10;

                }

                suma+=l[j];

            }

            else if(v==1){

                if(sumb){

                    num+=10;

                }

                sumb+=l[j];         

            }

            else if(v==2){

                if(sumc){

                    num+=10;

                }

                sumc+=l[j];

            }

        }

        num+=(abs(a-suma)+abs(b-sumb)+abs(c-sumc));

        if(suma&&sumb&&sumc){

            ans=min(ans,num);

        }

        num=suma=sumb=sumc=0;

    }

    cout <<ans<<endl;

    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, a, b) for (int i = a; i < b; i++)

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

//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122



int main() {

    int n, a, b, c;

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

    int l[n];

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



    int ans = 1000000000;

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

        int sum_a = 0;

        int mp_a = 0;

        bool used_a[n] = {};

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

            if (i & (1 << j)) {

                if (sum_a != 0) mp_a += 10;

                sum_a += l[j];

                used_a[j] = true;

            }

        }



        for (int k = 1; k < (1 << n); k++) {

            int sum_b = 0;

            int mp_b = 0;

            bool used_b[n] = {};

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

                if (k & (1 << m) && !used_a[m]) {

                    if (sum_b != 0) mp_b += 10;

                    sum_b += l[m];

                    used_b[m] = true;

                }

            }



            for (int p = 1; p < (1 << n); p++) {

                int sum_c = 0;

                int mp_c = 0;

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

                    if (p & (1 << q) && !used_a[q] && !used_b[q]) {

                        if (sum_c != 0) mp_c += 10;

                        sum_c += l[q];

                    }

                }



                if (!sum_b || !sum_c) continue;

                int mpsum = 0;

                mpsum += (mp_a + mp_b + mp_c);

                mpsum += (abs(sum_a - a) + abs(sum_b - b) + abs(sum_c -c));

                ans = min(ans, mpsum);

            }



        }





    }



    cout << ans << endl;

    return 0;

}


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

using namespace std;

typedef long long ll;

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)

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

const int MOD = 1e9 + 7;

const int INF = 1e9;

//'a' = 65, 'Z' = 90, 'a' = 97, 'z' = 122



int n, a, b, c;

int l[10];

int ans = INF;



int calc(string s) {

    int mp = 0;

    int cnt[3] = {};

    int suml[3] = {};

    rep(i, 0, s.size()) {

        int c = s[i] - '0';

        if (c == 3) continue;

        cnt[c]++;

        suml[c] += l[i];

    }

    rep(i, 0, 3) mp += (cnt[i] - 1) * 10;

    mp += abs(suml[0] - a) + abs(suml[1] - b) + abs(suml[2] - c);

    return mp;

}



void dfs(string s, int a, int b, int c) {

    if ((int)s.size() == n) {

        if (a && b && c) ans = min(ans, calc(s));

        return;

    }

    dfs(s + '0', 1, b, c);

    dfs(s + '1', a, 1, c);

    dfs(s + '2', a, b, 1);

    dfs(s + '3', a, b, c);

}



int main() {

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

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

    dfs("", 0, 0, 0);

    cout << ans << endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define int long long

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

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }



const int INF = 1e18;



int N, A, B, C;

vector<int> l;



// Aに使う竹の集合、Bに使う竹の集合、Cに使う竹の集合を渡すと、作りたい竹にするのにかかるコストを返してくれる

int calc(vector<int> a, vector<int> b, vector<int> c) {

  int aRes = abs(accumulate(all(a), 0LL) - A) + ((a.size()-1) * 10);

  int bRes = abs(accumulate(all(b), 0LL) - B) + ((b.size()-1) * 10);

  int cRes = abs(accumulate(all(c), 0LL) - C) + ((c.size()-1) * 10);



  return aRes + bRes + cRes;

}



int rec(int idx, vector<int> a, vector<int> b, vector<int> c) {

  if (idx >=  N) {

    if (a.size() == 0 or b.size() == 0 or c.size() == 0) return INF;

    return calc(a, b, c);

  }



  int ret = INF;



  // idx番目の竹をAに使う

  a.push_back(l[idx]);

  chmin(ret, rec(idx+1, a, b, c));

  a.pop_back();



  // idx番目の竹をBに使う

  b.push_back(l[idx]);

  chmin(ret, rec(idx+1, a, b, c));

  b.pop_back();



  // idx番目の竹をCに使う

  c.push_back(l[idx]);

  chmin(ret, rec(idx+1, a, b, c));

  c.pop_back();



  // idx番目の竹を使わない

  chmin(ret, rec(idx+1, a, b, c));



  return ret;

}



signed main() {

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

  l.resize(N);

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

    cin >> l[i];

  }



  vector<int> a;

  vector<int> b;

  vector<int> c;

  cout << rec(0, a, b, c) << endl;



  return 0;

}

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

using namespace std;



#define int long long

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

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }



const int INF = 1e18;



int N, A, B, C;

vector<int> l;



// Aに使う竹の集合、Bに使う竹の集合、Cに使う竹の集合を渡すと、作りたい竹にするのにかかるコストを返してくれる

int calc(vector<int> &a, vector<int> &b, vector<int> &c) {

  int aRes = abs(accumulate(all(a), 0LL) - A) + ((a.size()-1) * 10);

  int bRes = abs(accumulate(all(b), 0LL) - B) + ((b.size()-1) * 10);

  int cRes = abs(accumulate(all(c), 0LL) - C) + ((c.size()-1) * 10);



  return aRes + bRes + cRes;

}



int rec(int idx, vector<int> &a, vector<int> &b, vector<int> &c) {

  if (idx >=  N) {

    if (a.size() == 0 or b.size() == 0 or c.size() == 0) return INF;

    return calc(a, b, c);

  }



  int ret = INF;



  // idx番目の竹をAに使う

  a.push_back(l[idx]);

  chmin(ret, rec(idx+1, a, b, c));

  a.pop_back();



  // idx番目の竹をBに使う

  b.push_back(l[idx]);

  chmin(ret, rec(idx+1, a, b, c));

  b.pop_back();



  // idx番目の竹をCに使う

  c.push_back(l[idx]);

  chmin(ret, rec(idx+1, a, b, c));

  c.pop_back();



  // idx番目の竹を使わない

  chmin(ret, rec(idx+1, a, b, c));



  return ret;

}



signed main() {

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

  l.resize(N);

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

    cin >> l[i];

  }



  vector<int> a;

  vector<int> b;

  vector<int> c;

  cout << rec(0, a, b, c) << endl;



  return 0;

}

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

#include <vector>

#include <climits>

#include <numeric>

#include <algorithm>

#include <utility>

using namespace std;



using LL = long long;



int main() {

    int N;

    cin >> N;

    

    vector<int> ABC(3);

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

    

    vector<int> l(N);

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

    

    int ans = INT_MAX;

    

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

        vector<vector<int>> d(4, vector<int>());

        for(int i = 0; i < N; i++) d[(bit >> (2 * i) & 3)].push_back(l[i]);

        bool good = true;

        for(int i = 0; i < 3; i++) if(d[i].size() == 0) good = false;

        if(!good) continue;

        vector<int> cost(3, 0);

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

            cost[i] += 10 * (d[i].size() - 1);

            cost[i] += abs(ABC[i] - accumulate(d[i].begin(), d[i].end(), 0));

        }

        ans = min(ans, accumulate(cost.begin(), cost.end(), 0));

    }

    

    cout << ans << endl;

    

}


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

#include <string>

#include <vector>

#include <map>

#include <set>

#include <queue>

#include <algorithm>

#include <utility>

#include <iomanip>

#include <tuple>

#include <cstdio>

#include <cmath>

using namespace std;

using ll = long long;

const int INF = 1e9;



int n;

int ans = INF;

vector<int> abc, l;

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



void dfs(int depth) {

    if (depth == n) {

        int tmp = 0;

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

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

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

        }

        ans = min(ans, tmp);

    } else {

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

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

            now[i].second +=1;

            dfs(depth+1);

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

            now[i].second -= 1;

        }

    }

}



int main() {

    cin >> n;

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

        int inp; cin >> inp;

        abc.push_back(inp);

    }



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

        int inp; cin >> inp;

        l.push_back(inp);

    }

    dfs(0);

    cout << ans << endl;

}


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

#include<vector>

#include<string>

#include<algorithm>

#include<utility>

#include<cmath>

#include<climits>



using namespace std;

int ans = 100000;

int n = 0;

int a, b, c;

vector<int> l(8);



void calc(vector<int> v){

  int tmpa = 0, tmpb = 0, tmpc = 0, mp = 0;



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

    if(v[i] == 0){

      if(tmpa > 0) mp += 10;

      tmpa += l[i];



    } else if(v[i] == 1){

      if(tmpb > 0) mp += 10;

      tmpb += l[i];



    } else if(v[i] == 2){

      if(tmpc > 0) mp += 10;

      tmpc += l[i];



    }

  }

  if(tmpa == 0 || tmpb == 0|| tmpc ==0) return;



  mp += abs(tmpa - a) + abs(tmpb - b) + abs (tmpc - c);

  if(mp < ans){

    ans = mp;

  }



}



void dfs(int depth, vector<int> v){

  if(depth == n)  {

    calc(v);

  } else {

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

    v[depth] = i;

    dfs(depth + 1, v);

    }

  }

}



int main(){

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

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

    cin >> l[i];

  }



  vector<int> v(8);



  dfs(0, v);



  cout << ans << endl;







}


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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;



int A, B, C, n;

vector<int> l;

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

  if(cur == n){

    if(a <= 0 || b <= 0 || c <= 0) return 100000000;

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

  }

  int res = INT_MAX;

  res = min(res, rec(a + l[cur], b, c, cur + 1) + 10);

  res = min(res, rec(a, b + l[cur], c, cur + 1) + 10);

  res = min(res, rec(a, b, c + l[cur], cur + 1) + 10);

  res = min(res, rec(a, b, c, cur + 1));

  return res;

}



int main(){

  cin >> n >> A >> B >> C;

  l.resize(n);

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

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

  cout << ans - 30 << endl;

  

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



queue<string> res;

void product(string cand, int repeat) {

  auto now = res.front();

  if (now.size() == repeat) return;

  res.pop();

  for (auto &c : cand) res.push(now + c);

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n, a, b, c;

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

  vector<int> abc = {0, a, b, c};

  vector<int> l(n);

  for (int i = 0; i < n; i++) cin >> l[i];



  string cand = "0123";

  queue<string> res;

  res.push("");

  while (res.front().size() != n) {

    string now = res.front(); res.pop();

    for (auto &c : cand) res.push(now + c);

  }

  vector<int> ans;

  while (!res.empty()) {

    auto p = res.front(); res.pop();

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

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

      group[p[i]-'0'].push_back(l[i]);

    }

    int cost = 0;

    bool flag = true;

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

      if (group[i].size() == 0) {flag = false; break;}

      cost += 10 * (group[i].size() - 1);

      int s = accumulate(group[i].begin(), group[i].end(), 0);

      cost += abs(s - abc[i]);

    }

    if (flag) ans.push_back(cost);

  }

  cout << *min_element(ans.begin(), ans.end()) << '\n';

  return 0;

}

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

using namespace std;



int INF = 1001001001;

int n, A, B, C;

vector<int> l(8);



int cost(int a, int b, int c, int cnt, int i) {

  if (i == n) {

    if (!(a && b && c)) return INF;

    return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3);

  }

  vector<int> cand = {cost(a, b, c, cnt, i+1),

                      cost(a+l[i], b, c, cnt+1, i+1),

                      cost(a, b+l[i], c, cnt+1, i+1),

                      cost(a, b, c+l[i], cnt+1, i+1)};

  return *min_element(cand.begin(), cand.end());

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  cin >> n >> A >> B >> C;

  for (int i = 0; i < n; i++) cin >> l[i];

  cout << cost(0, 0, 0, 0, 0) << '\n';

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int INF = 1001001001;

int n;

vector<int> abc(3);

vector<int> l(8);



int cost(vector<int> v, vector<int> c, int j) {

  if (j == n) {

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

      if (!c[i]) return INF;

    }

    int ans = 10 * (c[0] + c[1] + c[2] - 3);

    for (int i = 0; i < 3; i++) ans += abs(abc[i] - v[i]);

    return ans;

  }

  int ans = cost(v, c, j+1);

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

    vector<int> nv = v, nc = c;

    nv[i] += l[j]; nc[i]++;

    ans = min(ans, cost(nv, nc, j+1));

  }

  return ans;

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  cin >> n;

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

  for (int i = 0; i < n; i++) cin >> l[i];

  cout << cost({0, 0, 0}, {0, 0, 0}, 0) << '\n';

  return 0;

}

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

using namespace std;



int INF = 1001001001;

int n, A, B, C;

vector<int> l(8);



int cost(int a, int b, int c, int cnt, int i) {

  if (i == n) {

    if (!(a && b && c)) return INF;

    return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3);

  }

  vector<int> cand = {cost(a, b, c, cnt, i+1),

                      cost(a+l[i], b, c, cnt+1, i+1),

                      cost(a, b+l[i], c, cnt+1, i+1),

                      cost(a, b, c+l[i], cnt+1, i+1)};

  return *min_element(cand.begin(), cand.end());

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  cin >> n >> A >> B >> C;

  for (int i = 0; i < n; i++) cin >> l[i];

  cout << cost(0, 0, 0, 0, 0) << '\n';

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define INF (1<<30)

#define MOD 1000000007

#define l_ength size

using ll = long long;

using namespace std;



int main(){

	int n; cin >> n;

	int a, b, c; cin >> a >> b >> c;

	vector<int> len(n);

	for( auto &i : len ) cin >> i;

	int bound = 0;

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

		bound += 3*pow(4, i);

	}

	int ans = INF;

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

		vector<int> welch;

		int itemp = i;

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

			welch.push_back( itemp % 4 );

			itemp -= itemp % 4;

			itemp /= 4;

		}

		int sum[4] = {0, 0, 0, 0};

		int gs[4] = {0, 0, 0, 0};

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

			++gs[welch[j]];

			sum[welch[j]] += len[j];

		}

		if( gs[1] == 0 || gs[2] == 0 || gs[3] == 0 ) continue;

		int res = abs( a-sum[1] ) + abs( b-sum[2] ) + abs( c-sum[3] ) + 10*(gs[1]-1) + 10*(gs[2]-1) + 10*(gs[3]-1);

		ans = min(ans, res);

	}

	cout << ans << endl;

	return 0;

}

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

#define l_ength size

const int inf = (1<<30);

const int mod = 1000000007; // 998244353

using ll = long long;

using namespace std;



int n, a, b, c;

vector<int> l(8, 0);



int ans = inf;



void dfs( int x, int y, int z, int i, int xcnt, int ycnt, int zcnt ){

	if( i == n ){

		if( xcnt*ycnt*zcnt == 0 ) return;

		int synth = 10*(xcnt-1)+10*(ycnt-1)+10*(zcnt-1);

		ans = min( ans, abs(a-x)+abs(b-y)+abs(c-z)+synth );

		return;

	}

	dfs( x, y, z, i+1, xcnt, ycnt, zcnt );

	dfs( x+l[i], y, z, i+1, xcnt+1, ycnt, zcnt );

	dfs( x, y+l[i], z, i+1, xcnt, ycnt+1, zcnt );

	dfs( x, y, z+l[i], i+1, xcnt, ycnt, zcnt+1 );

}



int main(){

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

	for( int i = 0; i < n; ++i ) cin >> l[i];

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

	cout << ans << endl;

}

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

#include<vector>

#include<algorithm>

#include<queue>

#include<map>

using namespace std;

typedef long long ll;

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

#define rrep(i, st, n) for (int i = st; i < n; ++i)

using pii = pair<int, int>;



int n, a[3], ans = 3000;

vector<int> l(8);

void calc(vector<int> v) {

    int b[3] = {0}, fus[3] = {0};

    rep(i, 3) rep(j, n) {

        if (v[j] == i) {

            b[i] += l[j];

            fus[i]++;

        }

    }

    int cnt = 0;

    rep(i, 3) if (fus[i] == 0) return;

    rep(i, 3) if (fus[i]) cnt += (fus[i] - 1) * 10;

    rep(i, 3) cnt += abs(b[i] - a[i]);

    ans = min(ans, cnt);

    //cout << ans << endl;

}

void dfs(int depth, vector<int> v) {

    /*

    rep(i, n) cout << v[i] << " ";

    cout << endl;

    */

    if (depth == n) {

        calc(v);

        return;

    }

    rep(i, 4) {

        v[depth] = i;

        dfs(depth + 1, v);

        

    }

}

int main() {

    cin >> n;

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

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

    vector<int> v(n);

    rep(i, n) v[i] = -1;

    dfs(0, v);

    cout << ans << endl;

}




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

#include<vector>

#include<algorithm>

#include<queue>

#include<map>

using namespace std;

typedef long long ll;

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

#define rrep(i, st, n) for (int i = st; i < n; ++i)

using pii = pair<int, int>;



int n, A, B, C, l[8];

const int inf = 3000;

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

    if (cur == n) {

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

        //1個目 a, b, c +10されてる

        else return inf;

    }

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

    int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;

    int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;

    int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;

    return min(min(ret0, ret1), min(ret2, ret3));

}

int main() {

    cin >> n >> A >> B >> C;

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

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

}


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


#include<iostream>

#include<map>

#include<algorithm>

#include <iomanip>

#include <cmath>

#include <sstream>

#include <unordered_map>

#include <unordered_set>

#include <deque>

#include <vector>

#include <bitset>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <cstring>



#define INF 1050000000

#define MOD 1000000007



int n, a, b, c;

int l[10];



using namespace std;



int dfs(int depth, int x, int y, int z) {

	if (depth == n) {

		if (x == 0 || y == 0 || z == 0) {//答えから除外する。無に魔法は使えない。

			return 1e9;

		}

		return abs(x - a) + abs(y - b) + abs(z - c) - 30;

	}



	int mu = dfs(depth + 1, x, y, z);

	int entyou = dfs(depth + 1, x + l[depth], y, z)+10;

	int tansyuku = dfs(depth + 1, x, y + l[depth], z)+10;

	int gousei = dfs(depth + 1, x, y, z + l[depth])+10;



	return min({ mu,entyou,tansyuku,gousei });



}





int main() {

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



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

		cin >> l[i];

	}



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

















}

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



#define N 9

#define INF 1000000



int DFS(int X,int Y,int Z,int n);

int MIN(int a,int b);

int ABS(int x);



int l[N],A,B,C,n;



int main(void){

	int i;

	

	scanf("%d",&n);

	scanf("%d%d%d",&A,&B,&C);

	for(i=0;i<n;i++){scanf("%d",&l[i]);}

	

	printf("%d\n",DFS(0,0,0,0));

	

	return 0;

}



int DFS(int X,int Y,int Z,int depth){

	int NO_USE_POWER,SYNTHESIS_1,SYNTHESIS_2,SYNTHESIS_3;

	

	if(depth==n){

		if(X==0||Y==0||Z==0){return INF;}

		else{return (ABS(X-A)+ABS(Y-B)+ABS(Z-C)-30);}

	}

	

	NO_USE_POWER=DFS(X,Y,Z,depth+1);

	SYNTHESIS_1=DFS(X+l[depth],Y,Z,depth+1)+10;

	SYNTHESIS_2=DFS(X,Y+l[depth],Z,depth+1)+10;

	SYNTHESIS_3=DFS(X,Y,Z+l[depth],depth+1)+10;

	

	return (MIN(MIN(NO_USE_POWER,SYNTHESIS_1),MIN(SYNTHESIS_2,SYNTHESIS_3)));

}



int MIN(int a,int b){

	if(a<b){return a;}

	else{return b;}

}



int ABS(int x){

	if(x<0){return (-1*x);}

	else{return x;}

}

// Fastest known solution for this problem: