(* O(1) *)
let get_wait_time cook_time = let m = cook_time mod 10 in if m = 0 then 0 else 10 - m
let get_next_time cook_time = cook_time + get_wait_time cook_time

(* O(|dishes|) *)
let solve dishes =
  let max_wait = List.map get_wait_time dishes |> List.fold_left max 0 in
  let sum = List.map get_next_time dishes |> List.fold_left (+) 0 in
  sum - max_wait

let read_int_array n = Array.init n (fun _ -> read_int ())
let read_ints n = read_int_array n |> Array.to_list

let _ = read_ints 5 |> solve |> string_of_int |> print_endline