main=print.solve.map read.words=<<getContents
solve(_:a:b:c:ls)=f(0,0,0)ls where
  f(i,j,k)[]
    |all(/=0)[i,j,k]=(abs$i-a)+(abs$j-b)+(abs$k-c)-30
    |otherwise=maxBound`div`2::Int
  f(i,j,k)(l:ls)=minimum[f(i,j,k)ls,f(i+l,j,k)ls+10,f(i,j+l,k)ls+10,f(i,j,k+l)ls+10]