open Scanf
open Printf

let (n,a,b,c) = sscanf (read_line ()) "%d %d %d %d" (fun n a b c -> (n,a,b,c))
let list = 
let rec input_list n l =
match n with 
  0 -> l
| x -> input_list (x-1) (sscanf (read_line ()) "%d" (fun x -> x):: l)
in input_list n [];;

let rec loop a_in b_in c_in mp l =
match l with
  [] -> 
  if (a_in * b_in * c_in = 0) then 3000
  else 
    abs(a - a_in) + abs(b - b_in) + abs(c - c_in) + mp - 30
  | x::rest -> 
  let a_use = loop (a_in + x) b_in c_in (mp+10) rest in
  let b_use = loop a_in (b_in + x) c_in (mp+10) rest in
  let c_use = loop a_in b_in (c_in + x) (mp+10) rest in
  let no_use= loop a_in b_in c_in mp rest in
  List.fold_left min 3000 [a_use; b_use; c_use; no_use];;

printf ("%d\n") (loop 0 0 0 0 list)
