stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.368357413680533x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 4.741233089416372x):
#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;

}
// Slower C++ solution:
#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;

}

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

#define INF (1<<30)

#define MOD 1000000007

#define l_ength size

using ll = long long;

using namespace std;



int n;

vector<int> anscandy;

int a, b, c;

int l[8];



void dfs( int x, int y, int z, int k, int mp ){

	if( k == n ){

		if( x != 0 && y != 0 && z != 0 ){

			anscandy.push_back( abs(a-x) + abs(b-y) + abs(c-z) + mp );

		}

		return;

	}

	( x == 0 ) ? dfs( x+l[k], y, z, k+1, mp ) : dfs( x+l[k], y, z, k+1, mp+10 );

	( y == 0 ) ? dfs( x, y+l[k], z, k+1, mp ) : dfs( x, y+l[k], z, k+1, mp+10 );

	( z == 0 ) ? dfs( x, y, z+l[k], k+1, mp ) : dfs( x, y, z+l[k], k+1, mp+10 );

	dfs( x, y, z, k+1, mp );

}



int main(){

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

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

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

	sort( anscandy.begin(), anscandy.end() );

	cout << anscandy[0] << endl;

	return 0;

}



// 18:53
// Slower C++ solution:
#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;

}

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

#define INF (1<<30)

#define MOD 1000000007

#define l_ength size

using ll = long long;

using namespace std;



int n;

vector<int> anscandy;

int a, b, c;

int l[8];



void dfs( int x, int y, int z, int k, int mp ){

	if( k == n ){

		if( x != 0 && y != 0 && z != 0 ){

			anscandy.push_back( abs(a-x) + abs(b-y) + abs(c-z) + 10*(mp-3) );

		}

		return;

	}

	dfs( x+l[k], y, z, k+1, mp+1 );

	dfs( x, y+l[k], z, k+1, mp+1 );

	dfs( x, y, z+l[k], k+1, mp+1 );

	dfs( x, y, z, k+1, mp );

}



int main(){

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

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

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

	sort( anscandy.begin(), anscandy.end() );

	cout << anscandy[0] << endl;

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.188232970034413x):
#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;

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 4.753900527642583x):
#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;

}
// Slower C++ solution:
#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;

}




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

using namespace std;

typedef long long ll;

#define F first

#define S second

#define pii pair<int, int>

#define eb emplace_back

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

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

#define rep3(i, l, n) for (int i = l; i < (n); ++i)

#define sz(v) (int)v.size()

#define inf (int)(1e9+7)

template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }

template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }







int n, a, b, c;

vector<int> l(8);



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

    if (d == n) {

        if (min({x, y, z}) <= 0) return inf;

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

    }

    int ret = inf;

    chmin(ret, dfs(d + 1, x, y, z));

    chmin(ret, dfs(d + 1, x + l[d], y, z) + 10);

    chmin(ret, dfs(d + 1, x, y + l[d], z) + 10);

    chmin(ret, dfs(d + 1, x, y, z + l[d]) + 10);

    return ret;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    

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

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

    

    cout << dfs(0, 0, 0, 0) - 30 << endl; // 1本だけの場合の+10は消す

}
// Slower C++ solution:


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

















}

// Faster C++ solution for the same problem (measured speedup: 3.3097141961020937x):
#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;}

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.550614183157079x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.3138964626482381x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.724159277536917x):
#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;

}