import Control.Monad

all_pat::[Int]->[([Int],[Int],[Int],[Int])]
all_pat [] = [([],[],[],[])]
all_pat (x:rest) = concat [[(x:a,b,c,n),(a,x:b,c,n),(a,b,x:c,n),(a,b,c,x:n)]|(a,b,c,n)<-all_pat rest]


single_cost::(Int,[Int])->Int
single_cost (a,x) = (max 0 ((length x) - 1))*10 + (abs ((sum x)-a))

tot_cost::Int->Int->Int->([Int],[Int],[Int],[Int])->Int
tot_cost a b c (x,y,z,_) = sum((map single_cost) (zip [a,b,c] [x,y,z]))

solver::Int->Int->Int->[Int]->Int
solver a b c ls = minimum (map (tot_cost a b c) (filter (\(x,y,z,_)-> and [x/=[],y/=[],z/=[]]) (all_pat ls)))

main::IO()
main=do
  (n:a:b:c:[])<-return.map read.words=<<getLine
  dat<-forM [1..n] (\_-> return.read=<<getLine)
  print (solver a b c dat)