
{-# LANGUAGE RankNTypes #-}

addA x tp = \cont -> tp (\a b c -> cont (a+x) b c)
addB x tp = \cont -> tp (\a b c -> cont a (b+x) c)
addC x tp = \cont -> tp (\a b c -> cont a b (c+x))

existZero = \a b c -> a==0 || b==0 || c==0
cost ta tb tc = \a b c -> abs (ta-a) + abs (tb-b) + abs (tc-c)

inf = 10^12

solv a b c ls = go ls (\cont -> cont 0 0 0) where
  go :: [Int] -> (forall c. (Int -> Int -> Int -> c) -> c) -> Int
  go [] t
    | t existZero = inf
    | otherwise   = (t $ cost a b c) - 30
  go (x:xs) t
    = min (min (10 + go xs (addA x t)) (10 + go xs (addB x t)))
          (min (10 + go xs (addC x t)) (go xs t))

main = do
  [n,a,b,c] <- map read . words <$> getLine :: IO [Int]
  xs <- map read . words <$> getContents :: IO [Int]
  print $! solv a b c xs
