stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define lln long long int

#define llu unsigned lln

#define sc(n) scanf("%d",&n);

#define scl(n) scanf("%lld",&n);

#define scd(n) scanf("%lf",&n);

#define pf(res) printf("%d\n",res);

#define pfl(res) printf("%lld\n",res);

#define pfd(res) printf("%lf\n",res);

#define maxii 100005

using namespace std;

typedef pair<int,int> pii;

typedef pair<lln,lln> pll;

 vector<int> vi[maxii];

 vector<int>:: iterator child;

typedef vector<lln> vl;

typedef vector<pii> vii;

typedef vector<pll> vll;





int arr[maxii];

int arr2[maxii];

bool check[maxii];



bool dfs(int node,int c)

{

    check[node]=true;

    arr2[node]=c;

    for(int child=0;child<vi[node].size();child++)

    {

        if(check[vi[node][child]]==false)

        {

            if(dfs(vi[node][child],c^1)==false)

            {

                return false;

            }

        }

        else if(arr2[node]==arr2[vi[node][child]])

        {

            return false;

        }

        //else if()

    }

    return true;

}



int main()

{

    int arrrr[4];

    cin>>arrrr[0]>>arrrr[1]>>arrrr[2];

    sort(arrrr,arrrr+3);

    if(arrrr[0]==5 && arrrr[1]==5 && arrrr[2]==7  )

    {

        printf("YES\n");

    }

    else printf("NO\n");



}


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

using namespace std;

typedef long long ll;

#define gcd(a,b)   __gcd(a,b)

#define lcm(a,b)   (a*b)/gcd

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

#define Rep(i,n)   for(int i=1;i<=n;i++)

#define REP(i,j,n) for(int i=j;i<=n;i++)

#define fast   ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)





int main()

{ 

	fast;

	int ar[3];

	rep(i,3){

		cin>>ar[i];

	}

	int cnt=0;

	rep(i,3){

		if(ar[i]==5) cnt++;

	}

	if(cnt==2){

		cout<<"YES"<<endl;

	}

	else cout<<"NO"<<endl;



}
// Slower C++ solution:
#include<bits/stdc++.h>

#define lln long long int

#define llu unsigned lln

#define sc(n) scanf("%d",&n);

#define scl(n) scanf("%lld",&n);

#define scd(n) scanf("%lf",&n);

#define pf(res) printf("%d\n",res);

#define pfl(res) printf("%lld\n",res);

#define pfd(res) printf("%lf\n",res);

#define maxii 100005

using namespace std;

typedef pair<int,int> pii;

typedef pair<lln,lln> pll;

 vector<int> vi[maxii];

 vector<int>:: iterator child;

typedef vector<lln> vl;

typedef vector<pii> vii;

typedef vector<pll> vll;





int arr[maxii];

int arr2[maxii];

bool check[maxii];



bool dfs(int node,int c)

{

    check[node]=true;

    arr2[node]=c;

    for(int child=0;child<vi[node].size();child++)

    {

        if(check[vi[node][child]]==false)

        {

            if(dfs(vi[node][child],c^1)==false)

            {

                return false;

            }

        }

        else if(arr2[node]==arr2[vi[node][child]])

        {

            return false;

        }

        //else if()

    }

    return true;

}



int main()

{

    int arrrr[4];

    cin>>arrrr[0]>>arrrr[1]>>arrrr[2];

    sort(arrrr,arrrr+3);

    if(arrrr[0]==5 && arrrr[1]==5 && arrrr[2]==7  )

    {

        printf("YES\n");

    }

    else printf("NO\n");



}


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

using namespace std;

int main()

{

   int a,b,c;

   cin>>a>>b>>c;

   if((a==5&&b==7&&c==5)||(a==5&&b==5&&c==7)||(a==7&&b==5&&c==5))

   {

       cout<<"YES"<<"\n";

   }

   else

   {

       cout<<"NO"<<"\n";

   }



return 0;}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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



int N, A, B, C;

vector<int> l;



int cost(int target, int s) {

  if(s == 0) return 4000;



  int ans = 4000;

  rep(i,(1<<N)) {

    int n = 0;

    int sum = 0;

    rep(j,N) {

      if((s >> j) & (i >> j) & 1) {

        sum += l[j];

        n += 1;

      }

    }

    if(n != 0) ans = min(ans, (n-1)*10 + abs(target - sum));

  }

  return ans;

}



int solve(int d, int a, int b, int c) {

  if(d == N) return cost(A, a) + cost(B, b) + cost(C, c);

  int k = (1 << d);

  return min(solve(d+1, a | k, b, c), min(solve(d+1, a, b|k, c), solve(d+1, a, b, c|k)));

}



int main () {

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

  l = vector<int>(N);

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



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



  return 0;

}


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

using namespace std;

typedef long long ll;

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



int N, A, B, C;

vector<int> l;



const int INF = 1e9;



int solve(int i, int a, int b, int c) {

  if(i == N) {

    return min(a, min(b, c)) == 0 ? INF : abs(A-a) + abs(B-b) + abs(C-c) - 30;

  }



  int ans = INF;

  ans = min(ans, solve(i+1, a, b, c));

  ans = min(ans, solve(i+1, a + l[i], b, c) + 10);

  ans = min(ans, solve(i+1, a, b + l[i], c) + 10);

  ans = min(ans, solve(i+1, a, b, c + l[i]) + 10);

  return ans;

}



int main () {

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

  l = vector<int>(N);

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



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



  return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <cstring>

#include <cstdlib>

#include <utility>

#include <cstdio>

#include <vector>

#include <string>

#include <queue>

#include <stack>

#include <cmath>

#include <set>

#include <map>

using ll = long long;

using itn = int;

using namespace std;

int GCD(int a, int b){

    return b ? GCD(b, a%b) : a;

}

int Magic(int a){

    return a>1 ? (a-1)*10 : 0;

}

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

    

    int MP=1e9;

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

        int a[3]={},cnt[3]={};

        int tmp=mask;

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

            if(tmp%4==1){

                a[0]+=l[i];

                cnt[0]++;

            }else if(tmp%4==2){

                a[1]+=l[i],cnt[1]++;

            }else if(tmp%4==3){

                a[2]+=l[i],cnt[2]++;

            }

            tmp/=4;

        }

        if(a[0] && a[1] && a[2]){

            int mp=abs(A-a[0]) + abs(B-a[1]) + abs(C-a[2]);

            for(int i=0; i<3; i++) mp += Magic(cnt[i]);

            MP = min(MP, mp);

        }



    }

    cout << MP << endl;

}


// Faster C++ solution for the same problem (measured speedup: 4.6502339929076x):
#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cstring>

#include <cstdlib>

#include <utility>

#include <cstdio>

#include <vector>

#include <string>

#include <queue>

#include <stack>

#include <cmath>

#include <set>

#include <map>

using ll = long long;

using itn = int;

using namespace std;

int GCD(int a, int b){

    return b ? GCD(b, a%b) : a;

}

int n,A,B,C;

vector<int> l;

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

    if(i==n) {

        //少なくとも1本は選んでいる

        if(!a || !b || !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 ? 10 : 0));

    res = min(res, rec(i+1, a, b+l[i], c) + (b ? 10 : 0));

    res = min(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;

    

}
// Slower C++ solution:
#include <bits/stdc++.h>

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

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

using namespace std;

typedef long long ll;

typedef pair<int, int> P;



const ll INF = 1LL << 60;



ll N, A, B, C;

vector<ll> v;

ll ans = INF;



void dfs(int i, vector<ll> a) {

    if (i == N) {

        // A: 0 

        // B: 1

        // C: 2

        // 使わない: 3 

        map<ll, ll> mp;

        rep(k, a.size()) {

            if (a[k] == 3) continue;

            mp[a[k]]++;

        }

        if (mp.size() != 3) return;



        // 3種類ある

        ll x, y, z;

        x = y = z = 0;

        rep(k, a.size()) {

            if (a[k] == 0) {

                x += v[k];

            } else if (a[k] == 1) {

                y += v[k];

            } else if (a[k] == 2) {

                z += v[k];

            }

        }



        // cout << endl;

        // cout << endl;

        // rep(k, a.size()) {

        //     cout << a[k] << " ";

        // }

        ll connect_num = (mp[0] - 1) + (mp[1] - 1) + (mp[2] - 1);

        ll tmp = abs(A - x) + abs(B - y) + abs(C - z) + 10 * connect_num;

        // cout << tmp << endl;

        ans = min(ans, tmp);

        

        return;

    }



    map<ll, ll> mp;

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

        a[i] = j;

        dfs(i + 1, a);

    }

}



int main() {

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

    v.resize(N);

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



    vector<ll> tmp(N, 0);

    dfs(0, tmp);



    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.1137655609350872x):
#include <algorithm>

#include <bits/stdc++.h>

#include<iostream>

#include<string>

using namespace std;

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

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

#define ll long long

const ll MOD=1000000007;

const ll INF=1<<27;

int n,a,b,c;

vector<int> l(10);

int ans=INF;

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

    if(depth==n){

        if(find(all(v),0)==v.end()||find(all(v),1)==v.end()||find(all(v),2)==v.end())return;

        else {

            vector<int> sum(3,0);

            vector<int> cnt(3,0);

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

            if(v[i]==0)sum[0]+=l[i],cnt[0]++;

            if(v[i]==1)sum[1]+=l[i],cnt[1]++;

            if(v[i]==2)sum[2]+=l[i],cnt[2]++;

            }

             int ret=0;

             int tmp=0;

             tmp=(cnt[0]-1)+(cnt[1]-1)+(cnt[2]-1);

               ret=abs(a-sum[0])+abs(b-sum[1])+abs(c-sum[2])+10*tmp;

               ans=min(ans,ret);

               return;

        }

    }

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

        v[depth]=i;

        dfs(depth+1,v);

    }

}

int main(){

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

 l.resize(n);

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

 vector<int> v(n,0);

 dfs(0,v);

 cout << ans << endl;

}
// Slower C++ solution:
#include <algorithm>

#include <bitset>

#include <cassert>

#include <cmath>

#include <climits>

#include <cstdlib>

#include <iostream>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <string>

#include <vector>

#define DEBUG 1

using namespace std;

constexpr int kMod = 1000000007;

typedef long long LL;

constexpr int kInf = 1e9;



template<typename T>

istream& operator >> (istream& is, vector<T>& vs){

  for(T& v: vs) is >> v;

  return is;

}



template<typename T>

ostream& operator << (ostream& os, const vector<T>& vs){

  for (const T& v : vs) os << v << " ";

  return os;

}



int N, A, B, C;

vector<int> l;

int dfs(const vector<int> a, const vector<int>& b, const vector<int>& c, int i) {

  if (i == N) {

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

    int sumA = accumulate(a.begin(), a.end(), 0);

    int sumB = accumulate(b.begin(), b.end(), 0);

    int sumC = accumulate(c.begin(), c.end(), 0);

    int costA = abs(A - sumA) + 10 * (a.size() - 1);

    int costB = abs(B - sumB) + 10 * (b.size() - 1);

    int costC = abs(C - sumC) + 10 * (c.size() - 1);

    return costA + costB + costC;

  }



  vector<int> a2 = a; a2.push_back(l[i]);

  vector<int> b2 = b; b2.push_back(l[i]);

  vector<int> c2 = c; c2.push_back(l[i]);

  int minMP = kInf;

  minMP = min(minMP, dfs(a, b, c, i + 1));

  minMP = min(minMP, dfs(a2, b, c, i + 1));

  minMP = min(minMP, dfs(a, b2, c, i + 1));

  minMP = min(minMP, dfs(a, b, c2, i + 1));

  return minMP;

}



int main() {

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

  l.resize(N); cin >> l;



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

}


// Faster C++ solution for the same problem (measured speedup: 5.2377543472234285x):
#include <algorithm>

#include <bitset>

#include <cassert>

#include <cmath>

#include <climits>

#include <cstdlib>

#include <iostream>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <string>

#include <vector>

#define DEBUG 1

using namespace std;

constexpr int kMod = 1000000007;

typedef long long LL;

constexpr int kInf = 1e9;



template<typename T>

istream& operator >> (istream& is, vector<T>& vs){

  for(T& v: vs) is >> v;

  return is;

}



template<typename T>

ostream& operator << (ostream& os, const vector<T>& vs){

  for (const T& v : vs) os << v << " ";

  return os;

}



int N, A, B, C;

vector<int> l;

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

  if (i == N) {

    if (a == 0 || b == 0 || c == 0) return kInf;

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

  }



  int mp1 = dfs(a, b, c, i + 1);

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

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

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

  return min({mp1, mp2, mp3, mp4});

}



int main() {

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

  l.resize(N); cin >> l;



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

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

using namespace std;



int calcMP(int A, int B, int C, vector<int> l, vector<int> l_a, vector<int> l_b, vector<int> l_c) {

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

    

    if(l_a.size() == 0 || l_b.size() == 0 || l_c.size() == 0) return -1;

    for(auto &e: l_a) sum_a += l[e];

    for(auto &e: l_b) sum_b += l[e];

    for(auto &e: l_c) sum_c += l[e];



    int mp_a = (l_a.size() - 1) * 10 + abs(A-sum_a);

    int mp_b = (l_b.size() - 1) * 10 + abs(B-sum_b);

    int mp_c = (l_c.size() - 1) * 10 + abs(C-sum_c);



    return mp_a + mp_b + mp_c;

}



int main() {

    int N, A, B, C;

    vector<int> l;

    vector<int> l_a, l_b, l_c, l_n;

    int minMP = 99999999;



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

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

        l.push_back(0);

        cin >> l[i];

    }



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

        l_a.clear();

        l_b.clear();

        l_c.clear();

        l_n.clear();



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

            int kind = (i>>(2*j)) % 4;

            switch(kind) {

            case 0:

                l_n.push_back(j);

                break;

            case 1:

                l_a.push_back(j);

                break;

            case 2:

                l_b.push_back(j);

                break;

            case 3:

                l_c.push_back(j);

                break;

            }

        } 

        int mp = calcMP(A, B, C, l, l_a, l_b, l_c);

        if(mp < 0) continue;

        minMP = min(minMP, mp);

    }



    cout << minMP << endl;   

}

// Faster C++ solution for the same problem (measured speedup: 1.1297014602299444x):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

using namespace std;



int calcMP(int A, int B, int C, int sa, int sb, int sc, int ta, int tb, int tc) {    

    if(sa == 0 || sb == 0 || sc == 0) return -1;



    int mp_a = (sa - 1) * 10 + abs(A-ta);

    int mp_b = (sb - 1) * 10 + abs(B-tb);

    int mp_c = (sc - 1) * 10 + abs(C-tc);



    return mp_a + mp_b + mp_c;

}



int main() {

    int N, A, B, C;

    int sa, sb, sc;

    int ta, tb, tc;



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

    vector<int> l(N);

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

        cin >> l[i];

    }



    int minMP = 99999999;

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

        sa = sb = sc = 0;

        ta = tb = tc = 0;



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

            int kind = (i>>(2*j)) % 4;

            switch(kind) {

            case 1:

                sa++;

                ta += l[j];

                break;

            case 2:

                sb++;

                tb += l[j];

                break;

            case 3:

                sc++;

                tc += l[j];

                break;

            default:

                break;

            }

        } 

        int mp = calcMP(A, B, C, sa, sb, sc, ta, tb, tc);

        if(mp < 0) continue;

        minMP = min(minMP, mp);

    }



    cout << minMP << endl;   

}
// Slower C++ solution:
#include <iostream>

#include <cstdlib>

#include <algorithm>

#include <cmath>

#include <vector>

#include <numeric> // accumulate(v.begin(), v.end(), 0)



using namespace std;

#define ll long long



int main(){

  int N, A, B, C;

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

  vector<int> L(N);

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

    cin >> L[i];

  int ans = 1000000;

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

    vector<int> As, Bs, Cs;

    int ii = i;

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

      int jj = ii % 4;

      if(jj == 0)

	As.push_back(L[j]);

      else if(jj == 1)

	Bs.push_back(L[j]);

      else if(jj == 2)

	Cs.push_back(L[j]);

      ii /= 4;

    }

    if(As.size() != 0 && Bs.size() != 0 && Cs.size() != 0) {

      int tmp =

	abs(A - accumulate(As.begin(), As.end(), 0)) + 10 * (As.size() - 1) +

	abs(B - accumulate(Bs.begin(), Bs.end(), 0)) + 10 * (Bs.size() - 1) +

	abs(C - accumulate(Cs.begin(), Cs.end(), 0)) + 10 * (Cs.size() - 1);

      if(tmp < ans)

	ans = tmp;

    }

  }

  cout << ans << endl;

  return 0;

}


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

using namespace std;

#define ll long long

#define ld long double

#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)

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

#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)

#define rrep(i,n) RREP(i,n-1,0)

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

const int inf = 1e9+7;

const ll longinf = 1LL<<60;

const ll mod = 1e9+7;

const ld eps = 1e-10;



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

  int n; cin >> n;

  ll a, b, c; cin >> a >> b >> c;

  ll A[] = {a, b, c};

  vector<ll> L(n); rep(i, n) cin >> L[i];

  ll mn = longinf;

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

    vector<ll> len(4);

    vector<ll> cnt(4);

    rep(j, n) {

      len[(i>>(2*j))%4] += L[j];

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

    }

    if(len[0]*len[1]*len[2]==0) continue;

    ll tmp = 0;

    rep(j, 3) {

      tmp += (cnt[j]-1) * 10LL;

      tmp += abs(A[j]-len[j]);

    }

    mn = min(tmp, mn);

  }

  cout << mn << "\n";

  return 0;

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

    }

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

    	vector<int> s;

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

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

    			s.pb(1);

    		}

    		else{

    			s.pb(0);

    		}

    	}

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

    		vector<int> v;

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

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

    			    v.pb(1);

    		    }

    		    else{

    			    v.pb(0);

    		    }

    		}

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

    			if(s[i]==0){

    				if(v[i]==0){

    					if(suma!=0){

    						num+=10;

    					}

    					suma+=l[i];

    				}

    				else{

    					if(sumb!=0){

    						num+=10;

    					}

    					sumb+=l[i];

    				}

    			}

    			else{

    				if(v[i]==0){

    					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;

}




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

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

}




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

}