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

using namespace std;



using lli = long long int;

using Vint = vector<int>;

using Vlli = vector<lli>;

using Wint = vector<Vint>;

using Wlli = vector<Vlli>;

using pii = pair<int, int>;

using pll = pair<lli, lli>;



const int MOD = 1e9 + 7;

const int INFi = 2e9 + 1;

const lli INFl = (lli)(9e18) + 1;

const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};



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

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

#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)

#define REP(i, n) FOR(i, 0, n)

#define rREP(i, n) rFOR(i, 0, (n-1))

#define vREP(i, vec) for(auto &(i) : (vec))





template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}

template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}

template <class T> inline void chmax(T &a, T b){a = max(a, b);}

template <class T> inline void chmin(T &a, T b){a = min(a, b);}





// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

inline

int numb(int a, int b, int c, int n, int k, Vint &Data){

  Vint A(4, 0), B(4, -1);

  REP(i, n){

    A.at(k & 3) += Data.at(i);

    B.at(k & 3)++;

    k >>= 2;

  }

  if(B.at(0) == -1 || B.at(1) == -1 || B.at(2) == -1) return INFi;

  int cost_merge = 10 * (B.at(0) + B.at(1) + B.at(2));

  return abs(a - A.at(0)) + abs(b - A.at(1)) + abs(c - A.at(2)) + cost_merge;

}



int main(void){

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

  Vint L(n); vREP(ele, L) cin >> ele;

  // cout << "L :"; vREP(ele, L) cout << ele << " "; cout << "\n";

  int res = INFi;

  REP(i, 1 << (2 * n)) chmin(res, numb(a, b, c, n, i, L));

  cout << res << '\n';

  return 0;

}

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

#include <array>



constexpr int N = 8;

constexpr int inf = 2e9;

std::array<int, N> A;



int main(void){

    int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c);

    for(int i = 0; i < n; ++i) scanf("%d", &A[i]);

    int N = (1 << n) << n;

    int res = inf;

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

        int val = i;

        int aa = 0, cna = 0,

            bb = 0, cnb = 0,

            cc = 0, cnc = 0;

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

            int d = val & 3; val >>= 2;

            switch(d){

                case 1: aa += A[j]; cna++; break;

                case 2: bb += A[j]; cnb++; break;

                case 3: cc += A[j]; cnc++; break;

            }

        }

        if(cna == 0 or cnb == 0 or cnc == 0) continue;

        int cost = (a > aa ? a - aa : aa - a) + (b > bb ? b - bb : bb - b) + (c > cc ? c - cc : cc - c);

        cost += 10 * (cna + cnb + cnc - 3);

        if(cost < res) res = cost;

    }

    printf("%d\n", res);

    return 0;

}

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

#include<string>

#include<queue>

#include<algorithm>

#include<map>

#include<set>

#include<vector>

#include<math.h>



using namespace std;



#define INF 1000000007

#define LINF (1LL << 62)



typedef long long i64;

typedef pair<i64,i64> P;





int n, a,b,c, x[10];



int solve(int ma, int mb, int mc){

	int cc = -1;

	int A = 0,B = 0, C = 0;

	int ans = 0;

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

		if((mc >> i) & 1){

			if(((ma >> i) & 1) || ((mb >> i) & 1)) return INF;

			C += x[i];

			cc++;

		}

	}

	if(cc == -1) return INF;

	ans += cc * 10 + abs(c-C);

	cc = -1;

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

		if((mb >> i) & 1){

			if((ma >> i) & 1) return INF;

			B += x[i];

			cc++;

		}

	}

	if(cc == -1) return INF;

	ans += cc * 10 + abs(b-B);

	cc = -1;

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

		if((ma >> i) & 1){

			A += x[i];

			cc++;

		}

	}

	if(cc == -1) return INF;

	ans += cc * 10 + abs(a-A);

	return ans;

}



int main(){

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

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

		cin >> x[i];

	}

	

	sort(x,x+n);

	

	int ans = INF;

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

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

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

				ans = min(ans, solve(i,j,k));

			}

		}

	}

	

	cout << ans << endl;

	

	return 0;

}

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



using namespace std;



#define INF 1000000007

#define LINF (1LL << 62)

#define PI 3.14159265358979



typedef long long i64;

typedef pair<i64,i64> P;



inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }



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

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







int n, a,b,c, d[10];

void solve(){

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

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

		cin >> d[i];

	}

	

	int ans = INF;

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

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

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

			sum[(i>>(j*2))%4] += d[j];

			cc[(i>>(j*2))%4]++;

		}

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

		int cnt = 0;

		cnt += abs(sum[0]-a) + (cc[0]-1)*10;

		cnt += abs(sum[1]-b) + (cc[1]-1)*10;

		cnt += abs(sum[2]-c) + (cc[2]-1)*10;

		chmin(ans,cnt);

	}

	cout << ans << endl;

}



int main(){

	std::cin.tie(0);

	std::ios::sync_with_stdio(false);

	int t = 1;

	//cin >> t;

	while(t--){

		solve();

	}

	

	return 0;

}

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

using namespace std;

int main(){

  	cin.tie(0);

  	ios::sync_with_stdio(false);

	int n;

  	cin >> n;

  	int a[3];

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

  	vector<int> l(n);

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

  	int ans = 1145141919;

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

      	vector<int> st(n);

      	int hoge = i;

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

          	st[j] = hoge & 3;

          	hoge /= 4;

        }

		vector<int> x(4, 0);

      	vector<int> cnt(4, 0);

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

          	x[st[j]] += l[j];

          	cnt[st[j]]++;

        }

		int cost = 0;

		bool f = true;

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

			if (cnt[j] == 0) f = false;

			cost += max((cnt[j] - 1) * 10, 0);

			cost += abs(x[j] - a[j]);

		}

		if (f) ans = min(ans, cost);

	}

	cout << ans << endl;

	return 0;

}

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

using namespace std;



int dfs(int cur, int a, int b, int c, int N, int A, int B, int C, int l[]){

  	if (cur == N){

    	if (min({a, b, c}) > 0)

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

    	else

            return 1000000000;

    }

    int ret0 = dfs(cur+1, a, b, c, N, A, B, C, l);

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

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

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

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

}



int main(){

  	cin.tie(0);

  	ios::sync_with_stdio(false);

	int N, A, B, C;

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

  	int l[N];

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

  	int ans = dfs(0, 0, 0, 0, N, A, B, C, l);

	cout << ans << endl;

	return 0;

}

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

using namespace std;

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

typedef long long ll;

typedef pair<int,int> P;

using vi=vector<long long>;

using vvi=vector<vector<long long>>;

using vc=vector<char>;

using vvc=vector<vector<char>>;

const int inf=1000000009;

void chmin(auto &a,auto b){if(b<a)a=b;}

void chmax(auto &a,auto b){if(a<b)a=b;}



int ans=999999999;

vi x(3);

int n;

void dfs(vvi v,int c,int i,vi a){

  if(c!=3)v[c].push_back(a[i]);

  if(i==n-1)dfs(v,3,i+1,a);

  else if(i==n){

    bool b=true;

    int mp=0;

    rep(j,3){

      int sum=0;

      if(!v[j].size())b=false;

      mp+=(v[j].size()-1)*10;

      rep(k,v[j].size())sum+=v[j][k];

      mp+=abs(sum-x[j]);

    }

    if(b)chmin(ans,mp);

  }

  else{

    dfs(v,0,i+1,a);

    dfs(v,1,i+1,a);

    dfs(v,2,i+1,a);

    dfs(v,3,i+1,a);

  }

}

int main(){

  cin>>n;

  vvi v(3);

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

  vi a(n);

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

  dfs(v,3,-1,a);

  cout<<ans<<endl;

}

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

using namespace std;

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

#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)

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

#define eb emplace_back

#define pb push_back

#define lb(v,k) (lower_bound(all(v),k)-v.begin())

#define ub(v,k) (upper_bound(all(v),k)-v.begin())

typedef long long ll;

typedef multiset<ll> S;

typedef pair<ll,ll> P;

typedef tuple<ll,ll,ll> PP;

typedef priority_queue<ll> PQ;

typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;

using vi=vector<ll>;

using vvi=vector<vector<ll>>;

const ll inf=1001001001001001;

const int INF=1001001001;

const int mod=1000000007;

bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}

bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}

int main(){

  int n;cin>>n;

  vi x(3);

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

  ll ans=inf;

  vi v(n);

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

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

    ll k=i;

  	vi num(4);

  	vi sum(4);

    rep(j,n){

      num[(k&3)]++;

      sum[(k&3)]+=v[j];

      k>>=2;

    }

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

    ll p=0;

    rep(j,3)p+=(num[j+1]-1)*10;

    rep(j,3)p+=abs(sum[j+1]-x[j]);

    chmin(ans,p);

  }

  cout<<ans<<endl;

}


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

#include <vector>

#include <algorithm>

using namespace std;



int main(){

  int N,A[3];

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

  int l[N];

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



  int ans=100000000;



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

    vector<int> use[4];

    int t=i;

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

      use[t%4].push_back(l[j]);

      t=t/4;

    }



    int sum=0;

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

      if(use[j].size()==0){

        sum=100000000;

        break;

      }



      int mp=10*(use[j].size()-1);

      int sm=0;

      for(int k : use[j]) sm+=k;

      mp=mp+abs(A[j]-sm);

      sum+=mp;

    }



    ans=min(ans,sum);

  }



  cout << ans << endl;

  return 0;



}


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

#include <vector>

#include <algorithm>

using namespace std;

#define INF 1000000000;



int N,A,B,C;

vector<int> l;



int dfs(int n, int na, int a, int nb, int b, int nc, int c){

  if(n==N){

    if(na==0 || nb==0 || nc==0) return INF;

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

  }



  int tmp1,tmp2,tmp3,tmp4;

  tmp1=dfs(n+1,na+1,a+l[n],nb,b,nc,c);

  tmp2=dfs(n+1,na,a,nb+1,b+l[n],nc,c);

  tmp3=dfs(n+1,na,a,nb,b,nc+1,c+l[n]);

  tmp4=dfs(n+1,na,a,nb,b,nc,c);

  int ans;

  ans=min(tmp1,tmp2);

  ans=min(ans,tmp3);

  ans=min(ans,tmp4);

  return ans;

}



int main(){

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

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

    int temp;

    cin >> temp;

    l.push_back(temp);

  }



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

  return 0;

}

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



int main()

{

    int n,a,b,c;

    std::cin >> n >> a >> b >>c;

    std::vector<int> l(n);

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

    int res = 1000000000;

    std::vector<std::vector<int>> ans(3);



    for(int bit0 = 0; bit0 < (1 << n); bit0++){             //aに使う

        for(int bit1 = 0; bit1 < (1 << n); bit1++){         //bに使う

            if(bit0 & bit1)continue;

            for(int bit2 = 0; bit2 < (1 << n); bit2++){     //cに使う

                if(bit0 & bit2)continue;

                if(bit1 & bit2)continue;

                int cur = 0;

                std::vector<int> va,vb,vc;

                for(int i = 0; i < n; i++)  if(bit0 & (1 << i))va.push_back(l[i]);

                for(int i = 0; i < n; i++)  if(bit1 & (1 << i))vb.push_back(l[i]);

                for(int i = 0; i < n; i++)  if(bit2 & (1 << i))vc.push_back(l[i]);

                if(!va.size() || !vb.size() || !vc.size())continue;

                cur += std::abs(std::accumulate(va.begin(),va.end(),0) - a) + ((int)va.size() - 1) * 10;

                cur += std::abs(std::accumulate(vb.begin(),vb.end(),0) - b) + ((int)vb.size() - 1) * 10;

                cur += std::abs(std::accumulate(vc.begin(),vc.end(),0) - c) + ((int)vc.size() - 1) * 10;

                res = std::min(res, cur);

            }

        }

    }

    std::cout << res << std::endl;

}

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



int n,a,b,c;

std::vector<int> l;





//再帰関数

int rec(int i, int x, int y, int z){

    //終端処理

    if(i == n){

        if(!x || !y || !z)return 1000000000;

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

    }



    int res = (rec(i + 1, x, y, z));



    res = std::min(res,rec(i + 1, x + l[i], y, z) + (x ? 10 : 0));

    res = std::min(res,rec(i + 1, x, y + l[i], z) + (y ? 10 : 0));

    res = std::min(res,rec(i + 1, x, y, z + l[i]) + (z ? 10 : 0));



    return res;



}



int main()

{

    std::cin >> n >> a >> b >> c;

    l.resize(n);

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



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

}

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

#include <iostream>

#include <vector>

#include <algorithm>



using namespace std;



const int INF = 1e9;



int N, A, B, C;

int ans = INF;



void calc(vector<int> l, vector<int> v) {

		int a = 0, b = 0, c = 0, t = 0, cnt = 0;

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

				switch (v[i]) {

						case 0: 

									if (a) cnt++;

									a += l[i];

									break;

						case 1: 

									if (b) cnt++;

									b += l[i];

									break;

						case 2: 

									if (c) cnt++;

									c += l[i];

									break;

						case 3: 

									break;

						default: 

									break;

				}

		}



		if (min( {a, b, c} ) ) t = abs(A - a) + abs(B - b) + abs(C- c) + 10 * cnt;

		else t = INF;



		if ( ans > t ) ans = t;

}



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

		if ( depth == N ) calc(l, v);

		else {

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

						v[depth] = i;

						dfs(depth + 1, l, v);

				}

		}

}



int main() {

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

		vector<int> l(N, 0);

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

				cin >> l[i];

		}



		vector<int> v(N, 0);

		dfs(0, l, v);

		cout << ans << endl;



		return 0;

}


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



using namespace std;



int MP = 1e9;

int N, A, B, C;

int l[8];



void calc(int select[]) {

		int mp = 0;

		int sum_a = 0, sum_b = 0, sum_c = 0;

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

				switch(select[i]) {

						case 0: if(sum_a)mp += 10; sum_a += l[i]; break;

						case 1: if(sum_b)mp += 10; sum_b += l[i]; break;

						case 2: if(sum_c)mp += 10; sum_c += l[i]; break;

						default: break;

				}

		}



		if (sum_a == 0 || sum_b == 0 || sum_c == 0) return;

		mp += abs(sum_a - A) + abs(sum_b - B) + abs(sum_c - C);

		MP = min(MP, mp);

}



void dfs(int depth, int select[]) {

		if (depth == N) calc(select);

		else {

				// 0:A, 1:B, 2:C, 4:not used

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

						select[depth] = i;

						dfs(depth+1, select);

				}

		}

}



int main() {

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

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



		int select[N];

		dfs(0, select);



		cout << MP << endl;

		return 0;

}


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

#include <algorithm>

#include <vector>



#define INF 1e9;



using namespace std;

		

int N, A, B, C;

vector<int> l;

int ans = INF;



void calc(vector<int> v) {

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

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

				switch (v[i]) {

						case 0:

								if (a) tmp += 10;

								a += l[i];

								break;

						case 1:

								if (b) tmp += 10;

								b += l[i];

								break;

						case 2:

								if (c) tmp += 10;

								c += l[i];

								break;

						case 3:

								break;

				}

		}

		if ( a == 0 || b == 0 || c == 0 ) {

				tmp = INF;

		} else {

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

		}

		if ( ans > tmp ) ans = tmp;

}



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

		if (depth == N) calc(v);

		else {

				// 0:A, 1:B, 2:C, 3:not use

				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++ ) {

				int t;

				cin >> t;

				l.push_back(t);

		}



		vector<int> v(N, 0);

		dfs(0, v);



		cout << ans << endl;



		return 0;

}


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



using namespace std;



int MP = 1e9;

int N, A, B, C;

int l[8];



void calc(int select[]) {

		int mp = 0;

		int sum_a = 0, sum_b = 0, sum_c = 0;

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

				switch(select[i]) {

						case 0: if(sum_a)mp += 10; sum_a += l[i]; break;

						case 1: if(sum_b)mp += 10; sum_b += l[i]; break;

						case 2: if(sum_c)mp += 10; sum_c += l[i]; break;

						default: break;

				}

		}



		if (sum_a == 0 || sum_b == 0 || sum_c == 0) return;

		mp += abs(sum_a - A) + abs(sum_b - B) + abs(sum_c - C);

		MP = min(MP, mp);

}



void dfs(int depth, int select[]) {

		if (depth == N) calc(select);

		else {

				// 0:A, 1:B, 2:C, 4:not used

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

						select[depth] = i;

						dfs(depth+1, select);

				}

		}

}



int main() {

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

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



		int select[N];

		dfs(0, select);



		cout << MP << endl;

		return 0;

}


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

#include <algorithm>

#include <cmath>

#include <string>



#define INF 1000000001



using namespace std;



string n_ary_convert(long n, long ary, long w){

    string ans = "";

    while(n != 0){

        if(n < 0){

            long temp = abs(ary) + n % ary;

            ans += to_string(temp);

            n = n / ary;

            if(temp == 0) continue;

            if(ary < 0) n++;

            else n--; 

        }

        else{

            ans += to_string(n % ary);

            n /= ary;

        }

    }

    while(ans.length() < w) ans += "0";

    reverse(ans.begin(), ans.end());

    return ans;

}



int main(){

    int N, A[3];

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

    int l[N];

    int ans = INF;



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



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

        int kdmt[4]; fill(kdmt, kdmt + 4, 0);

        int temp = 0;

        string s = n_ary_convert(i, 4, N);

        int mag[4]; fill(mag, mag + 4, 0);

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

            kdmt[s[j] - '0'] += l[j];

            mag[s[j] - '0']++;

        }

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

            if(mag[j] == 0) {

                temp += INF;

                break;

            }

            else temp += 10 * (mag[j] - 1);

            temp += abs(A[j] - kdmt[j]);

        }

        ans = min(temp, ans);

    }

    cout << ans << endl;

    

    return 0;



}

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

#include <queue>

#include <algorithm>



#define INF 1000000000;



using namespace std;



int dfs(int N, int cur, int a, int b, int c, int A, int B, int C, int * l){

    if(cur == N) {

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

        else return INF;

    }

    else{

        int ret0 = dfs(N, cur + 1, a, b, c, A, B, C, l);

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

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

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

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

    }

}



int main(){

    int N, A, B, C;

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

    int l[N];

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

    cout << dfs(N, 0, 0, 0, 0, A, B, C, l) << 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 pb push_back

#define fi first

#define se second

typedef pair<ll,ll> P;

#define Mod 1000000007



ll a,b,c;



ll solve(vector<ll> &v, ll tmp){

    ll i,j,k;

    ll n=v.size();

    ll s=1e10;

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

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

            for(k=0;k<n;k++){

                if(i==j||j==k||k==i) continue;

                s=min(s,tmp+abs(a-v[i])+abs(b-v[j])+abs(c-v[k]));

            }

        }

    }

    return s;

}



int main(){

    ll i,j;

    ll n;

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



    ll l[n];

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



    ll c[n];

    ll ans=1e10;



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

        ll ii=i;

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

            c[j]=ii%4;

            ii=ii/4;

        }

        vector<ll> v;

        ll p=0,q=0,r=0;

        ll tmp=0;



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

            if(c[j]==0) v.pb(l[j]);

            else if(c[j]==1) {

                if(p>0) tmp+=10;

                p+=l[j];

            }

            else if(c[j]==2) {

                if(q>0)  tmp+=10;

                q+=l[j];

            }

            else {

                if(r>0) tmp+=10;

                r+=l[j];

            }

        }

        if(p>0) v.pb(p);

        if(q>0) v.pb(q);

        if(r>0) v.pb(r);



        

        ans=min(ans,solve(v,tmp));





    }



    cout<<ans<<endl;

    



    return 0;

}

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

using namespace std;

typedef long long ll;

#define pb push_back

#define fi first

#define se second

typedef pair<ll,ll> P;

#define Mod 1000000007



int main(){

    ll i,j;

    ll n;

    cin>>n;

    ll a[4];

    for(i=1;i<4;i++) cin>>a[i];

    ll l[n];

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



    ll ans=1e18;

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

        ll ii =i;

        vector<ll> v(4,0);

        ll tmp=0;

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

            if(ii%4>0&&v[ii%4]>0) tmp+=10;

            v[ii%4]+=l[j];

            ii>>=2;

        }



        if (v[1]==0) continue;

        if (v[2]==0) continue;

        if (v[3]==0) continue;



        for(j=1;j<4;j++) {

            tmp+=abs(v[j]-a[j]);

        }

        ans=min(ans,tmp);

    }



    cout<<ans<<endl;



    return 0;

}

// Fastest known solution for this problem: