#include<iostream>
#include<vector>
#include<climits>

using namespace std;

int A,B,C,D,N; vector<int>l;

int dfs(int depth, int LA, int LB, int LC){
  if( depth == N ){ 
    if(LA && LB && LC){return abs(LA - A) + abs(LB - B) + abs(LC - C) - 30;}
     else{ return INT_MAX;}}
  
   int ret1 = dfs( depth+1, LA + l[depth],LB,LC) + 10 ;
   int ret2 = dfs( depth+1, LA, LB + l[depth], LC) + 10;
   int ret3 = dfs( depth+1, LA, LB, LC + l[depth]) + 10;
   int ret4 = dfs( depth+1, LA,LB,LC);
  
   return min(min(ret1,ret2),min(ret3,ret4));}
  
