import Control.Monad
import Data.List

composition :: [Int] -> [[Int]] -> [(Int, Int, Int, Int)]
composition _ [] = []
composition ls (b:bs) = comp (zip ls b) (0, 0, 0, 0) : composition ls bs
  where comp :: [(Int, Int)] -> (Int, Int, Int, Int) -> (Int, Int, Int, Int)
        comp [] c = c
        comp (n:ns) (a, b, c, d)
          | snd n == 1 = comp ns (a + fst n, b, c, d + cost a)
          | snd n == 2 = comp ns (a, b + fst n, c, d + cost b)
          | snd n == 3 = comp ns (a, b, c + fst n, d + cost c)
          | otherwise  = comp ns (a, b, c, d)
             where cost x = if x == 0 then 0 else 10

solve :: (Int, Int, Int) -> [(Int, Int, Int, Int)] -> [Int]
solve _ [] = []
solve abc@(a, b, c) ((aa, bb, cc, cost):cs) = total : solve abc cs
  where total = abs (aa - a) + abs (bb - b) + abs (cc - c) + cost

main :: IO ()
main = do
  [n, a, b, c] <- map read . words <$> getLine
  ls <- replicateM n readLn
  let check n = 1 `elem` n && 2 `elem` n && 3 `elem` n
  let bits = filter check $ replicateM n [1..4] 
  let comp = composition ls bits
  print . minimum $ solve (a, b, c) comp
