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

}


// Faster C++ solution for the same problem (measured speedup: 1.4579397549482551x):
#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 n, a, b, c;

int l[8];

int ans = 1000000000;



int calc_mp(string str) {

    int len_a = 0;

    int len_b = 0;

    int len_c = 0;

    int mp = 0;

    rep(i, 0, n) {

        if (str[i] == '0') {

            if (len_a != 0) mp += 10;

            len_a += l[i];

        }

        if (str[i] == '1') {

            if (len_b != 0) mp += 10;

            len_b += l[i];

        }

        if (str[i] == '2') {

            if (len_c != 0) mp += 10;

            len_c += l[i];

        }

    }



    if (len_a == 0 || len_b == 0 || len_c == 0) return -1;



    mp += abs(len_a - a) + abs(len_b -b) + abs(len_c - c);

    return mp;

}



void dfs(string select, int depth) {

    if (depth == n) {

        int x = calc_mp(select);

        if (x == -1) return;



        ans = min(ans, x);

        return;

    }



    rep(i, 0, 4) dfs(select + (char)(i + '0'), depth + 1);

}



int main() {

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

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



    dfs("", 0);

    cout << ans << endl;

    return 0;

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

}


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

}



bool is_ok(string s) {

    bool a, b, c;

    a = b = c = false;

    for (auto i : s) {

        if (i == '0') a = true;

        if (i == '1') b = true;

        if (i == '2') c = true;

    }

    return a && b && c;

}



void dfs(string s) {

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

        if (is_ok(s)) {

            ans = min(ans, calc(s));

        }

        return;

    }

    rep(i, 0, 4) dfs(s + char(i + '0'));

}



int main() {

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

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

    dfs("");

    cout << ans << endl;

    return 0;

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

}


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

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

using namespace std;



#define int long long

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;



// 「使用する可能性のある竹の集合」と「目標の長さ」を渡すと、目標の長さにするための最小コストを返してくれる

int calc2(vector<int> v, int val) {

  int ret = INF;

  int n = v.size();



  // 竹の集合の使い方を全列挙

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

    int cnt = 0;

    int sum = 0;

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

      if (mask & (1LL << i)) {

        sum += v[i];

        cnt++;

      }

    }

    if (cnt == 0) continue;

    chmin(ret, (cnt-1)*10 + abs(sum - val));

  }



  return ret;

}



// Aに使う竹、Bに使う竹、Cに使う竹の集合を渡すと、それぞれの目標の高さにするまでの最小コストを返してくれる

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

  return calc2(a, A) + calc2(b, B) + calc2(c, C);

}



// 「Aに使う可能性のある竹の集合」「Bに使う可能性のある竹の集合」「Bに使う可能性のある竹の集合」を全列挙

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

  if (idx >= N) {

    if (a.size() == 0 || b.size() == 0 || 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();



  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;

  int ans = rec(0, a, b, c);



  cout << ans << endl;



  return 0;

}

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

using namespace std;



#define int long long

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;



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

  if (idx >= N) {

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

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

  }



  int ret = INF;

  // A

  chmin(ret, rec(idx+1, a+l[idx], b, c) + (a > 0 ? 10 : 0));

  // B

  chmin(ret, rec(idx+1, a, b+l[idx], c) + (b > 0 ? 10 : 0));

  // C

  chmin(ret, rec(idx+1, a, b, c+l[idx]) + (c > 0 ? 10 : 0));

  // 使わない

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

  }



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



  cout << ans << endl;



  return 0;

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

}

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

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

    

}


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

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







}


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

  

}
// 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.1582305668127555x):
#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;

}
// 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.246446120753451x):
#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, int c, int j) {

  if (j == n) {

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

      if (!v[i]) return INF;

    }

    int ans = 10 * (c - 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;

    nv[i] += l[j];

    ans = min(ans, cost(nv, c+1, 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) << '\n';

  return 0;

}