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

}

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

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



}


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

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

}

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

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

}


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

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

}


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

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

}


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

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



}

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

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

}

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

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

}


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

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

}


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

}